/*
  Coverup UI: base tokens + components.
  Tokens are --cu-* custom properties. Themes (src/themes/*.css) only override
  the ground and accent tokens; everything else is shared.

  Mode:  <html data-mode="light|dark">   (omit to follow the OS)
  Theme: <html data-theme="sky">         (omit for the default, "sunny")
*/

/* ---------- tokens: light (default theme: sunny) ---------- */
:root {
  --cu-bg: #f7f8fa;
  --cu-surface: #ffffff;
  --cu-tint: #f1f3f6;
  --cu-rule: #e3e6eb;          /* soft inner dividers */
  --cu-line: #16181d;          /* outlines */
  --cu-shadow: #16181d;        /* hard offset shadow */
  --cu-ink: #16181d;
  --cu-ink-soft: #5c6470;
  --cu-ink-faint: #9099a6;
  --cu-accent: #ffd84d;
  --cu-accent-ink: #16181d;
  --cu-danger: #e5484d;
  --cu-ok: #2f9e6e;
  --cu-overlay: rgba(22, 24, 29, .4);

  --cu-border: 2px;
  --cu-radius: 8px;
  --cu-radius-lg: 12px;
  --cu-offset: 3px;            /* buttons, toasts */
  --cu-offset-lg: 4px;         /* panels */
  --cu-offset-xl: 8px;         /* dialogs */

  --cu-font: "Source Sans 3", ui-sans-serif, system-ui, sans-serif;
  --cu-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}

/* ---------- tokens: dark ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --cu-bg: #23252e; --cu-surface: #2c2f3a; --cu-tint: #343744; --cu-rule: #444858;
    --cu-line: #000000; --cu-shadow: #000000;
    --cu-ink: #f1f2f6; --cu-ink-soft: #b4b9c6; --cu-ink-faint: #7f8696;
    --cu-overlay: rgba(12, 13, 18, .5);
    color-scheme: dark;
  }
}
:root[data-mode="dark"] {
  --cu-bg: #23252e; --cu-surface: #2c2f3a; --cu-tint: #343744; --cu-rule: #444858;
  --cu-line: #000000; --cu-shadow: #000000;
  --cu-ink: #f1f2f6; --cu-ink-soft: #b4b9c6; --cu-ink-faint: #7f8696;
  --cu-overlay: rgba(12, 13, 18, .5);
  color-scheme: dark;
}

/* ---------- base ---------- */
.cu-body, body.cu {
  background: var(--cu-bg); color: var(--cu-ink); font-family: var(--cu-font);
  font-size: 16px; line-height: 1.5;
}
:where(.cu) :focus-visible, .cu :focus-visible { outline: 2px solid var(--cu-ink); outline-offset: 2px; }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i-sm { width: 15px; height: 15px; }

/* ---------- panel / card ---------- */
.panel {
  background: var(--cu-surface); border: var(--cu-border) solid var(--cu-line);
  border-radius: var(--cu-radius-lg); overflow: hidden;
  box-shadow: var(--cu-offset-lg) var(--cu-offset-lg) 0 var(--cu-shadow);
}
.panel .panel { border-color: var(--cu-line); border-radius: 10px; box-shadow: none; }
.panel-flat { box-shadow: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--cu-radius);
  font: 600 14.5px/1 var(--cu-font); white-space: nowrap; cursor: pointer; text-decoration: none;
  border: var(--cu-border) solid var(--cu-line); background: var(--cu-surface); color: var(--cu-ink);
  box-shadow: var(--cu-offset) var(--cu-offset) 0 var(--cu-shadow);
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: calc(var(--cu-offset) + 1px) calc(var(--cu-offset) + 1px) 0 var(--cu-shadow); }
.btn:active { transform: translate(var(--cu-offset), var(--cu-offset)); box-shadow: none; }
.btn-primary { background: var(--cu-accent); color: var(--cu-accent-ink); }
.btn-outline { background: transparent; }
.btn-danger { background: var(--cu-danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--cu-ink-soft); border-color: transparent; box-shadow: none; }
.btn-ghost:hover { transform: none; box-shadow: none; background: var(--cu-tint); color: var(--cu-ink); }
.btn-ghost:active { transform: none; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13.5px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 16px; }
.btn-icon { width: 36px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; box-shadow: none; transform: none; pointer-events: none; }
/* htmx adds .htmx-request to the element while its request is in flight */
.btn.htmx-request { pointer-events: none; opacity: .85; }
.btn.htmx-request::before {
  content: ""; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: cu-spin .7s linear infinite;
}
@keyframes cu-spin { to { transform: rotate(360deg); } }

