/* Components. Uses tokens.css only. */

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--mint);
  --btn-fg: var(--text-on-brand);
  --btn-border: transparent;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 40px; padding: 0 var(--s-4);
  border: 1px solid var(--btn-border); border-radius: var(--r-control);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 600; font-size: var(--fs-14); line-height: 1; white-space: nowrap;
  text-decoration: none; user-select: none;
  transition: transform var(--dur-1) var(--ease), background-color var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), opacity var(--dur-2);
}
a.btn { color: var(--btn-fg); }
.btn:hover { text-decoration: none; filter: brightness(1.06); }
.btn:active { transform: scale(0.97); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.45; cursor: not-allowed; transform: none; filter: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.gradient { --btn-bg: var(--brand-gradient); background: var(--brand-gradient); box-shadow: var(--brand-glow); }
.btn.ghost, .btn.secondary { --btn-bg: var(--surface-2); --btn-fg: var(--text); --btn-border: var(--border-strong); }
.btn.ghost:hover, .btn.secondary:hover { --btn-bg: var(--surface-hover); filter: none; }
.btn.subtle { --btn-bg: transparent; --btn-fg: var(--text-2); }
.btn.subtle:hover { --btn-bg: var(--surface-3); --btn-fg: var(--text); filter: none; }
.btn.danger { --btn-bg: var(--down); --btn-fg: var(--on-down); }
.btn.danger-soft { --btn-bg: var(--down-soft); --btn-fg: var(--down); --btn-border: rgba(255, 92, 108, 0.3); }
.btn.warn-soft { --btn-bg: var(--warn-soft); --btn-fg: var(--warn); --btn-border: rgba(255, 181, 71, 0.3); }
.btn.small, .btn.sm { min-height: 32px; padding: 0 var(--s-3); font-size: var(--fs-13); border-radius: var(--r-chip); }
.btn.big, .btn.lg { min-height: 48px; padding: 0 var(--s-6); font-size: var(--fs-16); border-radius: 12px; }
.btn.block { width: 100%; }
.btn.icon { width: 40px; padding: 0; }
.btn.icon.sm { width: 32px; }
.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-right-color: transparent; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- form controls ---------- */
input, select, textarea {
  width: 100%; min-height: 40px; padding: 0 var(--s-3);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-control);
  font-size: var(--fs-14);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), background-color var(--dur-2);
}
textarea { padding: var(--s-2) var(--s-3); min-height: 80px; }
input:not([type='checkbox']):not([type='radio']), select, textarea { display: block; }
input::placeholder { color: var(--text-3); }
input:hover, select:hover { border-color: var(--text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--info); box-shadow: 0 0 0 3px var(--info-soft); }
input:disabled, select:disabled { opacity: 0.55; cursor: not-allowed; }
input[type='number'] { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
input[type='number']::-webkit-inner-spin-button { opacity: 0.4; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a879b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
input[type='checkbox'], input[type='radio'] { width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--mint); cursor: pointer; }
label { display: block; margin: 0 0 6px; font-size: var(--fs-13); font-weight: 500; color: var(--text-2); }
.field { margin-bottom: var(--s-4); }
.field .hint, .hint { margin: 6px 0 0; font-size: var(--fs-12); color: var(--text-3); }
.row { display: flex; gap: var(--s-3); flex-wrap: wrap; }
.row > * { flex: 1 1 150px; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: var(--s-2); margin: 0; color: var(--text); font-size: var(--fs-14); font-weight: 500; cursor: pointer; }
.check input { width: 18px; }
.input-affix { position: relative; }
.input-affix > span { position: absolute; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: var(--fs-13); pointer-events: none; }
.input-affix > span.pre { left: 12px; }
.input-affix > span.post { right: 12px; }
.input-affix.has-pre input { padding-left: 26px; }
.input-affix.has-post input { padding-right: 34px; }
.input-affix input { -moz-appearance: textfield; }
.input-affix input::-webkit-inner-spin-button, .input-affix input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* switch: <label class="switch"><input type="checkbox" role="switch"><span class="track"></span> Text</label> */
.switch { display: inline-flex; align-items: center; gap: var(--s-3); margin: 0; color: var(--text); font-size: var(--fs-14); font-weight: 500; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative; flex: none; width: 40px; height: 24px; border-radius: var(--r-pill);
  background: var(--surface-3); border: 1px solid var(--border-strong);
  transition: background-color var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-2); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform var(--dur-2) var(--ease-sheet), background-color var(--dur-2);
}
.switch input:checked + .track { background: var(--mint); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.45; }
.switch.warn input:checked + .track { background: var(--warn); }
.switch .sub { display: block; font-size: var(--fs-12); color: var(--text-3); font-weight: 400; }

