/* === AION Gbrain — ACEVE Design System === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ACEVE Navy System */
  --navy: #0f1a2e;
  --navy-mid: #1a2a45;
  --navy-light: #243656;
  --slate: #3a4f6f;
  --steel: #5a7094;
  --silver: #8a9bb5;
  --ghost: #c5cfe0;
  --cloud: #e8ecf2;
  --snow: #f4f6f9;
  --white: #ffffff;

  /* Accent */
  --orange: #e87a2e;
  --orange-light: #fdf0e6;
  --orange-mid: #f5a05c;
  --teal: #1a9e8f;
  --teal-light: #e5f6f4;
  --purple: #6c5ce7;
  --purple-light: #f0eefe;

  /* Semantic */
  --success: #27ae60;
  --error: #d63031;
  --gold: #c8a656;

  /* Layout tokens */
  --sidebar-w: 260px;
  --topbar-h: 56px;
  --radius: 10px;
  --radius-lg: 14px;
  --max-chat: 760px;

  /* Mapped */
  --bg: var(--snow);
  --bg-sidebar: var(--navy);
  --bg-card: var(--white);
  --bg-input: var(--white);
  --text: var(--navy);
  --text-secondary: var(--steel);
  --text-muted: var(--silver);
  --border: var(--cloud);
  --msg-user: var(--orange-light);
  --msg-ai: transparent;
}

[data-theme="dark"] {
  --bg: #0c1220;
  --bg-sidebar: #080e1a;
  --bg-card: var(--navy);
  --bg-input: var(--navy-mid);
  --text: var(--cloud);
  --text-secondary: var(--silver);
  --text-muted: var(--steel);
  --border: var(--navy-light);
  --msg-user: var(--navy-mid);
  --msg-ai: transparent;
}

html, body {
  height: 100%;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }
.mobile-only { display: none; }
@media (max-width: 768px) { .mobile-only { display: flex; } }

/* === AUTH === */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 50%, var(--slate) 100%);
}

.auth-card {
  background: var(--white);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.auth-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--orange-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.auth-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.75rem;
  color: var(--navy);
  letter-spacing: 0.05em;
}

.auth-subtitle {
  color: var(--steel);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--slate);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--cloud);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--navy);
  background: var(--snow);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(232, 122, 46, 0.15);
}

.btn-primary {
  width: 100%;
  padding: 0.75rem;
  background: var(--orange);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 0.5rem;
}

.btn-primary:hover { background: #d06a20; }

.btn-secondary {
  padding: 0.5rem 1.25rem;
  background: var(--cloud);
  color: var(--slate);
  border: none;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  margin-top: 0.75rem;
}

.auth-error {
  color: var(--error);
  font-size: 0.8rem;
  text-align: center;
  margin-top: 0.75rem;
  min-height: 1.2em;
}

.auth-footer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--silver);
  margin-top: 1.5rem;
}

/* === APP LAYOUT === */
.app {
  display: flex;
  height: 100vh;
  max-height: 100dvh;
}

/* === SIDEBAR === */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: var(--ghost);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 8px rgba(232, 122, 46, 0.5);
}

.brand-name {
  font-family: 'DM Serif Display', serif;
  font-size: 1.2rem;
  color: white;
  letter-spacing: 0.08em;
}

.sidebar-section {
  padding: 1rem 0.75rem 0.5rem;
}

.sidebar-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--steel);
  padding: 0 0.5rem;
  margin-bottom: 0.5rem;
}

.sidebar-action {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.6rem;
  background: none;
  border: none;
  color: var(--ghost);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
  text-align: left;
}

.sidebar-action:hover {
  background: rgba(255,255,255,0.07);
  color: white;
}

.sidebar-action svg { flex-shrink: 0; opacity: 0.7; }

.sidebar-footer {
  margin-top: auto;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--orange);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
}

.user-role {
  font-size: 0.65rem;
  color: var(--steel);
}

/* === MAIN CONTENT === */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.topbar-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  background: var(--orange-light);
  color: var(--orange);
  border-radius: 20px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 0.25rem;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.45rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.icon-btn:hover { background: var(--border); color: var(--text); }

.sidebar .icon-btn:hover { background: rgba(255,255,255,0.1); color: white; }

.icon-btn-sm {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.25rem;
}

/* === CHAT MESSAGES === */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  scroll-behavior: smooth;
}

/* Welcome */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 3rem 1rem;
  max-width: 520px;
  margin: 0 auto;
}

.welcome-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--orange-light);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

[data-theme="dark"] .welcome-icon { background: var(--navy-mid); }

