/* ==========================================================================
   Chairman AI Assistant — chat UI
   ========================================================================== */

:root {
  --bg: #0a0d13;
  --panel: #12161f;
  --panel-alt: #171c27;
  --panel-raised: #1b2130;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e9ecf3;
  --text-muted: #8891a3;
  --text-faint: #5b6474;
  --accent: #35d0b8;
  --accent-hover: #4bdcc6;
  --accent-contrast: #04211d;
  --accent-soft: rgba(53, 208, 184, 0.12);
  --danger: #f0576a;
  --danger-soft: rgba(240, 87, 106, 0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Newsreader", Georgia, serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-alt: #f5f7fa;
  --panel-raised: #ffffff;
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #13151c;
  --text-muted: #5c6473;
  --text-faint: #97a0b0;
  --accent: #0e9c8a;
  --accent-hover: #0c8778;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(14, 156, 138, 0.1);
  --danger: #d43a4f;
  --danger-soft: rgba(212, 58, 79, 0.08);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.12);
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f8;
    --panel: #ffffff;
    --panel-alt: #f5f7fa;
    --panel-raised: #ffffff;
    --border: rgba(15, 23, 42, 0.09);
    --border-strong: rgba(15, 23, 42, 0.16);
    --text: #13151c;
    --text-muted: #5c6473;
    --text-faint: #97a0b0;
    --accent: #0e9c8a;
    --accent-hover: #0c8778;
    --accent-contrast: #ffffff;
    --accent-soft: rgba(14, 156, 138, 0.1);
    --danger: #d43a4f;
    --danger-soft: rgba(212, 58, 79, 0.08);
    --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.12);
    --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.06);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; }

.app {
  height: 100dvh;
  width: 100%;
  position: relative;
}

/* ---------------------------------------------------------------------- */
/* Login view                                                              */
/* ---------------------------------------------------------------------- */

.login-view {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(60% 50% at 15% 10%, var(--accent-soft), transparent 60%),
    radial-gradient(50% 40% at 90% 90%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.brand-mark {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(155deg, var(--accent), var(--accent-hover));
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.brand-text h1 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.field input {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 14.5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-error {
  margin: -4px 0 0;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
}

.login-footnote {
  margin: 22px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                  */
/* ---------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 11px 16px;
}

.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; }

.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

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

/* ---------------------------------------------------------------------- */
/* Chat view                                                                */
/* ---------------------------------------------------------------------- */

.chat-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark-sm {
  width: 34px;
  height: 34px;
  font-size: 10.5px;
  border-radius: 9px;
}

.topbar-titles h1 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.topbar-titles p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
}

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 6px 5px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 6px;
}

.user-chip button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.user-chip button:hover { background: var(--panel-raised); color: var(--danger); }

/* Messages ---------------------------------------------------------------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 12px;
  scroll-behavior: smooth;
}

.messages-inner,
.messages > * {
  max-width: 760px;
  margin: 0 auto;
}

.empty-state {
  max-width: 560px;
  margin: 8vh auto 0;
  text-align: center;
  padding: 0 12px;
}

.empty-state-mark {
  font-size: 40px;
  margin-bottom: 14px;
  filter: saturate(0.9);
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
  font-family: var(--font-serif);
}

.empty-state p {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.55;
}

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

@media (max-width: 560px) {
  .suggestions { grid-template-columns: 1fr; }
}

.suggestion-chip {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  line-height: 1.4;
}

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

.msg-row {
  display: flex;
  margin: 0 auto 18px;
  max-width: 760px;
}

.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.bubble {
  max-width: 82%;
  border-radius: var(--radius-md);
  padding: 12px 15px;
  font-size: 14.5px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-row.user .bubble {
  background: var(--accent);
  color: var(--accent-contrast);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.msg-row.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  white-space: normal;
}

.msg-row.assistant .bubble.error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.bubble.pending { display: flex; align-items: center; gap: 10px; color: var(--text-muted); }

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: pulse 1.1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.bubble.cancelled { color: var(--text-muted); font-style: italic; }

/* Markdown content inside assistant bubbles */
.bubble :is(h1, h2, h3) { font-size: 1.05em; margin: 0.6em 0 0.35em; }
.bubble p { margin: 0 0 0.7em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 0.7em; padding-left: 1.3em; }
.bubble li { margin: 0.2em 0; }
.bubble strong { font-weight: 700; }
.bubble code {
  background: var(--panel-alt);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.88em;
}
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }

.bubble .table-scroll { overflow-x: auto; margin: 0.4em 0 0.8em; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.bubble table { border-collapse: collapse; width: 100%; font-size: 0.92em; }
.bubble th, .bubble td { padding: 7px 11px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.bubble thead th { background: var(--panel-alt); font-weight: 600; color: var(--text-muted); font-size: 0.86em; text-transform: uppercase; letter-spacing: 0.02em; }
.bubble tbody tr:last-child td { border-bottom: none; }
.bubble tbody tr:hover td { background: var(--panel-alt); }

.tool-trace {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool-chip {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tool-chip::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.msg-actions {
  margin-top: 8px;
  display: flex;
  gap: 10px;
}

.msg-actions button {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 11.5px;
  cursor: pointer;
  padding: 0;
}

.msg-actions button:hover { color: var(--text-muted); }

/* Composer ------------------------------------------------------------- */

.composer {
  flex: none;
  padding: 12px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.composer-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#composer-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  max-height: 160px;
  padding: 7px 0;
}

#composer-input::placeholder { color: var(--text-faint); }

.composer-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}

.composer-btn:active { transform: scale(0.94); }

.composer-btn-send {
  background: var(--accent);
  color: var(--accent-contrast);
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
  transition: filter 0.15s ease, transform 0.05s ease, opacity 0.15s ease;
}

.composer-btn-send.is-visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.composer-btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.composer-btn-send:not(:disabled):hover { filter: brightness(1.08); }

.composer-btn-stop {
  background: var(--danger);
  color: #fff;
  display: none;
}

.composer-btn-stop.is-visible { display: flex; }

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

/* ---------------------------------------------------------------------- */
/* View switching                                                           */
/* ---------------------------------------------------------------------- */

.login-view, .chat-view { display: none; }
.app[data-view="login"] .login-view { display: flex; }
.app[data-view="chat"] .chat-view { display: flex; }

.app[data-view="loading"]::after {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--bg);
}

/* Scrollbars */
.messages::-webkit-scrollbar { width: 9px; }
.messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }

/* Sun/moon icon visibility is toggled directly in JS via the hidden attribute. */