/* segmented control */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-control); }
.segmented button, .segmented label {
  margin: 0; min-height: 30px; padding: 0 var(--s-3); border: 0; border-radius: 7px; background: transparent; color: var(--text-2);
  font-size: var(--fs-13); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  transition: background-color var(--dur-2), color var(--dur-2);
}
.segmented button svg { width: 14px; height: 14px; }
.segmented button[aria-pressed='true'], .segmented button[aria-selected='true'] { background: var(--surface-1); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }

/* ---------- cards ---------- */
.card {
  position: relative;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-card);
  padding: var(--s-5); box-shadow: var(--shadow-card); min-width: 0;
}
.card + .card { margin-top: var(--s-4); }
.grid > .card + .card, .stack > .card + .card, .card-grid > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card-title { font-size: var(--fs-14); font-weight: 650; color: var(--text); letter-spacing: -0.01em; margin: 0; }
.card-sub { font-size: var(--fs-13); color: var(--text-2); margin: 2px 0 0; }
.eyebrow { font-size: var(--fs-12); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.card.flush { padding: 0; overflow: hidden; }
.card.interactive { cursor: pointer; transition: border-color var(--dur-2), transform var(--dur-1) var(--ease), background-color var(--dur-2); }
.card.interactive:hover { border-color: var(--border-strong); background: var(--surface-2); }
.card.interactive:active { transform: scale(0.99); }
.divider { height: 1px; background: var(--border); margin: var(--s-4) 0; border: 0; }

/* ---------- pills, chips, status ---------- */
.pill, .chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: var(--fs-12); font-weight: 600; white-space: nowrap; line-height: 1;
  background: var(--neutral-soft); color: var(--text-2); border: 1px solid transparent;
}
.pill svg, .chip svg { width: 12px; height: 12px; }
.pill.on, .pill.ok, .chip.ok { background: var(--up-soft); color: var(--up); }
.pill.warn, .chip.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad, .chip.bad { background: var(--down-soft); color: var(--down); }
.pill.info, .chip.info { background: var(--info-soft); color: var(--info); }
.pill.off { background: var(--neutral-soft); color: var(--text-3); }
.pill.lead, .chip.lead { background: var(--brand-gradient); color: var(--text-on-brand); }
.pill.live { background: var(--down); color: var(--on-down); letter-spacing: 0.04em; }
.pill.dry { background: var(--info-soft); color: var(--info); letter-spacing: 0.04em; }
.pill.outline { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.chip.sm { height: 20px; padding: 0 8px; font-size: 11px; }

/* guard escalation: OK -> Paused (amber pulse) -> Flattened (red) -> Quarantined (red + action) */
.guard { display: inline-flex; align-items: center; gap: 6px; }
.guard .pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.guard-paused .pill { animation: pulse-warn 1.6s ease-in-out infinite; }
.guard-flattened .pill, .guard-quarantined .pill { background: var(--down); color: var(--on-down); }
@keyframes pulse-warn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 181, 71, 0.45); }
  50% { box-shadow: 0 0 0 5px rgba(255, 181, 71, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .guard-paused .pill { animation: none; border-color: var(--warn); }
}

/* live dot */
.dot { position: relative; display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.dot.on { background: var(--up); }
.dot.on::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: var(--up); animation: ping 1.8s var(--ease) infinite; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--down); }
@keyframes ping { 0% { transform: scale(1); opacity: 0.7; } 80%, 100% { transform: scale(2.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .dot.on::after { display: none; } }

kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; background: var(--surface-2); color: var(--text-2); font-family: var(--font-ui); font-size: 11px; font-weight: 600; }

/* ---------- stat tiles ---------- */
.stat { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-card); padding: var(--s-4); min-width: 0; box-shadow: var(--shadow-card); }
.stat .k { font-size: var(--fs-12); font-weight: 500; color: var(--text-2); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.stat .v { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--fs-22); font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat .v.pos { color: var(--up); }
.stat .v.neg { color: var(--down); }
.stat .v.warn { color: var(--warn); }
.stat .sub { font-size: var(--fs-12); color: var(--text-3); margin-top: 4px; }
.stat.plain { background: transparent; border: 0; padding: 0; box-shadow: none; }

/* number flash on change */
.flash-up { animation: flash-up 900ms var(--ease); }
.flash-down { animation: flash-down 900ms var(--ease); }
@keyframes flash-up { 0% { background: var(--up-soft); box-shadow: 0 0 0 4px var(--up-soft); } 100% { background: transparent; box-shadow: 0 0 0 4px transparent; } }
@keyframes flash-down { 0% { background: var(--down-soft); box-shadow: 0 0 0 4px var(--down-soft); } 100% { background: transparent; box-shadow: 0 0 0 4px transparent; } }
.flash-up, .flash-down { border-radius: 6px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 calc(var(--s-5) * -1); padding: 0 var(--s-5); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-13); }
.table th { position: sticky; top: 0; text-align: left; font-size: var(--fs-12); font-weight: 500; color: var(--text-3); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-1); }
.table td { padding: var(--s-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--dur-2); }
.table tbody tr:hover { background: var(--surface-2); }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table td.right, .table th.right { text-align: right; }
.table .num-input { width: 84px; min-height: 34px; padding: 0 8px; }
.table select { min-height: 34px; min-width: 96px; padding-left: 10px; }
/* On phones, .table.stackable rows become cards. Each td needs data-label. */
@media (max-width: 720px) {
  .table.stackable thead { display: none; }
  .table.stackable, .table.stackable tbody, .table.stackable tr, .table.stackable td { display: block; width: 100%; }
  .table.stackable tr { padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
  .table.stackable tr:last-child { border-bottom: 0; }
  .table.stackable td { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); padding: 3px 0; border: 0; text-align: right; }
  .table.stackable td::before { content: attr(data-label); color: var(--text-3); font-size: var(--fs-12); text-align: left; }
  .table.stackable td[data-label=''], .table.stackable td:not([data-label]) { justify-content: flex-start; text-align: left; }
  .table.stackable td[data-label='']::before, .table.stackable td:not([data-label])::before { display: none; }
}

