/* ===== Welfin Portal — design tokens ===== */
:root {
  --bg: #f7f7fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --sidebar-bg: #f1f2f7;
  --text: #1b1d29;
  --muted: #5b6072;
  --border: #e2e4ed;
  --hover: rgba(30, 34, 60, 0.06);
  --accent: #4f5bd5;
  --grad: linear-gradient(135deg, #4f5bd5 0%, #7c3aed 100%);
  --on-accent: #ffffff;
  --ring: 0 0 0 3px rgba(79, 91, 213, 0.35);
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-border: #fecdca;
  --ok: #1a7f4b;
  --warn: #b54708;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.10);
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  /* One scale: header < sidebar < popover < modal < toast. Menus use --z-popover. */
  --z-header: 20;
  --z-sidebar: 40;
  --z-popover: 80;
  --z-modal: 100;
  --z-toast: 120;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #171a23; --surface-2: #1f2330; --sidebar-bg: #12141c;
    --text: #e8eaf2; --muted: #a3a9be; --border: #2a2f3f; --hover: rgba(255, 255, 255, 0.07);
    --accent: #8b95ff; --ring: 0 0 0 3px rgba(139, 149, 255, 0.4);
    --danger: #fda29b; --danger-bg: #2a1517; --danger-border: #5c2a2d; --ok: #6ce9a6; --warn: #fdb022;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #171a23; --surface-2: #1f2330; --sidebar-bg: #12141c;
  --text: #e8eaf2; --muted: #a3a9be; --border: #2a2f3f; --hover: rgba(255, 255, 255, 0.07);
  --accent: #8b95ff; --ring: 0 0 0 3px rgba(139, 149, 255, 0.4);
  --danger: #fda29b; --danger-bg: #2a1517; --danger-border: #5c2a2d; --ok: #6ce9a6; --warn: #fdb022;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ===== base ===== */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { display: block; flex: none; }
.offscreen { position: fixed; left: -9999px; top: 0; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.brand-mark {
  width: 48px; height: 48px; border-radius: 14px; background: var(--grad); color: #fff;
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(124, 58, 237, 0.35); flex: none;
}
.brand-mark.big { width: 56px; height: 56px; border-radius: 18px; }
.brand-mark.sm { width: 28px; height: 28px; border-radius: 9px; box-shadow: none; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--muted);
  display: inline-grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn.sm { width: 32px; height: 32px; border-radius: 10px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:focus-visible { box-shadow: var(--ring); outline: none; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff; display: inline-block;
}
.skel {
  display: block; border-radius: 8px; background: var(--surface-2);
  background-image: linear-gradient(90deg, transparent, var(--hover), transparent);
  background-size: 200% 100%; background-repeat: no-repeat;
}

/* ===== login ===== */
.login-page { min-height: 100%; display: grid; place-items: center; overflow-x: hidden; }
.login-bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(60% 50% at 15% 20%, rgba(79, 91, 213, 0.28), transparent 70%),
    radial-gradient(55% 50% at 85% 25%, rgba(124, 58, 237, 0.24), transparent 70%),
    radial-gradient(60% 55% at 50% 95%, rgba(56, 189, 248, 0.18), transparent 70%),
    var(--bg);
  background-size: 140% 140%;
}
.login-wrap { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: 24px 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow-md); padding: 32px 24px; text-align: center;
}
.login-card .brand-mark { margin: 0 auto 16px; }
.login-title { font-size: 1.5rem; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.login-sub { color: var(--muted); margin: 4px 0 24px; }
.login-error {
  display: flex; gap: 8px; align-items: center; text-align: left; margin-bottom: 16px; padding: 10px 12px;
  border-radius: 12px; background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger); font-size: 0.925rem;
}
.field { position: relative; margin-bottom: 16px; text-align: left; }
.field input {
  width: 100%; height: 56px; padding: 22px 48px 6px 14px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.field label {
  position: absolute; left: 15px; top: 16px; color: var(--muted); pointer-events: none;
  transform-origin: left top; font-size: 1rem;
}
.field input:focus + label, .field input:not(:placeholder-shown) + label { transform: translateY(-9px) scale(0.75); }
.field-toggle {
  position: absolute; right: 6px; top: 8px; width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer;
}
.field-toggle:hover { background: var(--hover); color: var(--text); }
.btn-brand {
  width: 100%; height: 52px; border: 0; border-radius: 14px; background: var(--grad); color: var(--on-accent);
  font-weight: 600; font-size: 1rem; display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer;
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.3);
}
.btn-brand:focus-visible { box-shadow: var(--ring); outline: none; }
.btn-brand:disabled { opacity: 0.8; cursor: progress; }
.btn-brand .spinner.d-none { display: none; }

/* ===== app shell ===== */
.chat-page { overflow: hidden; }
.app { display: flex; flex: 1; height: 100%; min-height: 0; min-width: 0; background: var(--bg); }
.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.backdrop { display: none; }

/* sidebar */
.sidebar {
  width: 280px; flex: none; background: var(--sidebar-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.sidebar-head { display: flex; gap: 8px; align-items: center; padding: 12px; flex: none; }
.btn-new {
  flex: 1; height: 44px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: flex; align-items: center; gap: 8px; padding: 0 14px; font-weight: 550; cursor: pointer; box-shadow: var(--shadow-sm);
}
.btn-new:hover { background: var(--surface-2); }
.btn-new:focus-visible { box-shadow: var(--ring); outline: none; }

.history { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 8px; overscroll-behavior: contain; }
.h-title {
  position: sticky; top: 0; z-index: 1; margin: 0; padding: 12px 10px 6px; background: var(--sidebar-bg);
  font-size: 0.72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.h-list { list-style: none; margin: 0; padding: 0; }
.h-item {
  width: 100%; text-align: left; border: 0; background: transparent; color: var(--text); border-radius: 10px;
  padding: 7px 10px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; min-height: 48px;
}
.h-item:hover { background: var(--hover); }
.h-item:focus-visible { outline: none; box-shadow: var(--ring); }
.h-item.active { background: var(--surface); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border); }
.h-text { font-size: 0.9rem; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-meta { display: flex; gap: 8px; align-items: center; font-size: 0.68rem; color: var(--muted); }
.badge-model {
  max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 7px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); line-height: 1.5;
}
.history-empty { color: var(--muted); text-align: center; padding: 24px 8px; font-size: 0.9rem; }
.history-loading { display: grid; gap: 8px; padding: 10px; }
.history-loading .skel { height: 36px; }
.btn-more { width: 100%; height: 40px; margin-top: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; }
#history-sentinel { height: 1px; }

.sidebar-foot { position: relative; flex: none; padding: 8px; border-top: 1px solid var(--border); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--grad); color: #fff; font-weight: 650; display: grid; place-items: center; flex: none; }
.user-btn {
  width: 100%; min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 0; border-radius: 12px;
  background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--hover); }
.user-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.user-chev { margin-left: auto; color: var(--muted); }
.user-menu {
  position: absolute; left: 8px; right: 8px; bottom: calc(100% - 2px); z-index: 5; padding: 6px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md);
}
.user-menu form { margin: 0; }
.um-item {
  width: 100%; min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font-size: 0.92rem; text-align: left; cursor: pointer;
}
.um-item:hover, .um-item:focus-visible { background: var(--hover); outline: none; }
.um-item:focus-visible { box-shadow: var(--ring); }
.user-name { font-weight: 550; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* usage limits: sidebar meter */
.quota {
  width: 100%; display: grid; gap: 6px; padding: 8px 10px 10px; margin-bottom: 2px; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); font-size: 0.75rem; line-height: 1.3; text-align: left; cursor: default;
  font-variant-numeric: tabular-nums;
}
.quota:hover { background: var(--hover); }
.quota:focus-visible { outline: none; box-shadow: var(--ring); }
.quota-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quota-bar { display: block; height: 4px; border-radius: 999px; background: var(--border); overflow: hidden; }
.quota-fill { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); }
.quota[data-level="warn"] .quota-fill { background: var(--warn); }
.quota[data-level="full"] .quota-fill { background: var(--danger); }
.quota[data-level="full"] .quota-text { color: var(--danger); font-weight: 600; }
.quota.tip::after { left: 0; right: 0; width: auto; max-width: none; white-space: pre-line; }

/* ===== header ===== */
.topbar {
  position: relative; z-index: var(--z-header); height: 54px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 10px;
  border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 88%, transparent);
  min-width: 0; overflow: hidden;
}
.tb-side { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 8px; }
.tb-end { justify-content: flex-end; gap: 4px; }
.app-name { font-size: 1.08rem; font-weight: 650; letter-spacing: -0.015em; }
#sidebar-open { display: none; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.status-dot[data-state="busy"] { background: #f5a524; }
.status-dot[data-state="error"] { background: #e5484d; }

.usage-pill {
  height: 30px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 0.72rem; font-weight: 550; cursor: default; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.usage-pill:focus-visible { outline: none; box-shadow: var(--ring); }

/* tooltips (data-tip) */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip); position: absolute; z-index: 30; bottom: calc(100% + 8px); left: 0; width: max-content; max-width: min(260px, 80vw);
  padding: 6px 10px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 0.78rem; font-weight: 450; line-height: 1.4;
  text-align: left; white-space: normal; box-shadow: var(--shadow-md); opacity: 0; pointer-events: none; visibility: hidden;
}
.tip:hover::after, .tip:focus::after, .tip:focus-visible::after { opacity: 1; visibility: visible; }
.usage-pill.tip::after { bottom: auto; top: calc(100% + 8px); left: auto; right: 0; }