.welcome-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.welcome-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.chip {
  padding: 0.45rem 0.9rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover {
  border-color: var(--orange);
  color: var(--orange);
  background: var(--orange-light);
}

[data-theme="dark"] .chip:hover { background: var(--navy-mid); }

/* Messages */
.message {
  max-width: var(--max-chat);
  margin: 0 auto 1.25rem;
  display: flex;
  gap: 0.75rem;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  margin-top: 2px;
}

.message.user .msg-avatar { background: var(--orange); color: white; }
.message.assistant .msg-avatar { background: var(--navy-light); color: var(--orange); border: 1px solid var(--border); }
[data-theme="dark"] .message.assistant .msg-avatar { background: var(--navy-mid); border-color: var(--navy-light); }

.msg-content { flex: 1; min-width: 0; }

.msg-role {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.msg-body {
  line-height: 1.65;
  font-size: 0.92rem;
  word-wrap: break-word;
}

.message.user .msg-body {
  background: var(--msg-user);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
}

/* Markdown */
.msg-body p { margin-bottom: 0.65rem; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 0.5rem 0 0.65rem 1.25rem; }
.msg-body li { margin-bottom: 0.2rem; }
.msg-body code {
  background: var(--cloud);
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  font-size: 0.84em;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}
[data-theme="dark"] .msg-body code { background: var(--navy-light); }
.msg-body pre {
  background: var(--navy);
  color: var(--ghost);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  margin: 0.65rem 0;
  border: 1px solid var(--border);
}
.msg-body pre code { background: none; padding: 0; color: inherit; font-size: 0.82rem; }
.msg-body blockquote {
  border-left: 3px solid var(--orange);
  padding-left: 1rem;
  color: var(--text-secondary);
  margin: 0.65rem 0;
}
.msg-body h1, .msg-body h2, .msg-body h3 { margin: 0.9rem 0 0.4rem; font-weight: 600; }
.msg-body h1 { font-size: 1.15rem; }
.msg-body h2 { font-size: 1.05rem; }
.msg-body h3 { font-size: 0.95rem; }
.msg-body a { color: var(--orange); text-decoration: none; }
.msg-body a:hover { text-decoration: underline; }
.msg-body table { border-collapse: collapse; width: 100%; margin: 0.65rem 0; font-size: 0.85rem; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 0.4rem 0.65rem; text-align: left; }
.msg-body th { background: var(--cloud); font-weight: 600; }
[data-theme="dark"] .msg-body th { background: var(--navy-mid); }

/* Typing */
.typing-dots { display: flex; gap: 4px; padding: 0.5rem 0; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--orange); opacity: 0.4;
  animation: bounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* === FILE UPLOAD === */
.upload-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 26, 46, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.upload-box {
  background: var(--bg-card);
  border: 2px dashed var(--orange);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  text-align: center;
  max-width: 400px;
  cursor: pointer;
}

.upload-title { font-weight: 600; margin-top: 0.75rem; }
.upload-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.35rem; }

/* File attached bar */
.file-attached {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  color: var(--orange);
  background: var(--orange-light);
  max-width: var(--max-chat);
  margin: 0 auto;
  border-radius: var(--radius) var(--radius) 0 0;
}

[data-theme="dark"] .file-attached { background: var(--navy-mid); }

/* === INPUT AREA === */
.input-area {
  padding: 0.5rem 1rem 0.75rem;
  background: var(--bg);
  flex-shrink: 0;
}

.input-form {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  max-width: var(--max-chat);
  margin: 0 auto;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.4rem 0.5rem 0.4rem 0.25rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-form:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(232, 122, 46, 0.1);
}

.input-icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.45rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.input-icon-btn:hover { color: var(--orange); background: var(--orange-light); }
[data-theme="dark"] .input-icon-btn:hover { background: var(--navy-light); }
.input-icon-btn.recording { color: var(--error); animation: pulse-rec 1s ease-in-out infinite; }
@keyframes pulse-rec { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

#chat-input {
  flex: 1;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 0.3rem 0.25rem;
}

#chat-input::placeholder { color: var(--text-muted); }

.send-btn {
  background: var(--orange);
  color: white;
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn:not(:disabled):hover { opacity: 0.85; }

.input-footer {
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* === MOBILE === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }
  .chat-messages { padding: 0.75rem; }
  .welcome-screen { padding: 1.5rem 0.75rem; }
  .welcome-chips { gap: 0.35rem; }
  .chip { font-size: 0.75rem; padding: 0.35rem 0.7rem; }
}
