/* ============================================================
   ANTARMAN AI — Interface Styles
   Calm, white, minimal. One saffron accent, used sparingly.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --ground: #FCFCFA;
  --surface: #F4F3EF;
  --surface-2: #EEEDE7;
  --ink: #17160F;
  --muted: #6E6C62;
  --faint: #9A988E;
  --hairline: #E7E5DE;
  --accent: #C2620E;
  --accent-soft: #F6E9DC;
  --danger: #B4402B;

  --radius: 14px;
  --radius-lg: 20px;
  --sidebar-w: 280px;
  --measure: 720px;

  --sans: "Hanken Grotesk", "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --shadow-sm: 0 1px 2px rgba(23, 22, 15, 0.05);
  --shadow-md: 0 6px 24px rgba(23, 22, 15, 0.08);
  --shadow-lg: 0 18px 50px rgba(23, 22, 15, 0.14);

  --fs-body: 15.5px;
  --lh-body: 1.68;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #121210; --surface: #1B1A17; --surface-2: #232019;
    --ink: #F2F1EA; --muted: #9B988C; --faint: #6E6B60;
    --hairline: #2B2924; --accent: #E8944A; --accent-soft: #2A1E12;
    --danger: #E0765C;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 6px 24px rgba(0,0,0,0.5);
    --shadow-lg: 0 18px 50px rgba(0,0,0,0.6);
  }
}
:root[data-theme="light"] {
  --ground: #FCFCFA; --surface: #F4F3EF; --surface-2: #EEEDE7;
  --ink: #17160F; --muted: #6E6C62; --faint: #9A988E;
  --hairline: #E7E5DE; --accent: #C2620E; --accent-soft: #F6E9DC;
  --danger: #B4402B;
  --shadow-sm: 0 1px 2px rgba(23,22,15,0.05);
  --shadow-md: 0 6px 24px rgba(23,22,15,0.08);
  --shadow-lg: 0 18px 50px rgba(23,22,15,0.14);
}
:root[data-theme="dark"] {
  --ground: #121210; --surface: #1B1A17; --surface-2: #232019;
  --ink: #F2F1EA; --muted: #9B988C; --faint: #6E6B60;
  --hairline: #2B2924; --accent: #E8944A; --accent-soft: #2A1E12;
  --danger: #E0765C;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 6px 24px rgba(0,0,0,0.5);
  --shadow-lg: 0 18px 50px rgba(0,0,0,0.6);
}

/* Compact text-size mode */
:root[data-size="compact"] { --fs-body: 14.5px; --lh-body: 1.6; }

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button { font-family: inherit; }
::selection { background: var(--accent-soft); }

/* Thin themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--hairline) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }

/* ---------- Ambient glow ---------- */
.ambient {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(60% 45% at 50% 30%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 70%),
    radial-gradient(40% 30% at 85% 90%, color-mix(in srgb, var(--accent) 4%, transparent), transparent 70%);
}

/* ---------- App shell ---------- */
.app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; }

