/* ============================================================
   SCW AI — Design system matching scw.az
   ============================================================ */
:root {
  --bg-primary: #0d0b1e;
  --bg-secondary: #131128;
  --bg-tertiary: #1a1733;
  --bg-card: #1e1b3a;
  --bg-hover: #252245;
  --bg-input: #1a1733;

  --text-primary: #f0effe;
  --text-secondary: #9b97c4;
  --text-muted: #6b6894;
  --text-inverse: #0d0b1e;

  --accent: #6c5fff;
  --accent-hover: #7d72ff;
  --accent-glow: rgba(108, 95, 255, 0.3);
  --accent-subtle: rgba(108, 95, 255, 0.08);

  --green: #10b981;
  --green-subtle: rgba(16, 185, 129, 0.12);
  --red: #ef4444;
  --red-subtle: rgba(239, 68, 68, 0.12);
  --yellow: #f59e0b;
  --blue: #3b82f6;

  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.10);
  --border-accent: rgba(108, 95, 255, 0.25);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-display: 'DM Serif Display', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --sidebar-w: 280px;
  --nav-h: 56px;
}

[data-theme="light"] {
  --bg-primary: #fafaf8;
  --bg-secondary: #f3f2ef;
  --bg-tertiary: #eae9e5;
  --bg-card: #ffffff;
  --bg-hover: #efeeea;
  --bg-input: #ffffff;

  --text-primary: #1a1733;
  --text-secondary: #5b5890;
  --text-muted: #8b88b0;
  --text-inverse: #fafaf8;

  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.10);
  --border-accent: rgba(108, 95, 255, 0.2);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* --- Reset --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font: inherit; color: inherit; }
ul, ol { list-style: none; }
img, svg { display: block; max-width: 100%; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-slow);
  z-index: 100;
}

.sidebar-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  min-height: var(--nav-h);
}

.sidebar-logo {
  height: 28px;
  width: auto;
  flex-shrink: 0;
}

.sidebar-brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text-primary);
}

.sidebar-brand span {
  color: var(--accent);
}

.sidebar-actions {
  padding: 12px 12px 8px;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
}

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

.btn-new-chat .icon-plus {
  font-size: 1.2rem;
  font-weight: 300;
  color: var(--accent);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  text-align: left;
  transition: all var(--transition);
  position: relative;
  cursor: pointer;
}

.chat-list-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chat-list-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
}

.chat-list-item .chat-icon {
  flex-shrink: 0;
  opacity: 0.5;
  font-size: 0.9rem;
}

.chat-list-item.active .chat-icon { opacity: 1; }

.chat-list-item .chat-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list-item .chat-delete {
  flex-shrink: 0;
  opacity: 0;
  font-size: 0.75rem;
  padding: 4px;
  border-radius: 4px;
  color: var(--text-muted);
  transition: all var(--transition);
}

.chat-list-item:hover .chat-delete { opacity: 0.6; }
.chat-list-item .chat-delete:hover { opacity: 1; color: var(--red); background: var(--red-subtle); }

.chat-list-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  width: 100%;
  transition: background var(--transition);
  cursor: pointer;
}

.sidebar-user:hover { background: var(--bg-hover); }

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-user-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.sidebar-user-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 0.6875rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-logout {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 4px;
  transition: all var(--transition);
}

.sidebar-user-logout:hover { color: var(--red); background: var(--red-subtle); }

/* --- Main chat area --- */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  position: relative;
}

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  min-height: var(--nav-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-mobile-sidebar {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1.2rem;
  transition: background var(--transition);
}

.btn-mobile-sidebar:hover { background: var(--bg-hover); }

.top-bar-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-theme {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1.1rem;
  transition: all var(--transition);
}
.btn-theme:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-google-signin {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all var(--transition);
}

.btn-google-signin:hover {
  background: var(--bg-hover);
  border-color: var(--border-accent);
}

.btn-google-signin img {
  width: 18px;
  height: 18px;
}

.top-bar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius);
  transition: background var(--transition);
  cursor: pointer;
}

.top-bar-user:hover { background: var(--bg-hover); }

/* Messages area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}

.messages-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Welcome */
.welcome-block {
  text-align: center;
  padding: 48px 24px;
}

.welcome-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  border-radius: var(--radius-lg);
  box-shadow: 0 0 32px var(--accent-glow);
}

.welcome-title {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-title em { color: var(--accent); font-style: italic; }

.welcome-subtitle {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  max-width: 480px;
  margin: 0 auto 32px;
  line-height: 1.5;
}

.welcome-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 520px;
  margin: 0 auto;
}

.suggestion-chip {
  padding: 8px 16px;
  border-radius: 100px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  transition: all var(--transition);
  cursor: pointer;
  white-space: nowrap;
}

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

/* Message bubbles */
.message {
  display: flex;
  gap: 14px;
  padding: 16px 0;
  animation: msgIn 0.3s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.message.user .message-avatar {
  background: var(--accent-subtle);
  color: var(--accent);
}

.message.assistant .message-avatar {
  background: var(--green-subtle);
  color: var(--green);
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-role {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.message-text {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: break-word;
}

.message-text p { margin-bottom: 12px; }
.message-text p:last-child { margin-bottom: 0; }
.message-text ul, .message-text ol { margin: 8px 0; padding-left: 20px; }
.message-text li { margin-bottom: 4px; }
.message-text code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  border: 1px solid var(--border);
}

.message-text pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
}

.message-text pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: 0.8125rem;
  line-height: 1.6;
}

.message-text blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: var(--text-secondary);
  margin: 12px 0;
}

.message-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.8125rem;
}

.message-text th, .message-text td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.message-text th { background: var(--bg-tertiary); font-weight: 600; }

.message-text a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.input-area {
  padding: 0 24px 20px;
  flex-shrink: 0;
}

.input-container {
  max-width: 800px;
  margin: 0 auto;
  position: relative;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 18px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  padding: 8px 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text-primary);
  resize: none;
  max-height: 160px;
  min-height: 24px;
}

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

.btn-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  opacity: 0.5;
  pointer-events: none;
}

.btn-send.active {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.btn-send.active:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}

.btn-send svg { width: 18px; height: 18px; }

.input-hint {
  text-align: center;
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Google One Tap container */
.g_id_signin {
  display: none;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 0.8125rem;
  color: var(--text-primary);
  animation: toastIn 0.3s ease;
  max-width: 360px;
}

.toast.error { border-color: rgba(239,68,68,0.3); }
.toast.success { border-color: rgba(16,185,129,0.3); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Loading dots in message */
.message-text .streaming-cursor::after {
  content: ' ▌';
  animation: blink 1s infinite;
  color: var(--accent);
}

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

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; }
  .btn-mobile-sidebar { display: flex; }
  .messages-container { padding: 0 16px; }
  .input-area { padding: 0 12px 16px; }
  .welcome-title { font-size: 1.5rem; }
  .top-bar { padding: 0 12px; }
  .top-bar-title { max-width: 200px; }
}