/* ---------- list rows ---------- */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--border); min-height: 52px; }
.list-row:last-child { border-bottom: 0; }
.list-row .main { flex: 1 1 auto; min-width: 0; }
.list-row .title { font-weight: 600; font-size: var(--fs-14); }
.list-row .meta { font-size: var(--fs-12); color: var(--text-3); }

/* ---------- avatars ---------- */
.avatar { flex: none; width: 32px; height: 32px; border-radius: 10px; display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; letter-spacing: -0.02em; color: #071018; background: var(--c1); }
.avatar.sm { width: 24px; height: 24px; border-radius: 7px; font-size: 9px; letter-spacing: -0.04em; }
.avatar.lg { width: 44px; height: 44px; border-radius: 13px; font-size: 15px; }
.avatar.av0 { background: var(--c0); } .avatar.av1 { background: var(--c1); } .avatar.av2 { background: var(--c2); } .avatar.av3 { background: var(--c3); }
.avatar.av4 { background: var(--c4); } .avatar.av5 { background: var(--c5); } .avatar.av6 { background: var(--c6); } .avatar.av7 { background: var(--c7); }
.avatar.leader { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px var(--mint); }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface-1); }
.avatar-stack .avatar + .avatar { margin-left: -6px; }

/* ---------- progress ---------- */
.bar { height: 8px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--brand-gradient); transition: width 700ms var(--ease); }
.bar.done > span { background: var(--up); }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--down); }
.ring { flex: none; display: block; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-3); }
.grad-a { stop-color: var(--grad-a); }
.grad-b { stop-color: var(--grad-b); }
.ring .val { stroke: url(#ps-grad); transition: stroke-dashoffset 900ms var(--ease); }
.ring.done .val { stroke: var(--up); }
.ring.warn .val { stroke: var(--warn); }
.ring.bad .val { stroke: var(--down); }
.ring-wrap { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring-wrap .ring-label { position: absolute; font-family: var(--font-mono); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ring-wrap.lg .ring-label { font-size: var(--fs-18); }

/* sparkline */
.spark { width: 100%; height: 64px; overflow: visible; }
.spark path.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark path.area { opacity: 0.18; }
.spark.up path.line { stroke: var(--up); } .spark.up path.area { fill: var(--up); }
.spark.down path.line { stroke: var(--down); } .spark.down path.area { fill: var(--down); }
.spark.flat path.line { stroke: var(--text-3); } .spark.flat path.area { fill: transparent; }
.spark circle { r: 3.5px; }
.spark.up circle { fill: var(--up); } .spark.down circle { fill: var(--down); } .spark.flat circle { fill: var(--text-3); }

/* ---------- banners ---------- */
.banner { display: block; padding: var(--s-3) var(--s-4); border-radius: var(--r-card); border: 1px solid var(--border); background: var(--surface-2); font-size: var(--fs-13); color: var(--text); margin-bottom: var(--s-4); }
.banner.has-icon { display: flex; gap: var(--s-3); align-items: flex-start; }
.banner svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.banner.info { background: var(--info-soft); border-color: rgba(106, 168, 255, 0.28); }
.banner.info svg { color: var(--info); }
.banner.warn { background: var(--warn-soft); border-color: rgba(255, 181, 71, 0.3); }
.banner.warn svg { color: var(--warn); }
.banner.bad { background: var(--down-soft); border-color: rgba(255, 92, 108, 0.3); }
.banner.bad svg { color: var(--down); }
.banner .grow { flex: 1 1 auto; min-width: 0; }
.banner a { font-weight: 600; }

/* ---------- empty, error, lock ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-2); padding: var(--s-8) var(--s-4); color: var(--text-2); }
.empty .ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); margin-bottom: var(--s-2); }
.empty .ico svg { width: 22px; height: 22px; }
.empty h3 { margin: 0; color: var(--text); font-size: var(--fs-16); }
.empty p { margin: 0; max-width: 42ch; font-size: var(--fs-13); }
.empty .actions { display: flex; gap: var(--s-2); margin-top: var(--s-3); flex-wrap: wrap; justify-content: center; }
.empty.compact { padding: var(--s-5) var(--s-3); }
.lock-panel { position: relative; overflow: hidden; border-radius: var(--r-card); border: 1px solid var(--border); background: var(--surface-1); }
.lock-panel .ghostly { padding: var(--s-5); filter: blur(5px); opacity: 0.45; pointer-events: none; user-select: none; }
.lock-panel .lock-body { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s-5); background: linear-gradient(180deg, transparent, var(--surface-1) 70%); }
.lock-panel .lock-inner { text-align: center; max-width: 360px; }
.lock-panel .lock-inner .ico { margin: 0 auto var(--s-3); width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-gradient); color: var(--text-on-brand); }
.lock-panel .lock-inner .ico svg { width: 20px; height: 20px; }

/* ---------- skeletons ---------- */
.skel { display: block; border-radius: 6px; background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-hover) 50%, var(--surface-3) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; color: transparent !important; user-select: none; }
.skel.line { height: 12px; margin: 6px 0; }
.skel.line.w40 { width: 40%; } .skel.line.w60 { width: 60%; } .skel.line.w80 { width: 80%; }
.skel.num { height: 1em; width: 6ch; display: inline-block; vertical-align: middle; }
.skel.block { height: 96px; border-radius: var(--r-card); }
.skel.hero { height: var(--fs-hero); width: 7ch; border-radius: 10px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- dialogs, sheets, drawers (all <dialog>) ---------- */
dialog:not([open]) { display: none !important; }
dialog { padding: 0; border: 0; background: transparent; color: var(--text); max-width: none; max-height: none; }
dialog::backdrop { background: var(--overlay); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
dialog[open]::backdrop { animation: fade-in var(--dur-3) var(--ease); }
.dlg { width: min(440px, calc(100vw - 32px)); margin: auto; background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--r-sheet); box-shadow: var(--shadow-pop); padding: var(--s-6); }
.dlg[open] { animation: pop-in var(--dur-3) var(--ease); }
.dlg .dlg-icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-3); margin-bottom: var(--s-4); }
.dlg .dlg-icon svg { width: 22px; height: 22px; }
.dlg .dlg-icon.bad { background: var(--down-soft); color: var(--down); }
.dlg .dlg-icon.warn { background: var(--warn-soft); color: var(--warn); }
.dlg .dlg-icon.ok { background: var(--up-soft); color: var(--up); }
.dlg h2 { font-size: var(--fs-18); margin-bottom: var(--s-2); }
.dlg p { color: var(--text-2); font-size: var(--fs-14); }
.dlg .dlg-actions { display: flex; gap: var(--s-2); justify-content: flex-end; margin-top: var(--s-5); flex-wrap: wrap; }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* drawer: right side on desktop, bottom sheet on phones */
.drawer {
  position: fixed; inset: 0 0 0 auto; margin: 0; height: 100dvh; width: min(480px, 100vw);
  background: var(--surface-1); border-left: 1px solid var(--border-strong); box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column;
}
.drawer[open] { animation: drawer-in var(--dur-3) var(--ease-sheet); }
.drawer.closing { animation: drawer-out var(--dur-2) var(--ease) forwards; }
@keyframes drawer-in { from { transform: translateX(100%); } to { transform: none; } }
@keyframes drawer-out { to { transform: translateX(100%); } }
.sheet-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border); flex: none; }
.sheet-head h2 { margin: 0; font-size: var(--fs-18); }
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: var(--s-5); overscroll-behavior: contain; }
.sheet-foot { flex: none; display: flex; gap: var(--s-2); padding: var(--s-3) var(--s-5) calc(var(--s-3) + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface-1); }
.sheet-foot .btn { flex: 1; }
.grabber { display: none; }
.sheet-section { margin-bottom: var(--s-6); }
.sheet-section > h3 { font-size: var(--fs-12); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); font-weight: 600; margin-bottom: var(--s-3); }
@media (max-width: 720px) {
  .drawer, .sheet {
    inset: auto 0 0 0; width: 100vw; height: auto; max-height: 92dvh;
    border-left: 0; border-top: 1px solid var(--border-strong); border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  }
  .drawer[open], .sheet[open] { animation: sheet-in var(--dur-3) var(--ease-sheet); }
  .drawer.closing, .sheet.closing { animation: sheet-out var(--dur-2) var(--ease) forwards; }
  .grabber { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--border-strong); margin: 8px auto 0; flex: none; touch-action: none; cursor: grab; }
  .grabber-zone { touch-action: none; }
}
/* .sheet: bottom sheet on all sizes, centred card on desktop */
.sheet {
  position: fixed; margin: auto; width: min(520px, calc(100vw - 32px)); max-height: 86dvh;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--r-sheet); box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column; overflow: hidden;
}
.sheet[open] { animation: pop-in var(--dur-3) var(--ease); }
@media (max-width: 720px) {
  .sheet { margin: 0; inset: auto 0 0 0; width: 100vw; border-radius: var(--r-sheet) var(--r-sheet) 0 0; border-bottom: 0; }
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-out { to { transform: translateY(100%); } }

/* ---------- toasts ---------- */
.toasts { position: fixed; z-index: var(--z-toast); right: var(--s-5); bottom: var(--s-5); display: flex; flex-direction: column-reverse; gap: var(--s-2); width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow-pop);
  font-size: var(--fs-13); color: var(--text); animation: toast-in var(--dur-3) var(--ease-sheet);
}
.toast.leaving { animation: toast-out var(--dur-2) var(--ease) forwards; }
.toast .t-ico { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--up-soft); color: var(--up); }
.toast .t-ico svg { width: 14px; height: 14px; }
.toast.bad .t-ico { background: var(--down-soft); color: var(--down); }
.toast.warn .t-ico { background: var(--warn-soft); color: var(--warn); }
.toast.info .t-ico { background: var(--info-soft); color: var(--info); }
.toast .t-msg { flex: 1; min-width: 0; padding-top: 2px; overflow-wrap: anywhere; }
.toast .t-x { flex: none; border: 0; background: none; color: var(--text-3); padding: 2px; border-radius: 6px; }
.toast .t-x:hover { color: var(--text); }
.toast .t-x svg { width: 14px; height: 14px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }
@media (max-width: 720px) {
  .toasts { left: 50%; right: auto; transform: translateX(-50%); top: calc(var(--s-3) + env(safe-area-inset-top)); bottom: auto; flex-direction: column; }
  .toast { animation-name: toast-in-top; }
  @keyframes toast-in-top { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
}

/* ---------- command palette ---------- */
.palette { width: min(600px, calc(100vw - 24px)); margin: 12vh auto auto; background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: var(--shadow-pop); overflow: hidden; }
.palette[open] { animation: pop-in var(--dur-2) var(--ease); }
.palette .p-search { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-4); border-bottom: 1px solid var(--border); }
.palette .p-search svg { width: 18px; height: 18px; color: var(--text-3); flex: none; }
.palette .p-search input { border: 0; background: transparent; min-height: 54px; padding: 0; font-size: var(--fs-16); box-shadow: none; }
.palette ul { list-style: none; margin: 0; padding: var(--s-2); max-height: 50vh; overflow-y: auto; }
.palette li.group { padding: var(--s-2) var(--s-3) 4px; font-size: var(--fs-12); color: var(--text-3); font-weight: 600; }
.palette li[role='option'] { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-3); min-height: 42px; border-radius: 10px; cursor: pointer; font-size: var(--fs-14); }
.palette li[role='option'] svg { width: 16px; height: 16px; color: var(--text-2); flex: none; }
.palette li[role='option'] .hint { margin: 0 0 0 auto; }
.palette li[aria-selected='true'] { background: var(--surface-3); }
.palette li.danger svg, .palette li.danger { color: var(--down); }
.palette .p-foot { display: flex; gap: var(--s-4); padding: var(--s-2) var(--s-4); border-top: 1px solid var(--border); font-size: var(--fs-12); color: var(--text-3); }
.palette .p-foot span { display: inline-flex; gap: 4px; align-items: center; }
@media (max-width: 720px) { .palette { margin-top: 10px; } .palette .p-foot { display: none; } }