/* ---------- Icon buttons ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column;
  padding: 14px 12px 12px;
  transition: margin-left .28s cubic-bezier(.4,0,.2,1);
}
.app.collapsed .sidebar { margin-left: calc(var(--sidebar-w) * -1); }

.sidebar__top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; }
.brand {
  display: inline-flex; align-items: baseline; gap: 7px;
  text-decoration: none; color: var(--ink);
}
.brand__img { height: 20px; width: auto; display: block; }
.brand__text {
  font-weight: 800; font-size: 19px; letter-spacing: 0.04em;
  align-items: baseline;
}
.brand__ai {
  font-weight: 800; font-size: 13px; letter-spacing: 0.08em;
  color: var(--accent); transform: translateY(-1px);
}
@media (prefers-color-scheme: dark) { .brand__img { filter: invert(1) brightness(1.4); } }
:root[data-theme="dark"] .brand__img { filter: invert(1) brightness(1.4); }
:root[data-theme="light"] .brand__img { filter: none; }

.new-chat {
  display: flex; align-items: center; gap: 9px;
  width: 100%; margin-bottom: 12px; padding: 11px 13px;
  background: var(--ground); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: var(--radius);
  font-size: 14.5px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, background .15s ease, transform .05s ease;
}
.new-chat:hover { border-color: var(--accent); background: var(--ground); }
.new-chat:active { transform: scale(.99); }
.new-chat svg { color: var(--accent); }
.new-chat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 11px; margin-bottom: 8px;
  background: var(--ground); border: 1px solid var(--hairline);
  border-radius: 11px;
}
.search svg { color: var(--faint); flex: none; }
.search input {
  flex: 1; border: 0; background: transparent; outline: none;
  padding: 9px 0; font-size: 14px; color: var(--ink);
}
.search input::placeholder { color: var(--faint); }

.history { flex: 1; overflow-y: auto; margin: 6px -4px 0; padding: 0 4px; }
.history__group-label {
  position: sticky; top: 0; z-index: 1;
  padding: 12px 10px 5px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--faint);
  background: linear-gradient(var(--surface) 65%, transparent);
}
.history__item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  color: var(--muted); position: relative;
  transition: background .13s ease, color .13s ease;
}
.history__item:hover { background: var(--surface-2); color: var(--ink); }
.history__item.active { background: var(--accent-soft); color: var(--ink); }
.history__item.active::before {
  content: ""; position: absolute; left: 2px; top: 8px; bottom: 8px;
  width: 2.5px; border-radius: 3px; background: var(--accent);
}
.history__title {
  flex: 1; min-width: 0; font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history__menu {
  flex: none; opacity: 0; border: 0; background: transparent;
  color: var(--muted); cursor: pointer; border-radius: 7px;
  width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  transition: opacity .13s ease, background .13s ease;
}
.history__item:hover .history__menu,
.history__item.active .history__menu { opacity: 1; }
.history__menu:hover { background: rgba(0,0,0,.06); color: var(--ink); }
:root[data-theme="dark"] .history__menu:hover { background: rgba(255,255,255,.08); }
.history__empty { padding: 18px 10px; color: var(--faint); font-size: 13.5px; }

.history__rename {
  flex: 1; min-width: 0; font: inherit; font-size: 14px;
  border: 1px solid var(--accent); border-radius: 7px; padding: 3px 7px;
  background: var(--ground); color: var(--ink); outline: none;
}

/* context menu */
.ctx {
  position: fixed; z-index: 60; min-width: 150px;
  background: var(--ground); border: 1px solid var(--hairline);
  border-radius: 11px; box-shadow: var(--shadow-md); padding: 5px;
}
.ctx button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border: 0; background: transparent; cursor: pointer;
  border-radius: 8px; font-size: 13.5px; color: var(--ink); text-align: left;
}
.ctx button:hover { background: var(--surface-2); }
.ctx button.danger { color: var(--danger); }
.ctx button.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.sidebar__footer { border-top: 1px solid var(--hairline); padding-top: 8px; margin-top: 4px; }
.footer-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; background: transparent; cursor: pointer;
  border-radius: 10px; color: var(--muted); font-size: 14px; font-weight: 500;
  transition: background .13s ease, color .13s ease;
}
.footer-row:hover { background: var(--surface-2); color: var(--ink); }
.footer-row.account { cursor: default; }
.footer-row.account:hover { background: transparent; color: var(--muted); }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 999px; flex: none;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
}

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

