/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --text-dim: #9aa2b1;
  --accent: #4b8bff;
  --accent-2: #6f5cff;
  --user-bubble: #23324d;
  --danger: #ff6b6b;
  --radius: 12px;
  --font:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
}

.hidden {
  display: none !important;
}

/* ---------------- Login ---------------- */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: radial-gradient(circle at 50% 20%, #1a1f2e 0%, var(--bg) 60%);
}

.login-card {
  width: 360px;
  max-width: 92vw;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.brand {
  text-align: center;
  margin-bottom: 8px;
}

.brand h1 {
  margin: 10px 0 4px;
  font-size: 22px;
}

.brand p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 24px;
  color: white;
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 16px;
}

.brand-mark.large {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  font-size: 32px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.login-card input {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card button {
  margin-top: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: white;
  padding: 12px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.login-card button:disabled {
  opacity: 0.6;
  cursor: default;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
  text-align: center;
}

.login-hint {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  margin: 0;
}

/* ---------------- Chat layout ---------------- */
.chat-view {
  display: flex;
  height: 100%;
}

.sidebar {
  width: 260px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  padding: 4px;
}

.new-chat-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}

.new-chat-btn:hover {
  border-color: var(--accent);
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 10px;
  overflow-y: auto;
  min-height: 0;
}

.conv-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
  padding: 0 2px 0 8px;
}

.conv-item:hover {
  background: var(--bg-elev-2);
}

.conv-item.active {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
}

.conv-title {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 9px 4px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 6px;
  opacity: 0;
}

.conv-item:hover .conv-del,
.conv-item.active .conv-del {
  opacity: 1;
}

.conv-del:hover {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.12);
}

.sidebar-spacer {
  flex: 1;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-top: 1px solid var(--border);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  text-transform: uppercase;
}

.user-meta {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  padding: 0;
}

.logout-btn:hover {
  color: var(--danger);
}

.conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 12px;
}

.empty-state {
  max-width: 640px;
  margin: 8vh auto 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.empty-state h2 {
  margin: 4px 0 8px;
  font-weight: 600;
}

.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.suggestion {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}

.suggestion:hover {
  border-color: var(--accent);
}

.msg-row {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  gap: 14px;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}

.msg-avatar.user {
  background: var(--user-bubble);
}

.msg-avatar.assistant {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
}

.msg-body {
  flex: 1;
  min-width: 0;
  padding-top: 3px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.msg-body p:first-child {
  margin-top: 0;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

.msg-body pre {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
}

.msg-body code {
  background: var(--bg-elev-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 13px;
}

.msg-body pre code {
  background: none;
  padding: 0;
}

.msg-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}

.msg-body th,
.msg-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.msg-body a {
  color: var(--accent);
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin: 6px 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.tool-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.tool-chip.running .dot {
  animation: pulse 1s infinite;
}

.tool-chip.error {
  color: var(--danger);
  border-color: var(--danger);
}

.tool-chip.error .dot {
  background: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

.cursor-blink::after {
  content: "▋";
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
  color: var(--text-dim);
}

@keyframes blink {
  0%,
  100% {
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
}

.error-banner {
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 6px 0;
  font-size: 13px;
}

/* ---------------- Composer ---------------- */
.composer {
  padding: 10px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.composer-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
}

.composer-inner:focus-within {
  border-color: var(--accent);
}

#chat-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  resize: none;
  outline: none;
  max-height: 200px;
  line-height: 1.5;
  padding: 6px 0;
}

#send-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.composer-hint {
  max-width: 760px;
  margin: 8px auto 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 11.5px;
}

@media (max-width: 720px) {
  .sidebar {
    display: none;
  }
  .suggestions {
    grid-template-columns: 1fr;
  }
}