/* ---------- badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px;
  border-radius: 6px; font-size: 12.5px; font-weight: 600;
  border: var(--cu-border) solid var(--cu-line); background: var(--cu-surface); color: var(--cu-ink-soft);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--dot, var(--cu-ink-faint)); }
.badge-ok { --dot: var(--cu-ok); }
.badge-danger { --dot: var(--cu-danger); }
.badge-warn { --dot: var(--cu-accent); }
.badge-plain::before { display: none; }

/* ---------- form ---------- */
.input {
  width: 100%; height: 36px; padding: 0 12px; border-radius: var(--cu-radius);
  border: var(--cu-border) solid var(--cu-line); background: var(--cu-surface); color: var(--cu-ink);
  font: inherit; font-size: 14.5px;
}
.input::placeholder { color: var(--cu-ink-faint); }
.input:focus { outline: none; box-shadow: 3px 3px 0 var(--cu-accent), 3px 3px 0 1.5px var(--cu-line); }
.label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--cu-ink-soft); }
.search { position: relative; }
.search > .i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--cu-ink-faint); width: 15px; height: 15px; }
.search > .input { padding-left: 34px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 20px; height: 56px; padding: 0 16px; background: var(--cu-surface); border-bottom: var(--cu-border) solid var(--cu-line); }
.logo { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--cu-ink); color: var(--cu-surface); font-weight: 700; font-size: 15px; }
.navlink { position: relative; display: inline-flex; align-items: center; gap: 7px; height: 56px; padding: 0 4px; font-weight: 500; font-size: 15px; color: var(--cu-ink-soft); text-decoration: none; }
.navlink:hover { color: var(--cu-ink); }
.navlink[aria-current="page"] { color: var(--cu-ink); font-weight: 600; }
.navlink[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: calc(var(--cu-border) * -1); height: 3px; background: var(--cu-accent); border-top: 1.5px solid var(--cu-line); }
.kbd { font: 11px var(--cu-mono); padding: 1px 5px; border: 1.5px solid var(--cu-rule); border-radius: 5px; color: var(--cu-ink-faint); }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: var(--cu-border) solid var(--cu-line); background: var(--cu-accent); color: var(--cu-accent-ink); font-size: 12px; font-weight: 700; }

/* ---------- list rows, table ---------- */
.row-link { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--cu-rule); font-size: 16px; cursor: pointer; color: inherit; text-decoration: none; }
.row-link:first-child { border-top: 0; }
.row-link:hover { background: var(--cu-tint); }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; padding: 11px 16px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--cu-ink-faint); background: var(--cu-tint); border-bottom: 1px solid var(--cu-rule); }
.tbl td { padding: 12px 16px; border-top: 1px solid var(--cu-rule); }
.tbl tbody tr:first-child td { border-top: 0; }
.tbl tbody tr:hover td { background: var(--cu-tint); }
.tbl [data-empty] td { text-align: center; color: var(--cu-ink-soft); padding: 28px; }
.tbl [data-empty]:hover td { background: transparent; }
.table-scroll { overflow-x: auto; }

/* ---------- tree / sidebar (details + summary, no JS) ---------- */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin: 2px 0 4px 15px; padding-left: 12px; border-left: 1.5px solid var(--cu-rule); }
.tree-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: var(--cu-border) solid transparent; border-radius: var(--cu-radius); cursor: pointer; font-size: 15.5px; color: var(--cu-ink-soft); text-decoration: none; }
.tree-item:hover { background: var(--cu-tint); color: var(--cu-ink); }
.tree-item[aria-current="true"], .tree-item[aria-current="page"] { background: var(--cu-accent); color: var(--cu-accent-ink); font-weight: 600; border-color: var(--cu-line); box-shadow: 2px 2px 0 var(--cu-shadow); }
.tree-item[aria-current] .badge { background: var(--cu-surface); color: var(--cu-ink); }
.tree summary { list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree .chev { transition: transform .15s; }
.tree details[open] > summary .chev { transform: rotate(90deg); }

/* ---------- dialog / modal ---------- */
dialog.modal {
  width: min(440px, calc(100vw - 32px)); padding: 0; color: var(--cu-ink); background: var(--cu-surface);
  border: var(--cu-border) solid var(--cu-line); border-radius: var(--cu-radius-lg);
  box-shadow: var(--cu-offset-xl) var(--cu-offset-xl) 0 var(--cu-shadow);
}
dialog.modal::backdrop { background: var(--cu-overlay); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--cu-rule); }
.modal-title { margin: 0; font-size: 18px; font-weight: 600; }
.modal-body { padding: 20px; display: grid; gap: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; background: var(--cu-tint); border-top: 1px solid var(--cu-rule); }
.confirm-body { padding: 20px; display: flex; gap: 12px; }
.confirm-icon { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border: var(--cu-border) solid var(--cu-line); border-radius: var(--cu-radius); color: var(--cu-danger); }
.confirm-icon.is-neutral { color: var(--cu-ink); }
.confirm-text { margin: 2px 0 0; font-size: 15px; color: var(--cu-ink-soft); }