.topbar {
  display: flex; align-items: center; gap: 6px;
  height: 56px; padding: 0 14px; flex: none;
  border-bottom: 1px solid transparent;
}
.topbar__menu { display: none; }
.topbar__title {
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
  margin: 0; padding: 4px 8px; border-radius: 8px; cursor: pointer;
  color: var(--ink); max-width: 50vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__title:hover { background: var(--surface-2); }
.topbar__spacer { flex: 1; }

/* ---------- Thread ---------- */
.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages { max-width: var(--measure); margin: 0 auto; padding: 16px 24px 40px; display: flex; flex-direction: column; gap: 26px; }

/* Empty state */
.empty {
  max-width: var(--measure); margin: 0 auto;
  min-height: calc(100vh - 220px); min-height: calc(100dvh - 220px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px 24px; gap: 4px;
}
.empty.hidden { display: none; }
.empty__mark { margin-bottom: 6px; }
.empty__logo { height: 46px; width: auto; }
@media (prefers-color-scheme: dark) { .empty__logo { filter: invert(1) brightness(1.4); } }
:root[data-theme="dark"] .empty__logo { filter: invert(1) brightness(1.4); }
:root[data-theme="light"] .empty__logo { filter: none; }
.empty__wordmark { font-size: 40px; font-weight: 800; letter-spacing: 0.05em; align-items: baseline; gap: 10px; }
.empty__ai { color: var(--accent); font-size: 22px; }
.empty__tagline { color: var(--muted); font-size: 14px; margin: 8px 0 0; letter-spacing: 0.01em; }
.empty__greeting {
  font-size: clamp(24px, 4vw, 33px); font-weight: 700; letter-spacing: -0.02em;
  margin: 22px 0 26px; text-wrap: balance; max-width: 18ch;
}
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 560px; }
.chip {
  padding: 10px 15px; border: 1px solid var(--hairline); border-radius: 999px;
  background: var(--ground); color: var(--ink); font-size: 13.5px; font-weight: 500;
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, transform .05s ease, background .15s ease;
}
.chip:hover { border-color: var(--accent); background: var(--surface); }
.chip:active { transform: scale(.98); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Messages ---------- */
.msg { display: flex; gap: 14px; animation: rise .32s cubic-bezier(.21,1.02,.73,1) both; }
.msg.user { justify-content: flex-end; }

.msg__avatar {
  flex: none; width: 30px; height: 30px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--ground); overflow: hidden;
  margin-top: 1px;
}
.msg__avatar img { width: 100%; height: 100%; object-fit: contain; padding: 5px; }
@media (prefers-color-scheme: dark){ .msg__avatar img { filter: invert(1) brightness(1.4); } }
:root[data-theme="dark"] .msg__avatar img { filter: invert(1) brightness(1.4); }
:root[data-theme="light"] .msg__avatar img { filter: none; }

.msg__col { min-width: 0; max-width: 100%; }
.msg.assistant .msg__col { flex: 1; }

.bubble { font-size: var(--fs-body); }
.msg.user .bubble {
  background: var(--surface); border: 1px solid var(--hairline);
  padding: 11px 15px; border-radius: 16px 16px 5px 16px; max-width: min(78%, 560px);
  box-shadow: var(--shadow-sm);
}
.msg.assistant .bubble { padding-top: 3px; }

/* Assistant markdown typography */
.bubble p { margin: 0 0 0.7em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }
.bubble h1, .bubble h2, .bubble h3 { font-weight: 700; letter-spacing: -0.01em; margin: 1em 0 .4em; line-height: 1.3; }
.bubble h1 { font-size: 1.28em; }
.bubble h2 { font-size: 1.15em; }
.bubble h3 { font-size: 1.04em; }
.bubble ul, .bubble ol { margin: .5em 0 .8em; padding-left: 1.4em; display: flex; flex-direction: column; gap: .35em; }
.bubble ul { list-style: disc; }
.bubble ol { list-style: decimal; }
.bubble li::marker { color: var(--accent); }
.bubble code {
  font-family: var(--mono); font-size: .87em;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 6px; padding: .12em .4em; color: var(--accent);
}

/* message hover toolbar */
.msg__tools { display: flex; gap: 4px; margin-top: 8px; opacity: 0; transition: opacity .15s ease; }
.msg.assistant:hover .msg__tools, .msg__tools:focus-within { opacity: 1; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 12px; font-weight: 500; padding: 4px 7px; border-radius: 7px;
}
.tool-btn:hover { background: var(--surface-2); color: var(--ink); }
.tool-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* typing indicator */
.typing { display: inline-flex; align-items: center; gap: 6px; padding: 6px 0; }
.typing span {
  width: 8px; height: 8px; border-radius: 999px; background: var(--accent);
  animation: pulse 1.2s infinite ease-in-out; opacity: .4;
}
.typing span:nth-child(2){ animation-delay: .18s; }
.typing span:nth-child(3){ animation-delay: .36s; }

@keyframes pulse { 0%,60%,100%{ transform: translateY(0) scale(.8); opacity:.35 } 30%{ transform: translateY(-5px) scale(1); opacity:1 } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Composer ---------- */
.composer-wrap { flex: none; padding: 6px 24px 14px; }
.composer {
  max-width: var(--measure); margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--ground); border: 1px solid var(--hairline);
  border-radius: var(--radius-lg); padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--hairline));
  box-shadow: var(--shadow-md), 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
}
.composer__input {
  flex: 1; border: 0; background: transparent; outline: none; resize: none;
  font-family: inherit; font-size: var(--fs-body); line-height: 1.55; color: var(--ink);
  max-height: 184px; padding: 8px 0;
}
.composer__input::placeholder { color: var(--faint); }
.send {
  flex: none; width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: var(--accent); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: filter .15s ease, transform .06s ease, background .15s ease, opacity .15s ease;
}
.send:hover:not(:disabled) { filter: brightness(1.07); }
.send:active:not(:disabled) { transform: scale(.94); }
.send:disabled { background: var(--surface-2); color: var(--faint); cursor: not-allowed; }
.send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.disclaimer { max-width: var(--measure); margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--faint); }