/* ===== thread ===== */
.thread-wrap {
  flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; outline: none;
  padding: 16px 16px 12px;
}
.thread { flex: none; width: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.empty {
  margin: auto; width: 100%; max-width: 640px; min-height: 0; max-height: 100%;
  display: flex; flex-direction: column; align-items: center; text-align: center; justify-content: center;
}
.greeting { font-size: clamp(1.05rem, 3.6vh, 1.9rem); font-weight: 650; letter-spacing: -0.02em; margin: 10px 0 2px; overflow-wrap: anywhere; }
.greeting-sub { color: var(--muted); margin: 0 0 18px; }
.chips { display: grid; grid-template-columns: 1fr; gap: 8px; width: 100%; }
.chip {
  text-align: left; padding: 11px 14px; min-height: 46px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 0.93rem; line-height: 1.35; cursor: pointer; box-shadow: var(--shadow-sm);
}
.chip:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-2); }
.chip:focus-visible { box-shadow: var(--ring); outline: none; }
.chip:disabled { opacity: 0.55; cursor: not-allowed; }

.msg { display: flex; min-width: 0; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(85%, 560px); padding: 10px 16px; border-radius: 20px 20px 6px 20px; background: var(--grad); color: var(--on-accent);
  white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow-sm);
}
.msg.assistant { gap: 12px; align-items: flex-start; }
.ai-avatar { width: 30px; height: 30px; border-radius: 10px; background: var(--grad); color: #fff; display: grid; place-items: center; flex: none; margin-top: 2px; }
.a-body { flex: 1; min-width: 0; }
.a-content { overflow-wrap: anywhere; line-height: 1.7; }
.a-content.revealing { cursor: pointer; }
.a-content.revealing > :last-child::after {
  content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 2px; vertical-align: text-bottom; background: var(--accent); border-radius: 2px;
}

/* reply footer: one muted line of small chips + actions */
.a-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 8px; }
.u-line { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-width: 0; font-size: 0.72rem; color: var(--muted); line-height: 1.5; }
.u-pill, .u-chip { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.u-model { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.u-style { display: inline-flex; align-items: center; gap: 4px; }
.u-chip { font-weight: 600; border: 1px solid var(--border); color: var(--text); }
.u-chip.s-quick { color: var(--ok); }
.u-chip.s-balanced { color: var(--accent); }
.u-chip.s-detailed { color: var(--warn); }
.u-auto { padding: 0 6px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; font-size: 0.68rem; }
.u-smart {
  display: inline-flex; align-items: center; gap: 2px; max-width: 100%; min-width: 0; padding: 0 2px 0 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  color: var(--text);
}
.u-smart-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 6px; cursor: help; }
.u-smart-text:focus-visible { outline: none; box-shadow: var(--ring); }
.u-smart.tip:focus-within::after { opacity: 1; visibility: visible; }
.u-lock {
  display: inline-flex; align-items: center; gap: 3px; flex: none; height: 20px; padding: 0 7px; border: 0; border-radius: 999px;
  background: transparent; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}
.u-lock:hover { background: var(--hover); }
.u-lock:focus-visible { outline: none; box-shadow: var(--ring); }
@media (max-width: 575.98px) {
  .u-smart { flex: 1 1 100%; }
  .u-lock { height: 28px; }
}
.u-info { display: inline-grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: help; position: static; }
.u-info:hover { color: var(--text); background: var(--hover); }
.u-info:focus-visible { outline: none; box-shadow: var(--ring); }
.a-actions { display: flex; gap: 2px; }
.act-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 0.75rem; cursor: pointer;
}
.act-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.act-btn:focus-visible { box-shadow: var(--ring); outline: none; }
.act-btn:disabled { opacity: 0.5; cursor: not-allowed; }
@media (hover: hover) and (pointer: fine) {
  .msg.assistant .a-actions { opacity: 0; }
  .msg.assistant:hover .a-actions, .msg.assistant:focus-within .a-actions { opacity: 1; }
}