/* ---------- toast ---------- */
.toast-stack { position: fixed; z-index: 1000; display: grid; gap: 12px; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); }
.toast { position: relative; overflow: hidden; display: flex; align-items: flex-start; gap: 12px; width: min(320px, calc(100vw - 32px)); padding: 12px 14px; border-radius: 10px; background: var(--cu-surface); color: var(--tone, var(--cu-ink-soft)); border: var(--cu-border) solid var(--cu-line); box-shadow: var(--cu-offset-lg) var(--cu-offset-lg) 0 var(--cu-shadow); animation: cu-in .2s ease-out; }
.toast-ok { --tone: var(--cu-ok); } .toast-error { --tone: var(--cu-danger); }
.toast-text { color: var(--cu-ink); }
.toast-title { font-weight: 600; }
.toast-msg { font-size: 14px; color: var(--cu-ink-soft); }
.toast-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: currentColor; animation: cu-life var(--life, 4s) linear forwards; }
@keyframes cu-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes cu-life { from { width: 100%; } to { width: 0; } }

/* ---------- theme swatch (optional picker) ---------- */
.swatch { width: 28px; height: 28px; border-radius: 50%; border: var(--cu-border) solid var(--cu-line); box-shadow: 2px 2px 0 var(--cu-shadow); cursor: pointer; transition: transform .08s, box-shadow .08s; }
.swatch:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--cu-shadow); }
.swatch[aria-pressed="true"] { outline: 2px solid var(--cu-ink); outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .btn, .swatch, .toast, .toast-bar, .tree .chev { animation: none !important; transition: none !important; }
}

/* =====================================================================
   More components
   ===================================================================== */

/* ---------- layout helpers ---------- */
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.stack { display: grid; gap: 16px; }

/* ---------- card / panel parts ---------- */
.card-body { display: grid; gap: 12px; padding: 20px; }
.card-title { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.3; }
.card-text { margin: 0; font-size: 15px; color: var(--cu-ink-soft); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--cu-rule); }
.panel-title { margin: 0; font-size: 15px; font-weight: 600; }
.panel-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--cu-rule); background: var(--cu-tint); }

/* ---------- alert ---------- */
.alert { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: var(--cu-border) solid var(--cu-line); border-radius: 10px; background: var(--cu-surface); box-shadow: var(--cu-offset) var(--cu-offset) 0 var(--cu-shadow); --tone: var(--cu-ink-soft); }
.alert > .i { color: var(--tone); margin-top: 1px; }
.alert-title { font-weight: 600; }
.alert-text { font-size: 14.5px; color: var(--cu-ink-soft); }
.alert-ok { --tone: var(--cu-ok); } .alert-error { --tone: var(--cu-danger); } .alert-warn { --tone: #d99a00; }

/* ---------- avatar ---------- */
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 44px; height: 44px; font-size: 15px; }
.avatar-group { display: inline-flex; }
.avatar-group .avatar + .avatar { margin-left: -10px; }

/* ---------- breadcrumb ---------- */
.breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; padding: 0; list-style: none; font-size: 14.5px; color: var(--cu-ink-soft); }
.breadcrumb li + li::before { content: "/"; margin-right: 8px; color: var(--cu-ink-faint); }
.breadcrumb a { color: inherit; text-decoration: none; }
.breadcrumb a:hover { color: var(--cu-ink); text-decoration: underline; }
.breadcrumb [aria-current="page"] { color: var(--cu-ink); font-weight: 600; }