/* ============================================================
   SETTINGS PANEL + SCRIMS
   ============================================================ */
.scrim, .panel-scrim {
  position: fixed; inset: 0; z-index: 40; background: rgba(23,22,15,.34);
  opacity: 0; pointer-events: none; transition: opacity .22s ease;
  -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px);
}
.scrim.show, .panel-scrim.show { opacity: 1; pointer-events: auto; }
.scrim { z-index: 30; display: none; }

.panel {
  position: fixed; top: 0; right: 0; z-index: 50; height: 100%;
  width: min(420px, 92vw); background: var(--ground);
  border-left: 1px solid var(--hairline); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.panel.open { transform: none; }
.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 14px; border-bottom: 1px solid var(--hairline);
}
.panel__head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.panel__body { padding: 20px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 24px; }

.field { display: flex; flex-direction: column; gap: 9px; }
.field__label { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.field__hint { margin: 0; font-size: 12.5px; color: var(--faint); }

.segmented { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--hairline); border-radius: 11px; padding: 4px; }
.segmented button {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  padding: 8px 6px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted);
  transition: background .14s ease, color .14s ease;
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: var(--ground); color: var(--ink); box-shadow: var(--shadow-sm); }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.danger-btn {
  width: 100%; padding: 11px; border-radius: 11px; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--hairline));
  background: transparent; color: var(--danger); font-size: 14px; font-weight: 600;
  transition: background .14s ease;
}
.danger-btn:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.about { border-top: 1px solid var(--hairline); padding-top: 16px; }
.about p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.about__safe { color: var(--faint); font-size: 12.5px; }

/* confirm dialog */
.confirm-scrim {
  position: fixed; inset: 0; z-index: 70; display: none;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(23,22,15,.4);
}
.confirm-scrim.show { display: flex; }
.confirm {
  background: var(--ground); border: 1px solid var(--hairline);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 22px; max-width: 360px; width: 100%;
  animation: rise .2s ease both;
}
.confirm p { margin: 0 0 18px; font-size: 15px; }
.confirm__actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-ghost, .btn-danger {
  padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-ghost { border: 1px solid var(--hairline); background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--surface); }
.btn-danger { border: 0; background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 35; height: 100%;
    margin-left: calc(var(--sidebar-w) * -1); box-shadow: var(--shadow-lg);
  }
  .app.drawer-open .sidebar { margin-left: 0; }
  .app.collapsed .sidebar { margin-left: calc(var(--sidebar-w) * -1); }
  .scrim { display: block; }
  .sidebar__collapse { display: none; }
  .topbar__menu { display: inline-flex; }
  .messages, .composer, .disclaimer, .empty { padding-left: 16px; padding-right: 16px; }
  .composer-wrap { padding-left: 14px; padding-right: 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

/* Desktop: hide the mobile menu, but reveal it when the sidebar is collapsed
   so there is always a way to bring the sidebar back. */
@media (min-width: 821px) {
  .topbar__menu { display: none; }
  .app.collapsed .topbar__menu { display: inline-flex; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