/* file cards: only under answers whose message asked for a file */
.fcards { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 2px; }
.fcards[hidden] { display: none; }
.fcard {
  display: flex; align-items: center; gap: 12px; width: min(340px, 100%); min-width: 0; padding: 10px 10px 10px 12px;
  border-radius: 16px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm, none);
}
.fcard-icon {
  position: relative; display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 10px;
  color: var(--fc); background: color-mix(in srgb, var(--fc) 14%, var(--surface));
}
.fcard-icon.is-pdf { --fc: #d63c3c; }
.fcard-icon.is-docx { --fc: #2f6fde; }
.fcard-icon.is-png { --fc: #1f9d63; }
.fcard-badge {
  position: absolute; bottom: -3px; right: -5px; padding: 0 4px; border-radius: 5px; background: var(--fc); color: #fff;
  font-size: 0.56rem; font-weight: 700; letter-spacing: 0.03em; line-height: 1.5;
}
.fcard-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; line-height: 1.3; }
.fcard-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.875rem; color: var(--text); }
.fcard-kind { font-size: 0.75rem; color: var(--muted); }
.fcard-print {
  display: inline-flex; align-items: center; gap: 4px; width: fit-content; margin-top: 3px; padding: 0; border: 0; border-radius: 4px;
  background: transparent; color: var(--accent); font-size: 0.72rem; text-decoration: underline; cursor: pointer;
}
.fcard-print[hidden] { display: none; }
.fcard-print:focus-visible { outline: none; box-shadow: var(--ring); }
.fcard-dl {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none; min-width: 44px; height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.fcard-dl:hover { background: var(--hover); }
.fcard-dl:focus-visible { outline: none; box-shadow: var(--ring); }
.fcard-dl[aria-disabled="true"] { cursor: progress; }
.fcard-dl .fcard-spin { display: none; width: 16px; height: 16px; border-color: color-mix(in srgb, currentColor 30%, transparent); border-top-color: currentColor; }
.fcard-dl.is-busy .fcard-spin { display: inline-block; }
.fcard-dl.is-busy > .icon:first-child { display: none; }
@media (max-width: 575.98px) {
  .fcard { width: 100%; }
  .fcard-dl { padding: 0 10px; }
  .fcard-dl-text { display: none; }
}

/* off-screen sheet for the PNG export and the print view: always the light palette */
.x-stage { position: fixed; left: -10000px; top: 0; width: 800px; pointer-events: none; }
.x-sheet {
  --bg: #ffffff; --surface: #ffffff; --surface-2: #f0f1f6; --text: #1b1d29; --muted: #5b6072; --border: #e2e4ed;
  --hover: rgba(30, 34, 60, 0.06); --accent: #4f5bd5; color-scheme: light;
  box-sizing: border-box; width: 800px; padding: 40px 44px 28px; background: #ffffff; color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.7; overflow-wrap: anywhere;
}
.x-title { margin: 0 0 14px; font-size: 1.6rem; line-height: 1.3; }
.x-url { color: var(--muted); font-size: 0.9em; }
.x-sheet .md-code pre { white-space: pre-wrap; overflow: visible; }
.x-sheet .md-table-wrap { overflow: visible; }
.x-sheet .md-table { width: 100%; }
.x-foot { margin-top: 24px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--muted); }
#print-view { display: none; }
.u-details { flex-basis: 100%; font-size: 0.78rem; color: var(--muted); }
.u-details summary { cursor: pointer; width: fit-content; padding: 2px 0; }
.u-details summary:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.u-details dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 6px 0 4px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.u-details dt { font-weight: 550; }
.u-details dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.8em; }
.md ul, .md ol { margin: 0 0 0.8em; padding-left: 1.4em; }
.md li { margin: 0.2em 0; }
.md-h { font-weight: 650; margin: 1.1em 0 0.4em; line-height: 1.3; }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md-inline-code { font-family: var(--mono); font-size: 0.88em; padding: 0.15em 0.4em; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.md-code { margin: 0 0 0.9em; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.md-code-head {
  display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 12px; background: var(--surface-2);
  font-size: 0.75rem; color: var(--muted); border-bottom: 1px solid var(--border);
}
.md-copy { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 0.75rem; }
.md-copy:hover { background: var(--hover); color: var(--text); }
.md-code pre { margin: 0; padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 0.85rem; line-height: 1.55; color: var(--text); }
.md-quote { margin: 0 0 0.8em; padding: 2px 0 2px 14px; border-left: 3px solid var(--border); color: var(--muted); }
.md-quote > :last-child { margin-bottom: 0; }
.md-hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; opacity: 1; }
.md-img-alt { font-style: italic; color: var(--muted); }
.md-table-wrap { margin: 0 0 0.9em; overflow-x: auto; }
.md-table { border-collapse: collapse; font-size: 0.9em; line-height: 1.5; }
.md-table th, .md-table td { padding: 6px 10px; border: 1px solid var(--border); vertical-align: top; text-align: left; }
.md-table th { background: var(--surface-2); font-weight: 600; }

/* typing + error */
.typing { padding-top: 6px; }
.dots { display: flex; gap: 5px; height: 18px; align-items: center; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: 0.7; }
.typing .line { height: 12px; margin-top: 10px; }
.typing .l1 { width: 85%; }
.typing .l2 { width: 60%; }
.err-bubble {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: 100%; padding: 12px 14px;
  border-radius: 14px; background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger);
}
.err-msg { display: flex; gap: 8px; align-items: flex-start; overflow-wrap: anywhere; }
.err-msg .icon { margin-top: 3px; }
.err-bubble .act-btn { height: 32px; color: var(--danger); border: 1px solid var(--danger-border); }
.err-bubble .act-btn:hover:not(:disabled) { background: var(--surface); color: var(--danger); }
.err-bubble.is-quota {
  background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  color: var(--text);
}
.err-bubble.is-quota .icon { color: var(--warn); }

