:root {
  --bg-0: #0A0E14;
  --bg-1: #0F1520;
  --bg-2: #161D2C;
  --bg-3: #1E2638;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-1: #E6EDF3;
  --text-2: #8B96A8;
  --text-3: #4F5969;
  --accent: #3DFFC0;
  --accent-soft: rgba(61, 255, 192, 0.12);
  --meta: #1877F2;
  --danger: #FF5470;
  --font-display: 'Syne', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }

.screen { min-height: 100vh; display: flex; }
.screen.hidden { display: none; }

/* ============== LOGIN ============== */
#login-screen {
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
#login-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 70% 20%, rgba(61, 255, 192, 0.08), transparent 50%),
    radial-gradient(circle at 20% 80%, rgba(24, 119, 242, 0.10), transparent 50%);
  pointer-events: none;
}
.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(circle at center, black 0%, transparent 70%);
  opacity: 0.3;
  pointer-events: none;
}
.login-card {
  position: relative;
  max-width: 460px;
  width: calc(100% - 32px);
  padding: 48px 44px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  z-index: 1;
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 36px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.01em;
}
.logo-mark {
  color: var(--accent);
  font-size: 22px;
  text-shadow: 0 0 16px rgba(61, 255, 192, 0.4);
}
.login-title {
  font-family: var(--font-display);
  font-size: 44px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 18px;
}
.login-subtitle {
  color: var(--text-2);
  margin-bottom: 24px;
  font-size: 14.5px;
}
.login-features {
  list-style: none;
  margin-bottom: 32px;
  display: grid;
  gap: 8px;
}
.login-features li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text-2);
}
.check {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}
.btn-meta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--meta);
  color: white;
  text-decoration: none;
  font-weight: 600;
  border-radius: var(--r-md);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
  justify-content: center;
}
.btn-meta:hover {
  background: #166FE5;
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(24, 119, 242, 0.25);
}
.login-disclaimer {
  margin-top: 18px;
  color: var(--text-3);
  font-size: 12px;
  text-align: center;
}
.login-error {
  margin-top: 16px;
  padding: 12px 16px;
  background: rgba(255, 84, 112, 0.1);
  border: 1px solid rgba(255, 84, 112, 0.3);
  color: var(--danger);
  border-radius: var(--r-md);
  font-size: 13px;
}
.login-error.hidden { display: none; }

/* ============== APP ============== */
#app-screen { background: var(--bg-0); height: 100vh; overflow: hidden; }

.sidebar {
  width: 280px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  gap: 28px;
  flex-shrink: 0;
  overflow-y: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
}
.sidebar-section { display: flex; flex-direction: column; gap: 10px; }
.sidebar-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  font-weight: 600;
}
.user-info {
  padding: 12px 14px;
  background: var(--bg-2);
  border-radius: var(--r-md);
}
.user-info .user-name { font-weight: 600; font-size: 14px; }
.user-info .user-email { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.ad-accounts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}
.account-item {
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.account-item:hover { border-color: var(--border-strong); background: var(--bg-3); }
.account-item.active { border-color: var(--accent); background: var(--accent-soft); }
.account-item .account-name { font-weight: 600; }
.account-item .account-meta { color: var(--text-3); font-size: 11px; margin-top: 2px; }
.loading, .empty-msg {
  font-size: 12px;
  color: var(--text-3);
  padding: 8px;
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-1);
  padding: 10px 14px;
  border-radius: var(--r-md);
  cursor: pointer;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.btn-ghost:hover { border-color: var(--border-strong); background: var(--bg-2); }
.sidebar-footer { margin-top: auto; }

/* Chat */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}
.chat-header {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.chat-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
}
.status-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--accent);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.welcome {
  max-width: 740px;
  margin: 24px auto;
  text-align: left;
  width: 100%;
}
.welcome h3 {
  font-family: var(--font-display);
  font-size: 30px;
  margin-bottom: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.welcome p { color: var(--text-2); margin-bottom: 12px; }
.welcome-hint { font-size: 13px; color: var(--text-3); margin: 18px 0 12px; }
.prompt-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  padding: 11px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.message {
  max-width: 740px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  gap: 14px;
}
.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
  font-size: 11px;
  font-family: var(--font-display);
}
.message.user .message-avatar { background: var(--accent); color: var(--bg-0); }
.message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--accent), var(--meta));
  color: var(--bg-0);
}
.message-content {
  flex: 1;
  padding-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.65;
}
.message-content code {
  background: var(--bg-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.92em;
  font-family: 'SF Mono', Menlo, monospace;
}
.message-content pre {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: var(--r-md);
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
}
.message-content strong { color: var(--text-1); font-weight: 600; }
.message-content a { color: var(--accent); text-decoration: none; }
.message-content a:hover { text-decoration: underline; }
.message-thinking {
  color: var(--text-3);
  font-style: italic;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.message-thinking::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--text-3);
  border-radius: 50%;
  animation: blink 1.4s infinite;
}
@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.chat-form {
  display: flex;
  gap: 12px;
  padding: 20px 32px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  align-items: flex-end;
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  padding: 14px 16px;
  border-radius: var(--r-md);
  resize: none;
  font: inherit;
  font-size: 14.5px;
  max-height: 200px;
  transition: border-color 0.15s;
}
#chat-input::placeholder { color: var(--text-3); }
#chat-input:focus { outline: none; border-color: var(--accent); }
.btn-send {
  background: var(--accent);
  color: var(--bg-0);
  border: none;
  border-radius: var(--r-md);
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { transform: scale(1.05); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

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

/* Mobile */
@media (max-width: 900px) {
  .sidebar { width: 240px; padding: 16px; gap: 20px; }
  .login-title { font-size: 36px; }
  .login-card { padding: 36px 28px; }
  .messages, .chat-form, .chat-header { padding-left: 20px; padding-right: 20px; }
}
@media (max-width: 600px) {
  #app-screen { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 12px;
    gap: 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-section, .sidebar-header, .sidebar-footer { flex-shrink: 0; }
  .ad-accounts { flex-direction: row; max-height: none; }
  .account-item { white-space: nowrap; }
  .chat-main { height: calc(100vh - 80px); }
  .messages { padding: 16px; }
  .chat-form { padding: 12px 16px; }
}
