/* Lightico Copilot — UI design system. Vanilla CSS, no build step.
   Light + dark (prefers-color-scheme, with an explicit data-theme override). */

:root {
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-strong: #4338ca;
  --accent-soft: #eef2ff;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f2f6;
  --border: #e6e8ee;
  --text: #1b2233;
  --text-muted: #6b7280;
  --text-faint: #9aa1ad;
  --user-bubble: #4f46e5;
  --user-bubble-text: #ffffff;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --danger: #dc2626;
  --ok: #10b981;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .10);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #7c8cff;
    --accent-2: #a78bfa;
    --accent-strong: #6366f1;
    --accent-soft: #1e1f3a;
    --bg: #0c0e14;
    --surface: #14161f;
    --surface-2: #1b1e29;
    --border: #262a37;
    --text: #e7e9ee;
    --text-muted: #9aa1b1;
    --text-faint: #6b7280;
    --user-bubble: #4f46e5;
    --user-bubble-text: #ffffff;
    --code-bg: #0a0e1a;
    --code-text: #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #7c8cff; --accent-2: #a78bfa; --accent-strong: #6366f1; --accent-soft: #1e1f3a;
  --bg: #0c0e14; --surface: #14161f; --surface-2: #1b1e29; --border: #262a37;
  --text: #e7e9ee; --text-muted: #9aa1b1; --text-faint: #6b7280;
  --code-bg: #0a0e1a; --code-text: #cbd5e1;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow-md: 0 6px 20px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }

#newThread {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform .06s ease, filter .15s ease;
}
#newThread:hover { filter: brightness(1.06); }
#newThread:active { transform: translateY(1px); }

.side-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 0 6px; }
#threadList { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.thread {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13.5px; color: var(--text-muted);
  transition: background .12s ease, color .12s ease;
}
.thread:hover { background: var(--surface-2); color: var(--text); }
.thread.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.thread-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-del {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0; border: none; background: transparent;
  color: var(--text-faint); border-radius: 6px; cursor: pointer;
  opacity: 0; transition: opacity .12s ease, color .12s ease, background .12s ease;
}
.thread:hover .thread-del, .thread.active .thread-del { opacity: 1; }
.thread-del:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
@media (hover: none) { .thread-del { opacity: .6; } }

.side-foot { display: flex; align-items: center; justify-content: flex-end; padding: 6px; border-top: 1px solid var(--border); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; cursor: pointer; color: var(--text-muted);
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
#hamburger { display: none; }
#topTitle { font-weight: 600; font-size: 14px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#timeline {
  min-height: 0; height: 0; overflow: hidden;
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px; font-size: 13px; color: var(--accent-strong);
  background: var(--accent-soft); transition: height .2s ease, padding .2s ease;
}
#timeline.show { height: 40px; padding: 0 20px; }
#timeline.error { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }

#messages { flex: 1; overflow-y: auto; padding: 24px 20px; scroll-behavior: smooth; }
.wrap { max-width: 820px; margin: 0 auto; }

/* ---------- Messages ---------- */
.msg { margin-bottom: 22px; animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-bubble-text);
  padding: 11px 15px; border-radius: 16px 16px 4px 16px;
  max-width: 80%; font-size: 14.5px; line-height: 1.5; box-shadow: var(--shadow-sm);
}
.msg.assistant { display: flex; gap: 12px; }
.avatar { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.assistant .body { flex: 1; min-width: 0; }
.answer { font-size: 15px; line-height: 1.65; color: var(--text); }
.answer p { margin: 0 0 10px; }
.answer strong { font-weight: 700; }

/* Live activity stepper (in-progress assistant message) */
.activity {
  display: inline-flex; flex-direction: column; gap: 1px; margin-top: 2px;
  padding: 7px 14px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.step { display: flex; align-items: center; gap: 10px; padding: 5px 2px; font-size: 13.5px; line-height: 1.3; color: var(--text-muted); }
.step-icon { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; flex-shrink: 0; }
.step.done .step-icon { color: var(--ok); }
.step.active { color: var(--text); font-weight: 600; }
.step.active .step-icon { color: var(--accent); }
.step.warn .step-label { color: var(--danger); }
.step-spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent); animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); margin: 16px 0 8px; }

.insights { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 8px; }
.insights li { position: relative; padding: 10px 12px 10px 32px; background: var(--surface-2); border-radius: var(--radius-sm); font-size: 13.5px; line-height: 1.45; }
.insights li::before { content: "→"; position: absolute; left: 12px; color: var(--accent); font-weight: 700; }

img.chart { max-width: 100%; margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }

/* SQL disclosure */
.sql-wrap { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.sql-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--surface-2); cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.sql-head .meta { font-weight: 500; color: var(--text-faint); }
.copy-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); border-radius: 6px; padding: 3px 9px; font-size: 11px; cursor: pointer; }
.copy-btn:hover { color: var(--text); border-color: var(--accent); }
.sql-box { background: var(--code-bg); color: var(--code-text); padding: 12px 14px; font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; overflow-x: auto; margin: 0; }
.sql-wrap.collapsed .sql-box { display: none; }

.chips { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  border-radius: 18px; padding: 7px 13px; font-size: 13px; cursor: pointer;
  transition: all .12s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }

/* ---------- Empty state ---------- */
#empty { max-width: 620px; margin: 8vh auto 0; text-align: center; padding: 0 20px; }
#empty .hero-mark { width: 56px; height: 56px; border-radius: 15px; box-shadow: var(--shadow-md); margin-bottom: 18px; }
#empty h1 { font-size: 25px; letter-spacing: -.02em; margin: 0 0 8px; }
#empty p { color: var(--text-muted); font-size: 15px; margin: 0 0 26px; }
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.example {
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; font-size: 13.5px; color: var(--text);
  box-shadow: var(--shadow-sm); transition: transform .08s ease, border-color .12s ease;
}
.example:hover { border-color: var(--accent); transform: translateY(-2px); }
.example span { display: block; color: var(--text-faint); font-size: 11.5px; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Input ---------- */
#inputRow { padding: 14px 20px 18px; border-top: 1px solid var(--border); background: var(--surface); }
.input-box {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 16px;
  padding: 8px 8px 8px 16px; box-shadow: var(--shadow-sm); transition: border-color .15s ease;
}
.input-box:focus-within { border-color: var(--accent); }
#question {
  flex: 1; border: none; outline: none; resize: none; background: transparent; color: var(--text);
  font-size: 14.5px; line-height: 1.5; max-height: 160px; padding: 6px 0; font-family: inherit;
}
#question::placeholder { color: var(--text-faint); }
#ask {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; cursor: pointer;
  transition: filter .15s ease, transform .06s ease;
}
#ask:hover { filter: brightness(1.08); }
#ask:active { transform: translateY(1px); }
#ask:disabled { opacity: .45; cursor: not-allowed; }
.hint { max-width: 820px; margin: 8px auto 0; font-size: 11px; color: var(--text-faint); text-align: center; }

/* ---------- Responsive ---------- */
.scrim { display: none; }
@media (max-width: 760px) {
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: var(--shadow-md);
  }
  #sidebar.open { transform: none; }
  #hamburger { display: inline-flex; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
  .examples { grid-template-columns: 1fr; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .step-spinner { animation: none; }
  .msg { animation: none; }
}