.to-bottom {
  position: absolute; right: 16px; bottom: calc(var(--composer-h, 130px) + 6px); z-index: 11; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow-md);
}
.to-bottom:hover { background: var(--surface-2); }
.to-bottom:focus-visible { box-shadow: var(--ring); outline: none; }

/* ===== composer ===== */
.composer-wrap { position: relative; flex: none; z-index: 10; padding: 8px 16px 8px; pointer-events: none; }
.composer-wrap::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(to top, var(--bg) 45%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  -webkit-mask-image: linear-gradient(to top, #000 65%, transparent); mask-image: linear-gradient(to top, #000 65%, transparent);
}
.composer, .note { pointer-events: auto; }
.composer {
  position: relative; max-width: 760px; margin: 0 auto; padding: 10px 10px 8px 16px; border: 1px solid var(--border); border-radius: 24px;
  background: var(--surface); box-shadow: var(--shadow-md);
}
.composer:focus-within { border-color: var(--accent); box-shadow: var(--shadow-md), var(--ring); }
.composer textarea {
  display: block; width: 100%; border: 0; outline: none; resize: none; background: transparent; color: var(--text);
  font: inherit; line-height: 1.5; padding: 2px 6px 2px 0; max-height: calc(1.5em * 8 + 4px);
}
.composer textarea::placeholder { color: var(--muted); opacity: 1; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 36px; margin-top: 4px; }
.tb-l, .tb-r { display: flex; align-items: center; gap: 4px; min-width: 0; }
.tb-l { position: relative; }
.tb-r { gap: 8px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px 0 10px; border: 1px solid var(--border); border-radius: 999px;
  background: transparent; color: var(--muted); font-size: 0.82rem; font-weight: 550; cursor: pointer;
}
.pill-btn:hover, .pill-btn[aria-expanded="true"] { background: var(--hover); color: var(--text); }
.pill-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.tok-est, .counter { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.counter.warn { color: var(--danger); font-weight: 600; }
.tok-est.warn { color: var(--warn); font-weight: 600; }
.composer.is-locked { background: var(--surface-2); }
.composer textarea:disabled { cursor: not-allowed; }

/* ===== attachments ===== */
.att-list, .att-sent { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; min-width: 0; }
.att-list { margin: 0 0 8px -6px; max-height: 128px; overflow-y: auto; }
.att-chip {
  display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 240px; height: 44px; padding: 4px 4px 4px 4px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); color: var(--text);
}
.att-sent .att-chip { height: 40px; padding-right: 10px; background: var(--surface); box-shadow: var(--shadow-sm); }
.att-icon {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center; overflow: hidden; border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
.att-sent .att-icon { width: 30px; height: 30px; border-radius: 8px; }
.att-chip[data-kind="pdf"] .att-icon { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.att-chip[data-kind="xlsx"] .att-icon, .att-chip[data-kind="csv"] .att-icon { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.att-chip[data-kind="pptx"] .att-icon { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.att-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.att-name { font-size: 0.8rem; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }
.att-x {
  width: 28px; height: 28px; flex: none; margin-left: auto; display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.att-x:hover { background: var(--hover); color: var(--text); }
.att-x:focus-visible { box-shadow: var(--ring); outline: none; }
.att-msg {
  display: flex; margin: 0 0 8px -6px; padding: 6px 10px; border-radius: 10px; font-size: 0.78rem; line-height: 1.4;
  background: color-mix(in srgb, var(--warn) 10%, var(--surface)); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  overflow-wrap: anywhere;
}
.user-col { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: min(85%, 560px); min-width: 0; }
.user-col .bubble { max-width: 100%; }
.att-sent { justify-content: flex-end; }
.a-notice {
  display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; padding: 8px 12px; border-radius: 12px; font-size: 0.8rem; line-height: 1.45;
  background: color-mix(in srgb, var(--warn) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); color: var(--text);
}
.a-notice .icon { color: var(--warn); margin-top: 2px; }
.a-notice-text { min-width: 0; overflow-wrap: anywhere; }
.a-notice p { margin: 0; }
.a-notice.is-cut { margin: 10px 0 0; }
.a-notice[hidden] { display: none; }
.h-files { display: inline-flex; align-items: center; gap: 2px; }
.t-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 10px; font-size: 0.78rem; color: var(--muted); }
.t-label { font-variant-numeric: tabular-nums; }
.t-bar { position: relative; width: 120px; height: 4px; overflow: hidden; border-radius: 4px; background: var(--surface-2); }
.t-bar span { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 4px; background: var(--grad); }
.t-bar.is-busy span { width: 40%; }
.t-cancel { border: 1px solid var(--border); }
.drop-zone {
  position: absolute; inset: 8px; z-index: 20; display: grid; place-items: center; padding: 16px; border: 2px dashed var(--accent); border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); pointer-events: none;
}
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--text); }
.drop-inner .icon { color: var(--accent); }
.drop-sub { font-size: 0.8rem; color: var(--muted); }
.quota-note {
  display: flex; align-items: center; gap: 6px; width: fit-content; max-width: min(760px, 100%); margin: 0 auto 8px; padding: 3px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--warn);
  font-size: 0.75rem; font-weight: 550; line-height: 1.4; box-shadow: var(--shadow-sm); pointer-events: auto;
}
.quota-note[data-level="block"] { padding: 5px 12px; border-radius: 12px; background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.send {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--grad); color: #fff; display: grid; place-items: center; cursor: pointer;
  position: relative; box-shadow: 0 4px 12px rgba(124, 58, 237, 0.35);
}
.send:focus-visible { box-shadow: var(--ring); outline: none; }
.send:disabled { background: var(--surface-2); color: var(--muted); box-shadow: none; cursor: not-allowed; opacity: 0.8; }
.send .spinner { position: absolute; display: none; }
.send.is-busy { background: var(--grad); color: transparent; opacity: 0.9; cursor: progress; }
.send.is-busy .icon { visibility: hidden; }
.send.is-busy .spinner { display: block; }
.note { max-width: 760px; margin: 6px auto 0; text-align: center; font-size: 0.7rem; color: var(--muted); }

.menu, .popover {
  position: absolute; left: 0; bottom: calc(100% + 10px); z-index: 20; padding: 6px; border-radius: 16px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-md);
}
.menu { width: min(272px, calc(100vw - 28px)); }
.m-opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; min-height: 46px; border-radius: 12px; cursor: pointer; }
.m-opt.active { background: var(--hover); }
.m-opt[aria-selected="true"] { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.m-text { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.3; }
.m-title { font-weight: 600; font-size: 0.9rem; }
.m-desc { font-size: 0.78rem; color: var(--muted); }
.m-check { color: var(--accent); visibility: hidden; }
.m-opt[aria-selected="true"] .m-check { visibility: visible; }
.popover { width: 230px; padding: 14px; text-align: left; }
.popover label { font-size: 0.85rem; font-weight: 600; display: block; margin-bottom: 6px; }
.popover input { width: 100%; height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.popover input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.hint { font-size: 0.75rem; color: var(--muted); margin: 6px 0 0; }
.hint.err { color: var(--danger); }

.toast-box { position: fixed; left: 0; right: 0; bottom: 120px; display: flex; justify-content: center; pointer-events: none; z-index: var(--z-toast); }
.toast-item { background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 0.875rem; box-shadow: var(--shadow-md); }

/* ===== change-password dialog ===== */
.modal-layer { position: fixed; inset: 0; z-index: var(--z-modal); display: grid; place-items: center; padding: 16px; }
.dlg-backdrop { position: absolute; inset: 0; background: rgba(8, 10, 20, 0.55); }
.sheet {
  position: relative; width: 100%; max-width: 420px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 20px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md);
}
.sheet-handle { display: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-title { margin: 0; font-size: 1.15rem; font-weight: 650; letter-spacing: -0.01em; }
.sheet .field { margin-bottom: 12px; }
.sheet .login-error { margin-bottom: 12px; }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.meter-row { display: flex; align-items: center; gap: 10px; margin: -4px 0 12px; }
.meter { flex: 1; height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 6px; background: var(--danger); transform: scaleX(0); transform-origin: left; }
.meter[data-level="1"] span { transform: scaleX(0.25); background: var(--danger); }
.meter[data-level="2"] span { transform: scaleX(0.5); background: #f5a524; }
.meter[data-level="3"] span { transform: scaleX(0.75); background: #84cc16; }
.meter[data-level="4"] span { transform: scaleX(1); background: var(--ok); }
.meter-label { min-width: 52px; font-size: 0.75rem; font-weight: 600; color: var(--muted); text-align: right; }
.rules { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 4px; font-size: 0.82rem; color: var(--muted); }
.rules li { display: flex; align-items: center; gap: 8px; }
.rules .icon { opacity: 0.3; }
.rules li.ok { color: var(--ok); }
.rules li.ok .icon { opacity: 1; }

/* ===== model picker ===== */
.mp { position: relative; flex: 0 1 auto; min-width: 0; }
.mp-btn {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%; height: 38px; padding: 0 10px 0 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm); cursor: pointer; font-size: 0.88rem; font-weight: 550;
}
.mp-btn:hover { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.14); }
.mp-btn:focus-visible, .mp.is-open .mp-btn { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.mp-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-chev { color: var(--muted); }
.mp.is-open .mp-btn .mp-chev { transform: rotate(180deg); }

.mp-panel {
  position: absolute; z-index: var(--z-popover); top: calc(100% + 8px); left: 50%; margin-left: calc(min(320px, calc(100vw - 24px)) / -2); width: min(320px, calc(100vw - 24px));
  display: flex; flex-direction: column; overflow: hidden; border-radius: 16px; border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  box-shadow: var(--shadow-md); transform-origin: top center;
}
.mp-panel.up { top: auto; bottom: calc(100% + 8px); transform-origin: bottom center; }
.mp-backdrop, .mp-handle { display: none; }
.mp-search { display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 52px; flex: none; border-bottom: 1px solid var(--border); color: var(--muted); }
.mp-search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: none; background: transparent; color: var(--text); font: inherit; font-size: 0.95rem; }
.mp-search input::placeholder { color: var(--muted); opacity: 1; }
.mp-scroll-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.mp-scroll-wrap::before, .mp-scroll-wrap::after { content: ""; position: absolute; left: 0; right: 8px; height: 16px; z-index: 3; pointer-events: none; opacity: 0; }
.mp-scroll-wrap::before { top: 0; background: linear-gradient(to bottom, rgba(16, 24, 40, 0.14), transparent); }
.mp-scroll-wrap::after { bottom: 0; background: linear-gradient(to top, rgba(16, 24, 40, 0.14), transparent); }
.mp-scroll-wrap.has-top::before, .mp-scroll-wrap.has-bottom::after { opacity: 1; }
.mp-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 8px 10px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.mp-scroll::-webkit-scrollbar { width: 8px; }
.mp-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
.mp-scroll::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
.mp-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 10px 0; flex: none; }
.mp-tab {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; min-height: 48px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
}
.mp-tab:hover { border-color: var(--accent); }
.mp-tab:focus-visible { outline: none; box-shadow: var(--ring); }
.mp-tab.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); box-shadow: inset 0 0 0 1px var(--accent); }
.mp-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--grad); color: #fff; font-weight: 650; display: grid; place-items: center; flex: none; }
.mp-avatar.sm { width: 28px; height: 28px; font-size: 0.8rem; }
.mp-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.mp-title { font-weight: 600; }
.mp-sub { font-size: 0.78rem; color: var(--muted); }
.mp-opt { display: flex; align-items: center; gap: 10px; padding: 9px 10px; min-height: 44px; cursor: pointer; border-radius: 12px; }
.mp-opt.active { background: var(--hover); }
.mp-opt[aria-selected="true"] { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.mp-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.mp-chip { font-size: 0.68rem; font-weight: 600; padding: 0 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); line-height: 1.6; flex: none; }
.mp-chip.default { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.mp-check { margin-left: auto; color: var(--accent); visibility: hidden; }
.mp-opt[aria-selected="true"] .mp-check { visibility: visible; }
.mp-skel { display: grid; gap: 8px; padding: 6px 4px; }
.mp-skel .skel { height: 36px; }
.mp-error {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin: 6px 2px; padding: 12px; border-radius: 12px;
  background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger); font-size: 0.875rem; overflow-wrap: anywhere;
}
.mp-retry { height: 34px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--danger-border); background: var(--surface); color: var(--danger); cursor: pointer; font-weight: 550; }
.mp-retry:focus-visible { outline: none; box-shadow: var(--ring); }
.mp-empty { text-align: center; color: var(--muted); padding: 28px 8px; margin: 0; }

