/* Artemii v2: tokens, layout, sidebar, top bar, menus, dialogs, toasts. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #faf9f5; --bg-soft: #f1efe8; --bg-soft2: #e9e6dc; --panel: #ffffff;
  --side: #f4f2ea; --side-hover: #eae7dc; --side-active: #e3dfd2;
  --text: #1f1e1b; --muted: #6a665d; --border: #e4e0d4; --border-strong: #d3cebf;
  --bubble: #efece2; --code-bg: #f4f2eb;
  --accent: #ffa800; --accent-text: #8a5200; --accent-ring: #b36b00; --accent-soft: rgba(255, 168, 0, 0.18);
  --danger: #b4232a; --danger-bg: #fcecea; --danger-border: #efbcb7; --ok: #1e7a3a; --ok-bg: #e2f2e7;
  --warn-bg: #fff3d6; --warn-border: #efd48a; --warn-text: #7a4b00;
  --shadow: 0 1px 2px rgba(31, 30, 27, 0.05), 0 10px 30px rgba(31, 30, 27, 0.09);
  --shadow-sm: 0 1px 2px rgba(31, 30, 27, 0.06);
  --scrim: rgba(31, 30, 27, 0.45);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #211f1c; --bg-soft: #2a2825; --bg-soft2: #34322e; --panel: #2a2825;
  --side: #1a1917; --side-hover: #262421; --side-active: #302d29;
  --text: #ece8de; --muted: #a29d91; --border: #38352f; --border-strong: #4a463f;
  --bubble: #2f2c28; --code-bg: #1b1a18;
  --accent: #ffa800; --accent-text: #ffb52e; --accent-ring: #ffa800; --accent-soft: rgba(255, 168, 0, 0.16);
  --danger: #ff8a8e; --danger-bg: #3a1a1c; --danger-border: #6d2e32; --ok: #6fd593; --ok-bg: #16301f;
  --warn-bg: #33270b; --warn-border: #67501a; --warn-text: #ffcf70;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 36px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --scrim: rgba(0, 0, 0, 0.6);
}
:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --msg-font: var(--serif); --msg-size: 16.5px; --msg-lh: 1.65;
  --sidebar-w: 268px; --panel-w: clamp(400px, 46vw, 760px);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}
:root[data-font="readable"] { --msg-font: var(--font); --msg-lh: 1.7; }
:root[data-font="mono"] { --msg-font: var(--mono); --msg-lh: 1.7; }
:root[data-size="small"] { --msg-size: 15px; }
:root[data-size="large"] { --msg-size: 18.5px; }
:root[data-font="mono"][data-size="medium"] { --msg-size: 14.5px; }
:root[data-font="mono"][data-size="small"] { --msg-size: 13.5px; }
:root[data-font="mono"][data-size="large"] { --msg-size: 16px; }

html, body { height: 100%; }
body { overflow: hidden; background: var(--bg); transition: background-color 0.15s; }
#root { height: 100%; }
/* Boot splash: a centred spinning mark. Fades in after ~250ms so quick loads never flash it. */
.boot-splash { height: 100%; display: grid; place-items: center; animation: splash-in 0.3s ease-out 0.25s both; }
.boot-splash .logo-mark { width: 40px; height: 40px; }
@keyframes splash-in { from { opacity: 0; } to { opacity: 1; } }
.boot-splash.view-loading { height: auto; flex: 1; min-height: 0; }
@keyframes pulse { 50% { opacity: 0.35; } }

button { font: inherit; color: inherit; }
kbd { font-family: var(--font); font-size: 11px; background: var(--bg-soft2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--muted); }
.small { font-size: 12.5px; }
.btn-danger-quiet { color: var(--danger); background: transparent; border-color: var(--danger-border); }
.btn-danger-quiet:hover { background: var(--danger-bg); }
.form-error { color: var(--danger); margin: 0.5rem 0 0; min-height: 1em; font-size: 13px; }
.rename-input { width: 100%; height: 28px; font-size: inherit; background: var(--panel); border-color: var(--accent-ring); }

/* ---------- shell ---------- */
.app { height: 100%; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) auto; transition: grid-template-columns 0.22s var(--ease); position: relative; }
.app.sidebar-collapsed { grid-template-columns: 0 minmax(0, 1fr) auto; }
.main { min-width: 0; height: 100%; position: relative; background: var(--bg); overflow: hidden; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; animation: fade-in 0.18s ease-out; }
@keyframes fade-in { from { opacity: 0; } }
.artifact-root { min-width: 0; height: 100%; overflow: hidden; position: relative; }
.scrim { display: none; }
.offline-bar { position: fixed; left: 50%; top: 10px; transform: translateX(-50%); z-index: 90; display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); font-size: 13px; box-shadow: var(--shadow); }