/* ---------- hold-to-confirm ---------- */
.hold { position: relative; overflow: hidden; isolation: isolate; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.hold::before { content: ''; position: absolute; inset: 0; z-index: -1; background: rgba(0, 0, 0, 0.28); transform-origin: left; transform: scaleX(0); }
.hold.holding::before { transform: scaleX(1); transition: transform var(--hold-ms, 1500ms) linear; }
.hold.done::before { transform: scaleX(1); }

/* ---------- stepper (onboarding) ---------- */
.stepper { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-3); }
.step { position: relative; padding: var(--s-4); border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); min-width: 0; }
.step .n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--border-strong); font-size: 12px; font-weight: 700; color: var(--text-2); margin-bottom: var(--s-3); }
.step h4 { margin: 0 0 4px; }
.step p { margin: 0; font-size: var(--fs-13); color: var(--text-2); }
.step .btn { margin-top: var(--s-3); }
.step.done .n { background: var(--mint); border-color: transparent; color: var(--text-on-brand); }
.step.done h4 { color: var(--text-2); }
.step.current { border-color: var(--mint); box-shadow: var(--brand-glow); }
@media (max-width: 960px) { .stepper { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) {
  .stepper { grid-template-columns: 1fr; gap: 0; }
  .step { background: transparent; border: 0; border-radius: 0; padding: var(--s-3) 0 var(--s-3) 40px; box-shadow: none; }
  .step .n { position: absolute; left: 0; top: var(--s-3); }
  .step.current { box-shadow: none; }
  .step:not(.current) p, .step:not(.current) .btn { display: none; }
}

/* ---------- badges (milestones) ---------- */
.badges { display: flex; gap: var(--s-3); flex-wrap: wrap; }
.badge { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3) var(--s-2) var(--s-2); border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); min-width: 0; }
.badge .b-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-3); flex: none; }
.badge .b-ico svg { width: 18px; height: 18px; }
.badge .b-t { font-size: var(--fs-13); font-weight: 600; }
.badge .b-s { font-size: var(--fs-12); color: var(--text-3); }
.badge.earned { border-color: rgba(78, 230, 166, 0.35); }
.badge.earned .b-ico { background: var(--brand-gradient); color: var(--text-on-brand); }
.badge:not(.earned) .b-t { color: var(--text-2); }

/* ---------- confetti (reward moment) ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; opacity: 0.95; animation: confetti-fall 2.6s cubic-bezier(0.2, 0.6, 0.4, 1) forwards; }
@keyframes confetti-fall { to { transform: translate3d(var(--dx, 0), 105vh, 0) rotate(var(--rot, 540deg)); opacity: 0.9; } }
@media (prefers-reduced-motion: reduce) { .confetti { display: none; } }
.lock-panel.hidden { display: none; }
.lock-panel { min-height: 280px; margin-bottom: var(--s-4); }
.lock-panel h3 { font-size: var(--fs-18); }
.dlg-list { list-style: none; margin: var(--s-3) 0 0; padding: var(--s-3) var(--s-4); border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; font-family: var(--font-mono); font-size: var(--fs-13); color: var(--text); }
.dlg .dlg-warn { display: flex; gap: var(--s-2); align-items: flex-start; margin: var(--s-3) 0 0; padding: var(--s-3); border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: var(--fs-13); font-weight: 600; }
.dlg-warn svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