/* ===== responsive ===== */
@media (min-width: 576px) {
  .chips { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 40px 36px; }
  .thread-wrap { padding-left: 24px; padding-right: 24px; }
}
@media (max-width: 991.98px) {
  #sidebar-open { display: inline-grid; }
  .sidebar {
    position: fixed; z-index: var(--z-sidebar); top: 0; bottom: 0; left: 0; width: min(86vw, 320px); height: auto; transform: translateX(-100%);
    box-shadow: var(--shadow-md); visibility: hidden;
  }
  .app.drawer-open .sidebar { transform: none; visibility: visible; }
  .backdrop { display: block; position: fixed; inset: 0; z-index: calc(var(--z-sidebar) - 10); background: rgba(8, 10, 20, 0.5); opacity: 0; pointer-events: none; }
  .app.drawer-open .backdrop { opacity: 1; pointer-events: auto; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
  .thread-wrap { padding-left: 12px; padding-right: 12px; }
}
@media (min-width: 992px) {
  .app.sidebar-collapsed .sidebar { margin-left: -280px; visibility: hidden; }
  .app:not(.sidebar-collapsed) #sidebar-open { display: none; }
  #sidebar-open { display: inline-grid; }
  .to-bottom { right: 24px; }
}
@media (max-width: 575.98px) {
  .modal-layer { place-items: end stretch; padding: 0; }
  .sheet { max-width: none; border-radius: 20px 20px 0 0; border-bottom: 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; max-height: 92dvh; }
  .sheet-handle { display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: -8px auto 12px; }
  .mp-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; margin-left: 0; max-height: 80vh; max-height: 80dvh;
    border-radius: 20px 20px 0 0; border-bottom: 0; transform-origin: bottom center; padding-bottom: env(safe-area-inset-bottom);
  }
  .mp-panel.up { bottom: 0; }
  .mp-handle { display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 8px auto 0; flex: none; }
  .mp-backdrop { display: block; position: fixed; inset: 0; z-index: calc(var(--z-popover) - 1); background: rgba(8, 10, 20, 0.5); opacity: 0; pointer-events: none; }
  .mp.is-open .mp-backdrop, .mp-backdrop.is-open { opacity: 1; pointer-events: auto; }
  .pill-word { display: none; }
  .mp-btn { height: 36px; }
}
@media (max-width: 479.98px) {
  .brand-mark.sm { display: none; }
  .app-name { display: none; }
  .bubble { max-width: 92%; }
  .user-col { max-width: 92%; }
  .msg.assistant { gap: 8px; }
  .att-list { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; max-height: none; padding-bottom: 2px; scrollbar-width: thin; }
  .att-list .att-chip { flex: none; max-width: 78%; }
}
@media (max-width: 399.98px) {
  .pill-btn .lbl { display: none; }
  .pill-btn { padding: 0 8px; gap: 4px; }
}
@media (max-width: 767.98px) {
  body.chat-page .sidebar { bottom: calc(4.25rem + env(safe-area-inset-bottom)); }
}
@media (max-height: 760px) {
  .brand-mark.big { width: 40px; height: 40px; border-radius: 14px; }
  .greeting { margin-top: 4px; }
  .greeting-sub { margin-bottom: 8px; }
  .chips { gap: 6px; }
  .chip { min-height: 0; padding: 8px 12px; }
}
@media (max-height: 640px) {
  .greeting-sub, .brand-mark.big { display: none; }
  .greeting { margin-top: 0; }
}
@media (max-height: 560px) {
  .chips { display: none; }
}