/* ---------- dropdown (details/summary, closes on outside click via coverup.js) ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown > summary { list-style: none; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown-menu { position: absolute; z-index: 50; top: calc(100% + 8px); left: 0; min-width: 200px; margin: 0; padding: 6px; list-style: none; background: var(--cu-surface); border: var(--cu-border) solid var(--cu-line); border-radius: 10px; box-shadow: var(--cu-offset-lg) var(--cu-offset-lg) 0 var(--cu-shadow); }
.dropdown-end .dropdown-menu { left: auto; right: 0; }
.dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--cu-ink); font: inherit; font-size: 15px; text-align: left; text-decoration: none; cursor: pointer; }
.dropdown-item:hover { background: var(--cu-tint); }
.dropdown-item.is-danger { color: var(--cu-danger); }
.dropdown-sep { height: 1px; margin: 6px 4px; background: var(--cu-rule); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; border-bottom: var(--cu-border) solid var(--cu-line); overflow-x: auto; }
.tab { margin-bottom: calc(var(--cu-border) * -1); padding: 8px 14px; border: var(--cu-border) solid transparent; border-bottom: 0; border-radius: var(--cu-radius) var(--cu-radius) 0 0; background: none; color: var(--cu-ink-soft); font: 600 15px var(--cu-font); white-space: nowrap; cursor: pointer; }
.tab:hover { color: var(--cu-ink); background: var(--cu-tint); }
.tab[aria-selected="true"] { background: var(--cu-accent); color: var(--cu-accent-ink); border-color: var(--cu-line); }
.tab-panel { padding-top: 16px; }

/* ---------- button group + pagination ---------- */
.join { display: inline-flex; box-shadow: var(--cu-offset) var(--cu-offset) 0 var(--cu-shadow); border-radius: var(--cu-radius); }
.join > .btn { border-radius: 0; box-shadow: none; }
.join > .btn + .btn { margin-left: calc(var(--cu-border) * -1); }
.join > .btn:first-child { border-radius: var(--cu-radius) 0 0 var(--cu-radius); }
.join > .btn:last-child { border-radius: 0 var(--cu-radius) var(--cu-radius) 0; }
.join > .btn:hover { transform: none; box-shadow: none; background: var(--cu-tint); }
.join > .btn:active { transform: none; }
.join > .btn[aria-current="page"] { background: var(--cu-accent); color: var(--cu-accent-ink); }

/* ---------- progress ---------- */
.progress { appearance: none; -webkit-appearance: none; width: 100%; height: 14px; border: var(--cu-border) solid var(--cu-line); border-radius: 999px; background: var(--cu-surface); overflow: hidden; }
.progress::-webkit-progress-bar { background: transparent; }
.progress::-webkit-progress-value { background: var(--cu-accent); border-right: var(--cu-border) solid var(--cu-line); }
.progress::-moz-progress-bar { background: var(--cu-accent); border-right: var(--cu-border) solid var(--cu-line); }

/* ---------- tooltip (CSS only) ---------- */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { content: attr(data-tip); position: absolute; z-index: 60; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); padding: 4px 9px; border-radius: 6px; background: var(--cu-ink); color: var(--cu-surface); font: 500 12.5px var(--cu-font); white-space: nowrap; pointer-events: none; }

/* ---------- stat ---------- */
.stat { display: grid; gap: 4px; padding: 16px 18px; }
.stat-label { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--cu-ink-faint); }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-delta { font-size: 13.5px; color: var(--cu-ok); font-weight: 600; }
.stat-delta.is-down { color: var(--cu-danger); }

/* ---------- empty state ---------- */
.empty { display: grid; justify-items: center; gap: 8px; padding: 40px 20px; text-align: center; }
.empty > .i { width: 32px; height: 32px; color: var(--cu-ink-faint); }
.empty-title { margin: 0; font-size: 18px; font-weight: 600; }
.empty-text { margin: 0 0 8px; max-width: 36ch; font-size: 15px; color: var(--cu-ink-soft); }

/* ---------- form controls ---------- */
.field { display: grid; gap: 6px; }
.hint { font-size: 13px; color: var(--cu-ink-soft); }
.hint.is-error { color: var(--cu-danger); }
.input.is-invalid { border-color: var(--cu-danger); }
.textarea { min-height: 96px; padding: 10px 12px; height: auto; resize: vertical; line-height: 1.45; }
.select { appearance: none; -webkit-appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239099a6' 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 10px center; background-size: 16px; }
.check { appearance: none; -webkit-appearance: none; flex: none; width: 20px; height: 20px; margin: 0; border: var(--cu-border) solid var(--cu-line); border-radius: 5px; background: var(--cu-surface); cursor: pointer; }
.check[type="radio"] { border-radius: 50%; }
.check:checked { background-color: var(--cu-accent); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2316181d' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7'/%3E%3C/svg%3E"); background-size: 14px; background-position: center; background-repeat: no-repeat; }
.check[type="radio"]:checked { background-image: radial-gradient(circle, #16181d 0 3.5px, transparent 4px); background-size: auto; }
.toggle { appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 42px; height: 24px; margin: 0; border: var(--cu-border) solid var(--cu-line); border-radius: 999px; background: var(--cu-surface); cursor: pointer; transition: background .15s; }
.toggle::before { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--cu-ink); transition: transform .15s; }
.toggle:checked { background: var(--cu-accent); }
.toggle:checked::before { transform: translateX(18px); background: #16181d; }
.check:disabled, .toggle:disabled, .input:disabled { opacity: .45; cursor: not-allowed; }
.choice { display: inline-flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
:where(.check, .toggle):focus-visible { outline: 2px solid var(--cu-ink); outline-offset: 2px; }