/* ---------- sidebar ---------- */
.sidebar { background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; overflow: hidden; height: 100%; }
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 16px; }
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; letter-spacing: -0.015em; color: var(--text); text-decoration: none; border-radius: 8px; }
.brand .logo-mark { margin-left: -1px; }
.sb-close { display: inline-flex; }
.sb-actions { padding: 6px 8px 4px; display: grid; gap: 2px; }
.sb-action { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 9px; border: 0; background: transparent; color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; text-align: left; width: 100%; }
.sb-action:hover { background: var(--side-hover); }
.sb-new { background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow-sm); margin-bottom: 4px; }
.sb-new:hover { background: var(--panel); border-color: var(--border-strong); }
.sb-new svg { color: var(--accent-text); }
.sb-action .kbd-hint, .sb-action kbd { margin-left: auto; opacity: 0; transition: opacity 0.15s; font-size: 10.5px; }
.sb-action:hover kbd, .sb-action:focus-visible kbd { opacity: 1; }
.sb-scroll { flex: 1; overflow-y: auto; padding: 6px 8px 12px; scrollbar-width: thin; }
.sec { margin-top: 10px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; padding-right: 2px; }
.sec-toggle { display: flex; align-items: center; gap: 4px; background: none; border: 0; cursor: pointer; padding: 4px 8px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); border-radius: 6px; }
.sec-toggle:hover { color: var(--text); }
.sec-count { font-weight: 500; }
.sec-add { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.sec-add:hover { background: var(--side-hover); color: var(--text); }
.sec-body { display: grid; gap: 1px; }
.chat-item { position: relative; display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 6px 0 10px; border-radius: 9px; color: var(--text); text-decoration: none; font-size: 14px; cursor: pointer; }
.chat-item:hover { background: var(--side-hover); }
.chat-item.active { background: var(--side-active); font-weight: 550; }
.ci-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-pin { color: var(--muted); display: inline-flex; }
.ci-more { opacity: 0; width: 26px; height: 26px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; flex: none; }
.chat-item:hover .ci-more, .chat-item:focus-within .ci-more, .ci-more:focus-visible { opacity: 1; }
.ci-more:hover { background: var(--side-active); color: var(--text); }
.ci-run { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; flex: none; }
.project-item svg { color: var(--muted); flex: none; }
.more-link, .archived-link { color: var(--muted); }
.archived-link { margin-top: 14px; }
.archived-link svg { flex: none; }
.sb-empty { color: var(--muted); font-size: 13px; padding: 4px 10px 6px; }
.sb-empty.pad { padding: 14px 10px; }
.load-more { margin: 8px 10px; }
.sb-skel { display: grid; gap: 10px; padding: 14px 8px; }
.sk { background: linear-gradient(90deg, var(--bg-soft2), var(--bg-soft), var(--bg-soft2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-row { height: 18px; }
.w40 { width: 40%; } .w50 { width: 50%; } .w60 { width: 60%; } .w70 { width: 70%; } .w75 { width: 75%; } .w80 { width: 80%; } .w90 { width: 90%; } .w100 { width: 100%; }
.sb-foot { border-top: 1px solid var(--border); padding: 8px; display: grid; gap: 6px; }
.profile { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; background: transparent; border-radius: 10px; cursor: pointer; text-align: left; }
.profile:hover { background: var(--side-hover); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #1a1100; font-size: 12px; font-weight: 700; flex: none; }
.profile-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.profile-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-plan { font-size: 11.5px; text-transform: capitalize; }
.meter-wrap[hidden] { display: none; }
.meter { width: 100%; border: 0; background: transparent; padding: 7px 8px 6px; border-radius: 10px; cursor: pointer; text-align: left; display: grid; gap: 6px; }
.meter:hover { background: var(--side-hover); }
.meter-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.meter-pct { font-weight: 600; color: var(--text); }
.meter-warn .meter-pct { color: var(--warn-text); }
.meter-full .meter-pct { color: var(--danger); }
.bar { display: block; height: 6px; border-radius: 999px; background: var(--bg-soft2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.5s var(--ease); }
.bar-warn .bar-fill { background: #e07b00; }
.bar-full .bar-fill { background: var(--danger); }

/* ---------- top bar ---------- */
.topbar { flex: none; height: 52px; display: flex; align-items: center; gap: 4px; padding: 0 12px 0 10px; min-width: 0; }
.tb-menu { display: none; }
.app.sidebar-collapsed .tb-menu { display: inline-flex; }
.tb-title { min-width: 0; max-width: 46ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; background: transparent; font-size: 14.5px; font-weight: 600; padding: 5px 9px; border-radius: 8px; cursor: pointer; color: var(--text); }
.tb-title:hover { background: var(--bg-soft); }
.tb-title.static { cursor: default; }
.tb-title.static:hover { background: none; }
.tb-crumb-host { display: contents; }
.tb-crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: 14px; padding: 5px 6px 5px 9px; border-radius: 8px; white-space: nowrap; }
.tb-crumb:hover { color: var(--text); background: var(--bg-soft); }
.tb-sep { color: var(--border-strong); }
.tb-spacer { flex: 1; }
.tb-actions { display: flex; gap: 4px; align-items: center; }
.tb-share svg { color: var(--muted); }

/* ---------- menus, popovers ---------- */
.menu, .popover { position: fixed; z-index: 100; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); animation: pop 0.12s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
.menu { min-width: 200px; padding: 5px; outline: none; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; text-align: left; font-size: 13.5px; color: var(--text); }
.menu-item:hover, .menu-item:focus-visible { background: var(--bg-soft); outline: none; box-shadow: none; }
.menu-item svg { color: var(--muted); flex: none; }
.menu-item.danger, .menu-item.danger svg { color: var(--danger); }
.menu-item:disabled { opacity: 0.45; cursor: default; }
.menu-ico { width: 16px; }
.menu-label { flex: 1; }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.menu-heading { padding: 6px 10px 4px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.popover { padding: 16px; width: 300px; outline: none; }
.pop-title { font-weight: 650; margin-bottom: 10px; }
.pop-note { font-size: 12.5px; margin: 12px 0; }
.usage-rows { display: grid; gap: 16px; }
.usage-row { display: grid; gap: 6px; }
.usage-row-head { display: flex; justify-content: space-between; font-size: 13.5px; }
.usage-row .bar { height: 8px; }
.usage-reset { font-size: 12.5px; }

/* ---------- dialogs (override shared) ---------- */
dialog.dlg { border-radius: 16px; background: var(--panel); border-color: var(--border); box-shadow: var(--shadow); }
dialog.dlg::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
dialog.dlg[open] { animation: pop 0.16s ease-out; }
.dlg-title { font-size: 17px; margin-bottom: 12px; }
.pick-list { display: grid; gap: 4px; max-height: 320px; overflow: auto; margin: 4px 0; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: transparent; cursor: pointer; text-align: left; font-size: 14px; }
.pick-item span { flex: 1; }
.pick-item:hover { background: var(--bg-soft); }
.pick-item.on { border-color: var(--accent-ring); background: var(--accent-soft); }
.share-row { display: flex; gap: 8px; margin-top: 8px; }
.share-row input { flex: 1; min-width: 0; }

/* ---------- toasts ---------- */
.toasts { position: fixed; z-index: 120; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; width: min(92vw, 460px); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 14px; background: #2b2924; color: #f5f2ea; border-radius: 12px; box-shadow: var(--shadow); font-size: 13.5px; animation: toast-in 0.2s var(--ease); max-width: 100%; }
:root[data-theme="dark"] .toast { background: #efebe0; color: #1f1e1b; }
.toast-error { background: #7d1d22; color: #fff; }
:root[data-theme="dark"] .toast-error { background: #ffb4b7; color: #3a0b0e; }
.toast-msg { flex: 1; }
.toast-action { background: none; border: 0; color: var(--accent); font-weight: 650; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
:root[data-theme="dark"] .toast-action { color: #8a5200; }
.toast-x { background: none; border: 0; color: inherit; opacity: 0.6; cursor: pointer; display: grid; place-items: center; padding: 2px; }
.toast-x:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive shell ---------- */
@media (max-width: 800px) {
  .app, .app.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 60; transform: translateX(-102%); transition: transform 0.22s var(--ease); box-shadow: var(--shadow); }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 50; background: var(--scrim); border: 0; }
  .tb-menu, .app.sidebar-collapsed .tb-menu { display: inline-flex; }
  .app.sidebar-collapsed .sidebar { display: flex; }
  .sb-action kbd { display: none; }
  .ci-more { opacity: 1; }
  .tb-share span { display: none; }
  .tb-share { padding: 0 8px; }
  .topbar { padding: 0 6px; }
  .toasts { bottom: 76px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

.loading-inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