/* ===== motion (only when the user has no reduced-motion preference) ===== */
@media (prefers-reduced-motion: no-preference) {
  body, .sidebar, .topbar, .composer, .chip, .h-item, .bubble, .md-code, .btn-new, .field input, .send, .mp-btn, .pill-btn {
    transition: background-color 0.25s ease-out, color 0.25s ease-out, border-color 0.25s ease-out, box-shadow 0.2s ease-out;
  }
  .btn-brand, .btn-new, .chip, .send, .icon-btn, .act-btn, .h-item, .mp-opt, .mp-tab, .m-opt {
    transition: transform 0.15s ease-out, background-color 0.15s ease-out, border-color 0.15s ease-out, box-shadow 0.2s ease-out, color 0.15s;
  }
  .btn-brand:hover:not(:disabled), .send:hover:not(:disabled) { transform: translateY(-1px); }
  .chip:hover:not(:disabled) { transform: translateY(-2px); }
  .btn-brand:active:not(:disabled), .send:active:not(:disabled), .chip:active:not(:disabled), .btn-new:active,
  .act-btn:active:not(:disabled), .icon-btn:active, .mp-opt:active, .m-opt:active { transform: scale(0.97); }
  .field label, .mp-chev { transition: transform 0.18s ease-out; }
  .a-actions { transition: opacity 0.15s ease-out; }
  .tip::after { transition: opacity 0.15s ease-out, visibility 0.15s; }

  .login-bg { animation: drift 18s ease-in-out infinite alternate; }
  @keyframes drift { from { background-position: 0% 0%; } to { background-position: 100% 100%; } }
  .login-card { animation: rise 0.4s ease-out both; }
  .login-card.shake { animation: rise 0.4s ease-out both, shake 0.4s 0.35s ease-in-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
  @keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
  .spinner { animation: spin 0.7s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  .sidebar { transition: transform 0.25s ease-out, visibility 0.25s; }
  .backdrop, .mp-backdrop { transition: opacity 0.22s ease-out; }
  .dlg-backdrop { animation: fade-in 0.2s ease-out backwards; }
  .sheet { animation: slide-up 0.22s ease-out backwards; }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  .meter span { transition: transform 0.2s ease-out, background-color 0.2s ease-out; }
  .quota-fill { transition: width 0.3s ease-out, background-color 0.2s ease-out; }
  .quota-note { animation: toast-in 0.2s ease-out backwards; }

  .msg, .empty, .popover, .menu, .user-menu, .h-item.is-new, .fcard { animation: slide-up 0.25s ease-out backwards; }
  .to-bottom, .toast-item { animation: toast-in 0.2s ease-out backwards; }
  @keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
  @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
  .chip { animation: slide-up 0.35s ease-out backwards; }
  .chip:nth-child(2) { animation-delay: 0.06s; }
  .chip:nth-child(3) { animation-delay: 0.12s; }
  .chip:nth-child(4) { animation-delay: 0.18s; }

  .dots span { animation: bounce 1.2s ease-in-out infinite; }
  .dots span:nth-child(2) { animation-delay: 0.15s; }
  .dots span:nth-child(3) { animation-delay: 0.3s; }
  @keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-6px); opacity: 1; } }
  .skel { animation: shimmer 1.4s linear infinite; }
  @keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
  .a-content.revealing > :last-child::after { animation: blink 0.9s steps(2) infinite; }
  @keyframes blink { 50% { opacity: 0; } }
  .status-dot[data-state="busy"] { animation: pulse 1.2s ease-in-out infinite; }
  .t-bar span { transition: width 0.2s ease-out; }
  .t-bar.is-busy span { animation: indeterminate 1.2s ease-in-out infinite; }
  @keyframes indeterminate { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
  .att-chip, .drop-zone { animation: toast-in 0.18s ease-out backwards; }
  @keyframes pulse { 50% { opacity: 0.35; } }

  .mp-panel { opacity: 0; transform: translateY(-6px) scale(0.97); transition: opacity 0.18s ease-out, transform 0.18s ease-out; }
  .mp-panel.up { transform: translateY(6px) scale(0.97); }
  .mp.is-open .mp-panel, .mp-panel.is-open { opacity: 1; transform: none; }
  .swap-next { animation: swap-next 0.18s ease-out both; }
  .swap-prev { animation: swap-prev 0.18s ease-out both; }
  @keyframes swap-next { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
  @keyframes swap-prev { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
  @media (max-width: 575.98px) {
    .mp-panel, .mp-panel.up { transform: translateY(100%); transition: opacity 0.2s ease-out, transform 0.25s ease-out; }
    .mp.is-open .mp-panel, .mp-panel.is-open { transform: none; }
  }
}
@media (prefers-reduced-motion: reduce) {
  .dots span:nth-child(2) { opacity: 0.85; }
  .dots span:nth-child(3) { opacity: 1; }
  .spinner { border-top-color: transparent; border-right-color: #fff; }
  .fcard-dl .fcard-spin { border-right-color: currentColor; }
  .login-card.shake { outline: 2px solid var(--danger); outline-offset: 0; }
}

/* Portaled menus. position is also set inline; this keeps them above the shell and scrollable. */
.wf-pop {
  position: fixed;
  z-index: var(--z-popover);
  box-sizing: border-box;
  margin: 0;
  left: auto;
  right: auto;
  bottom: auto;
  overflow: auto;
  overscroll-behavior: contain;
}
.user-menu.wf-pop { width: max-content; min-width: 12rem; }
.mp-panel.wf-pop { overflow: hidden; }
.wf-pop-backdrop { z-index: calc(var(--z-popover) - 1); }
.wf-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  pointer-events: none !important;
}
.wf-select__btn { text-align: left; }
.wf-menu {
  padding: 6px;
  border-radius: 16px;
  background: var(--g-glass-strong, var(--surface));
  border: 1px solid var(--g-border, var(--border));
  box-shadow: var(--g-shadow, var(--shadow-md));
  color: var(--g-text, var(--text));
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.wf-menu__opt {
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.wf-menu__opt.is-active,
.wf-menu__opt:hover { background: var(--hover); }
.wf-menu__opt[aria-selected="true"] { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.wf-cal__bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 4px 8px; }
.wf-cal__title { font-weight: 650; font-size: 0.92rem; }
.wf-cal__nav, .wf-cal__day {
  border: 0; background: transparent; color: inherit; cursor: pointer; border-radius: 10px; font: inherit;
}
.wf-cal__nav { width: 36px; height: 36px; }
.wf-cal__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.wf-cal__dow { text-align: center; font-size: 0.72rem; color: var(--muted); padding: 4px 0; }
.wf-cal__day { height: 36px; }
.wf-cal__day:hover, .wf-cal__day:focus-visible { background: var(--hover); outline: none; }
.wf-cal__day[aria-selected="true"] { background: var(--accent); color: #fff; }
.wf-tip {
  position: fixed;
  z-index: var(--z-popover);
  width: max-content;
  max-width: min(260px, calc(100vw - 16px));
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--g-glass-strong, var(--text));
  color: var(--g-text, var(--bg));
  border: 1px solid var(--g-border, transparent);
  box-shadow: var(--shadow-md);
  font-size: 0.78rem;
  line-height: 1.4;
  pointer-events: none;
}
body.wf-tips .tip::after { content: none; }
@media (max-width: 575.98px) {
  .mp-panel.wf-pop--sheet {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: min(80vh, 80dvh);
  }
}

/* ===== print: the file card's "Print / Save as PDF" fallback shows only the answer sheet ===== */
@media print {
  @page { size: A4; margin: 16mm; }
  html, body.is-printing { height: auto !important; overflow: visible !important; background: #fff !important; }
  body.is-printing > :not(#print-view) { display: none !important; }
  body.is-printing #print-view { display: block; }
  #print-view .x-sheet { width: auto; padding: 0; font-size: 11pt; }
  #print-view .md-code, #print-view tr, #print-view .md-quote { break-inside: avoid; }
  #print-view .md-h { break-after: avoid; }
  #print-view .x-foot { break-inside: avoid; }
}
