/* odin-htmx-demo — one stylesheet, driven by variables.
   The whole theme is two token sets (dark default, light override). Components
   read tokens, never raw colours, so re-theming is local to :root. */

/* ---- tokens ----------------------------------------------------------- */

:root {
  --violet: #7c5cff;
  --indigo: #5b8cff;
  --cyan:   #22d3ee;
  --pink:   #f472d0;
  --green:  #34d399;
  --amber:  #fbbf24;
  --red:    #fb7185;

  --grad: linear-gradient(135deg, var(--violet), var(--indigo) 55%, var(--cyan));
  --grad-soft: linear-gradient(135deg, color-mix(in oklab, var(--violet) 22%, transparent), color-mix(in oklab, var(--cyan) 22%, transparent));

  --bg:      #0b0d17;
  --bg-2:    #11142100;
  --surface: #151a2c;
  --surface-2: #1b2138;
  --elevated: #20274180;
  --line:    #2a3252;
  --line-2:  #353f66;

  --text:    #eef1fb;
  --muted:   #9aa3c4;
  --faint:   #6b769e;

  --ok:   var(--green);
  --warn: var(--amber);
  --bad:  var(--red);

  --radius:   14px;
  --radius-sm: 9px;
  --radius-lg: 22px;

  --shadow:   0 18px 40px -22px rgba(4, 6, 18, .8);
  --shadow-lg: 0 30px 70px -30px rgba(3, 5, 16, .9);
  --ring: 0 0 0 3px color-mix(in oklab, var(--violet) 40%, transparent);

  --ease: cubic-bezier(.22, .61, .36, 1);
  --spring: cubic-bezier(.2, .9, .25, 1.2);
  --fast: 130ms;
  --med: 200ms;

  --maxw: 1160px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Menlo, monospace;
}

:root[data-theme="light"] {
  --bg:      #f4f6fd;
  --surface: #ffffff;
  --surface-2: #f7f8fe;
  --elevated: #ffffff;
  --line:    #e3e7f4;
  --line-2:  #d3d9ee;

  --text:    #161a2c;
  --muted:   #5b647f;
  --faint:   #8a93ad;

  --shadow:   0 18px 40px -26px rgba(40, 50, 90, .35);
  --shadow-lg: 0 30px 70px -34px rgba(40, 50, 90, .4);
}

/* ---- base ------------------------------------------------------------- */

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 500px at 12% -8%, color-mix(in oklab, var(--violet) 24%, transparent), transparent 60%),
    radial-gradient(800px 520px at 100% 0%, color-mix(in oklab, var(--cyan) 16%, transparent), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.02em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.icon { width: 1.15em; height: 1.15em; flex: none; }

::selection { background: color-mix(in oklab, var(--violet) 45%, transparent); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }

/* ---- topbar ----------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 18px;
  padding: 12px clamp(16px, 4vw, 38px);
  background: color-mix(in oklab, var(--bg) 72%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.03em; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 11px; color: #fff; background: var(--grad);
  box-shadow: 0 8px 22px -8px var(--violet);
}
.brand-mark .icon { width: 19px; height: 19px; }
.brand-name b { color: var(--violet); }

.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 13px; border-radius: 10px; color: var(--muted);
  font-weight: 550; font-size: .92rem;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.nav-link .icon { width: 17px; height: 17px; opacity: .85; }
.nav-link:hover { color: var(--text); background: color-mix(in oklab, var(--surface) 70%, transparent); }
.nav-link[aria-current="page"] { color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-2); }
.nav-link[aria-current="page"] .icon { color: var(--violet); opacity: 1; }
@media (max-width: 880px) { .nav-link span { display: none; } }

/* search box */
.search { position: relative; margin-left: auto; display: flex; align-items: center; }
.search > .icon { position: absolute; left: 12px; color: var(--faint); width: 17px; height: 17px; pointer-events: none; }
.search input {
  width: 230px; max-width: 40vw; padding: 9px 14px 9px 36px;
  border-radius: 11px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-size: .9rem;
  transition: width var(--med) var(--ease), border-color var(--fast), box-shadow var(--fast);
}
.search input::placeholder { color: var(--faint); }
.search input:focus { outline: none; width: 290px; border-color: var(--violet); box-shadow: var(--ring); }

.search-results { position: absolute; top: calc(100% + 9px); right: 0; width: min(380px, 86vw); }
.search-panel {
  background: var(--elevated); backdrop-filter: blur(20px);
  border: 1px solid var(--line-2); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); overflow: hidden;
  animation: pop var(--med) var(--spring);
}
.search-list { list-style: none; margin: 0; padding: 6px; max-height: 60vh; overflow: auto; }
.search-list a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 10px; transition: background var(--fast); }
.search-list a:hover { background: color-mix(in oklab, var(--violet) 16%, transparent); }
.sr-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sr-text strong { font-size: .9rem; font-weight: 600; }
.sr-text small { color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-list mark { background: color-mix(in oklab, var(--cyan) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-empty { padding: 16px; color: var(--muted); font-size: .9rem; }

/* ---- buttons ---------------------------------------------------------- */

.btn {
  --bg-btn: var(--surface-2);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 17px; border: 1px solid var(--line-2); border-radius: 11px;
  background: var(--bg-btn); color: var(--text); font: inherit; font-weight: 600; font-size: .92rem;
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), filter var(--fast), background var(--fast), border-color var(--fast);
}
.btn .icon { width: 17px; height: 17px; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary { border-color: transparent; color: #fff; background: var(--grad); background-size: 160% 160%; box-shadow: 0 10px 26px -12px var(--violet); }
.btn-primary:hover { box-shadow: 0 14px 30px -10px var(--violet); background-position: 100% 0; }
.btn-accent { border-color: transparent; color: #04121a; background: linear-gradient(135deg, var(--cyan), var(--green)); box-shadow: 0 10px 26px -12px var(--cyan); }
.btn-danger { border-color: transparent; color: #fff; background: linear-gradient(135deg, var(--red), var(--pink)); box-shadow: 0 10px 26px -12px var(--red); }
.btn-outline { background: transparent; border-color: var(--line-2); }
.btn-outline:hover { border-color: var(--violet); color: var(--text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface); color: var(--text); }
.btn-loading { pointer-events: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); cursor: pointer;
  transition: transform var(--fast) var(--ease), color var(--fast), background var(--fast), border-color var(--fast);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-2); transform: translateY(-1px); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn.danger:hover { color: var(--red); border-color: color-mix(in oklab, var(--red) 50%, var(--line)); }

/* theme toggle swaps which icon shows */
.theme-toggle .icon { position: absolute; transition: opacity var(--med), transform var(--med) var(--spring); }
.theme-toggle { position: relative; overflow: hidden; }
:root[data-theme="dark"] .theme-toggle .icon:nth-child(1) { opacity: 0; transform: rotate(-90deg) scale(.5); }
:root[data-theme="dark"] .theme-toggle .icon:nth-child(2) { opacity: 1; }
:root[data-theme="light"] .theme-toggle .icon:nth-child(1) { opacity: 1; }
:root[data-theme="light"] .theme-toggle .icon:nth-child(2) { opacity: 0; transform: rotate(90deg) scale(.5); }

/* ---- layout / cards --------------------------------------------------- */

.container { max-width: var(--maxw); margin: 0 auto; padding: clamp(20px, 4vw, 40px); }

.page-head { margin-bottom: 28px; }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: .72rem; font-weight: 700; color: var(--violet); margin-bottom: 8px; }
.page-head h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); }
.lede { color: var(--muted); margin-top: 8px; max-width: 60ch; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { font-size: 1.15rem; }

.block { margin-bottom: 30px; }
.block-head { margin-bottom: 14px; }
.block-head h2 { font-size: 1.2rem; }
.block-head p { font-size: .9rem; margin-top: 3px; }

.demo {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 22px;
}
.demo.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.demo.col { display: flex; flex-direction: column; gap: 16px; }
.demo .row { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
.demo .row.center { align-items: center; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }

/* ---- stats / dashboard ------------------------------------------------ */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  position: relative; overflow: hidden; padding: 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: transform var(--med) var(--ease), border-color var(--med);
}
.stat::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--grad); opacity: .9; }
.stat:hover { transform: translateY(-3px); border-color: var(--line-2); }
.stat-top { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.stat-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--grad-soft); color: var(--violet); }
.stat-label { font-size: .85rem; font-weight: 550; }
.stat-value { font-size: 2.1rem; font-weight: 750; letter-spacing: -.03em; margin: 8px 0 2px; }
.stat-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-delta { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; color: var(--green); font-weight: 600; }
.stat-delta .icon { width: 14px; height: 14px; }
.spark { width: 88px; height: 30px; overflow: visible; }
.spark polyline { fill: none; stroke: var(--cyan); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 4px 8px color-mix(in oklab, var(--cyan) 50%, transparent)); }

.split { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

.link-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .link-grid { grid-template-columns: 1fr; } }
.tile {
  display: flex; gap: 13px; padding: 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2);
  transition: transform var(--fast) var(--ease), border-color var(--fast), background var(--fast);
}
.tile:hover { transform: translateY(-2px); border-color: var(--violet); background: var(--surface); }
.tile-icon { display: grid; place-items: center; width: 38px; height: 38px; flex: none; border-radius: 10px; background: var(--grad-soft); color: var(--violet); }
.tile strong { display: block; font-size: .96rem; }
.tile p { color: var(--muted); font-size: .83rem; margin-top: 2px; }

.ping-slot { min-height: 56px; display: flex; align-items: center; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--line-2); margin: 12px 0 16px; }
.ping-ok { display: flex; align-items: center; gap: 11px; }
.ping-ok .icon { width: 22px; height: 22px; color: var(--green); }
.ping-ok strong { font-family: var(--mono); }
.ping-ok small { display: block; color: var(--muted); }

/* ---- badges / chips / tags / avatars ---------------------------------- */

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; border: 1px solid transparent; }
.badge .dot { width: 7px; height: 7px; border-radius: 99px; background: currentColor; box-shadow: 0 0 0 3px color-mix(in oklab, currentColor 22%, transparent); }
.badge-ok   { color: var(--green); background: color-mix(in oklab, var(--green) 14%, transparent); border-color: color-mix(in oklab, var(--green) 28%, transparent); }
.badge-warn { color: var(--amber); background: color-mix(in oklab, var(--amber) 14%, transparent); border-color: color-mix(in oklab, var(--amber) 28%, transparent); }
.badge-mute { color: var(--faint); background: color-mix(in oklab, var(--faint) 14%, transparent); border-color: color-mix(in oklab, var(--faint) 26%, transparent); }

.chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 8px; font-size: .78rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--muted); }
.chip-r0 { color: var(--indigo); border-color: color-mix(in oklab, var(--indigo) 40%, transparent); }
.chip-r1 { color: var(--pink); border-color: color-mix(in oklab, var(--pink) 40%, transparent); }
.chip-r2 { color: var(--cyan); border-color: color-mix(in oklab, var(--cyan) 40%, transparent); }
.chip-r3 { color: var(--amber); border-color: color-mix(in oklab, var(--amber) 40%, transparent); }
.chip-r4 { color: var(--green); border-color: color-mix(in oklab, var(--green) 40%, transparent); }

.tag { font-family: var(--mono); font-size: .74rem; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--muted); }
.tag-new { color: #fff; background: var(--grad); border-color: transparent; }
.count { position: relative; font-weight: 700; }
.count i { font-style: normal; font-size: .7rem; color: var(--muted); margin-left: 6px; font-weight: 500; }

.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%; font-size: .8rem; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, hsl(var(--h), 80%, 62%), hsl(calc(var(--h) + 40), 75%, 48%));
  box-shadow: 0 6px 14px -6px hsl(var(--h), 70%, 45%); }
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -10px; border: 2px solid var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }
.avatar-more { background: var(--surface-2); color: var(--muted); }

/* ---- meters / rings / spinners ---------------------------------------- */

.meter { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.meter.lg { height: 11px; }
.meter i { display: block; height: 100%; border-radius: inherit; background: var(--grad); transition: width var(--med) var(--ease); }
.meter-accent i { background: linear-gradient(90deg, var(--cyan), var(--green)); }

.ring { --p: 0; position: relative; width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--violet) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: var(--surface); }
.ring span { position: relative; font-weight: 700; font-size: .92rem; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid color-mix(in oklab, currentColor 25%, transparent); border-top-color: currentColor; animation: spin .7s linear infinite; }
.spinner-lg { width: 30px; height: 30px; border-width: 3px; color: var(--violet); }
.bar-indeterminate { position: relative; width: 160px; height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-indeterminate i { position: absolute; inset: 0; width: 40%; border-radius: inherit; background: var(--grad); animation: indeterminate 1.2s var(--ease) infinite; }

/* ---- tabs ------------------------------------------------------------- */

.tabs { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.tablist { display: flex; gap: 2px; padding: 6px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.tab { flex: 1; padding: 9px 14px; border: none; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .9rem; border-radius: 9px; cursor: pointer; transition: color var(--fast), background var(--fast); }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); background: var(--surface); box-shadow: 0 4px 12px -8px rgba(0,0,0,.5), inset 0 0 0 1px var(--line); }
.tabpanel { padding: 22px; animation: fade-up var(--med) var(--ease); }
.tabpanel h3 { margin-bottom: 8px; }

/* ---- accordion -------------------------------------------------------- */

.accordion { gap: 10px; }
.acc { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden; }
.acc summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; cursor: pointer; font-weight: 600; list-style: none; }
.acc summary::-webkit-details-marker { display: none; }
.acc summary .icon { transition: transform var(--med) var(--spring); color: var(--violet); }
.acc[open] summary .icon { transform: rotate(45deg); }
.acc-body { padding: 0 16px 15px; color: var(--muted); animation: fade-up var(--med) var(--ease); }

/* ---- forms ------------------------------------------------------------ */

.form { max-width: 760px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } }
.span-2 { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span, .field legend { font-size: .85rem; font-weight: 600; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.field.inline { flex-direction: row; align-items: center; gap: 12px; }
.field.inline span:last-child { color: var(--text); font-weight: 500; }

input, select, textarea {
  width: 100%; padding: 10px 13px; font: inherit; font-size: .92rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 10px;
  transition: border-color var(--fast), box-shadow var(--fast), background var(--fast);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--violet); box-shadow: var(--ring); background: var(--surface); }
textarea { resize: vertical; min-height: 76px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%239aa3c4' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; cursor: pointer; }
.out { font-family: var(--mono); color: var(--violet); font-size: .8rem; }

/* range */
input[type="range"] { -webkit-appearance: none; appearance: none; height: 7px; padding: 0; border: none; border-radius: 99px;
  background: linear-gradient(90deg, var(--violet), var(--cyan)) no-repeat, var(--surface-2);
  background-size: var(--fill, 50%) 100%; cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 19px; height: 19px; border-radius: 50%; background: #fff; border: 3px solid var(--violet); box-shadow: 0 3px 10px -2px var(--violet); transition: transform var(--fast); }
input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid var(--violet); }

/* switch / check / radio */
.toggle { position: relative; display: inline-flex; flex: none; width: 44px; height: 25px; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle i { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line-2); transition: background var(--fast); }
.toggle i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: var(--faint); transition: transform var(--med) var(--spring), background var(--fast); }
.toggle input:checked + i { background: var(--grad); border-color: transparent; }
.toggle input:checked + i::after { transform: translateX(19px); background: #fff; }
.toggle input:focus-visible + i { box-shadow: var(--ring); }

.check, .radio { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-weight: 500; color: var(--text); }
.check input, .radio input { position: absolute; opacity: 0; width: 0; }
.check i, .radio i { display: grid; place-items: center; width: 20px; height: 20px; flex: none; border: 1px solid var(--line-2); background: var(--surface-2); transition: background var(--fast), border-color var(--fast); }
.check i { border-radius: 6px; }
.radio i { border-radius: 50%; }
.check i::after { content: ""; width: 10px; height: 10px; border-radius: 3px; background: #fff; transform: scale(0); transition: transform var(--fast) var(--spring); }
.radio i::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #fff; transform: scale(0); transition: transform var(--fast) var(--spring); }
.check input:checked + i, .radio input:checked + i { background: var(--grad); border-color: transparent; }
.check input:checked + i::after, .radio input:checked + i::after { transform: scale(1); }
.radios { display: flex; gap: 18px; flex-wrap: wrap; }
fieldset { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }

.field-msg { min-height: 18px; font-size: .8rem; margin: 0; }
.msg { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; animation: fade-up var(--fast) var(--ease); }
.msg-ok { color: var(--green); }
.msg-err { color: var(--red); }

.form-actions { display: flex; gap: 10px; margin-top: 22px; }
.form-result:empty { display: none; }
.result-ok, .result-err { margin-top: 18px; padding: 15px 17px; border-radius: var(--radius-sm); animation: pop var(--med) var(--spring); }
.result-ok { display: flex; gap: 12px; align-items: center; background: color-mix(in oklab, var(--green) 12%, transparent); border: 1px solid color-mix(in oklab, var(--green) 32%, transparent); }
.result-ok .icon { width: 26px; height: 26px; color: var(--green); flex: none; }
.result-ok p { color: var(--muted); font-size: .88rem; margin-top: 2px; }
.result-err { background: color-mix(in oklab, var(--red) 12%, transparent); border: 1px solid color-mix(in oklab, var(--red) 32%, transparent); }
.result-err ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }

/* ---- data table ------------------------------------------------------- */

.toolbar { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .filter { position: relative; flex: 1; min-width: 220px; display: flex; align-items: center; }
.toolbar .filter > .icon { position: absolute; left: 13px; color: var(--faint); width: 17px; height: 17px; pointer-events: none; }
.toolbar .filter input { padding-left: 38px; }

.add { position: relative; }
.add > summary { list-style: none; }
.add > summary::-webkit-details-marker { display: none; }
.add[open] > summary { background: var(--surface); color: var(--text); }
.add-form {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 10px; align-items: center;
  width: min(620px, 92vw); box-shadow: var(--shadow-lg); animation: pop var(--med) var(--spring);
}
@media (max-width: 620px) { .add-form { grid-template-columns: 1fr; right: auto; } }

.table-card { padding: 14px; overflow: visible; }
.table-meta { padding: 4px 8px 12px; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table thead th { text-align: left; padding: 0 6px 10px; border-bottom: 1px solid var(--line); }
.table .th-actions { text-align: right; color: var(--muted); font-size: .8rem; font-weight: 600; padding-right: 14px; }
.sort { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; margin-left: -8px; border: none; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; border-radius: 7px; cursor: pointer; transition: color var(--fast), background var(--fast); }
.sort:hover { color: var(--text); background: var(--surface-2); }
.caret { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; opacity: 0; transition: opacity var(--fast), transform var(--fast); }
.sort[data-dir="asc"] { color: var(--text); }
.sort[data-dir="asc"] .caret { opacity: 1; border-bottom: 5px solid var(--violet); }
.sort[data-dir="desc"] { color: var(--text); }
.sort[data-dir="desc"] .caret { opacity: 1; border-top: 5px solid var(--violet); }

.table tbody td { padding: 11px 6px; border-bottom: 1px solid color-mix(in oklab, var(--line) 60%, transparent); vertical-align: middle; }
.row { transition: background var(--fast); }
.row:hover { background: color-mix(in oklab, var(--violet) 7%, transparent); }
.c-name { display: flex; align-items: center; gap: 11px; }
.c-name .avatar { width: 32px; height: 32px; font-size: .72rem; }
.c-name-text { display: flex; flex-direction: column; line-height: 1.25; }
.c-name-text small { color: var(--faint); font-size: .74rem; font-family: var(--mono); }
.c-email { color: var(--muted); font-size: .86rem; }
.c-score { width: 150px; }
.c-score .meter { margin-bottom: 4px; }
.c-score small { color: var(--muted); font-size: .76rem; }
.c-actions { text-align: right; white-space: nowrap; }
.c-actions .icon-btn { width: 32px; height: 32px; }
.c-actions .icon-btn .icon { width: 15px; height: 15px; }

.row-empty td { padding: 40px !important; }
.empty { display: grid; place-items: center; gap: 10px; color: var(--muted); }
.empty .icon { width: 30px; height: 30px; opacity: .5; }

.pager { display: flex; gap: 6px; justify-content: flex-end; align-items: center; padding: 14px 8px 4px; }
.page { min-width: 34px; height: 34px; padding: 0 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 9px; font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; transition: color var(--fast), border-color var(--fast), background var(--fast); }
.page:hover:not(:disabled) { color: var(--text); border-color: var(--line-2); }
.page:disabled { opacity: .4; cursor: not-allowed; }
.page.is-current { color: #fff; background: var(--grad); border-color: transparent; }

/* ---- overlays --------------------------------------------------------- */

#overlay:empty { display: none; }
.backdrop { position: fixed; inset: 0; z-index: 100; display: grid; background: color-mix(in oklab, #05060f 60%, transparent); backdrop-filter: blur(4px); animation: fade var(--med) var(--ease); }
.backdrop.htmx-swapping { animation: fade var(--med) var(--ease) reverse; }

.modal { place-self: center; width: min(440px, 92vw); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; animation: modal-in var(--med) var(--spring); }
.htmx-swapping .modal { animation: modal-out var(--fast) var(--ease) forwards; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head .icon-btn .icon { transform: rotate(45deg); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-body p { color: var(--muted); font-size: .9rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }

.drawer { place-self: stretch end; width: min(380px, 90vw); height: 100%; background: var(--surface); border-left: 1px solid var(--line-2); box-shadow: var(--shadow-lg); padding: 22px; display: flex; flex-direction: column; gap: 18px; animation: drawer-in var(--med) var(--spring); }
.htmx-swapping .drawer { animation: drawer-out var(--med) var(--ease) forwards; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head .icon-btn .icon { transform: rotate(45deg); }
.drawer-nav { display: flex; flex-direction: column; gap: 4px; }
.drawer-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; color: var(--muted); font-weight: 550; transition: background var(--fast), color var(--fast); }
.drawer-link:hover { background: var(--surface-2); color: var(--text); }
.drawer-link .icon { color: var(--violet); }
.drawer-foot { margin-top: auto; font-size: .84rem; }

/* ---- toasts ----------------------------------------------------------- */

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: 340px; }
.toast { display: flex; align-items: center; gap: 11px; padding: 13px 15px; border-radius: var(--radius-sm); background: var(--elevated); backdrop-filter: blur(18px); border: 1px solid var(--line-2); box-shadow: var(--shadow-lg); animation: toast-in var(--med) var(--spring); }
.toast.leaving { animation: toast-out var(--med) var(--ease) forwards; }
.toast p { font-size: .88rem; font-weight: 550; flex: 1; }
.toast-icon { display: grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 9px; }
.toast-icon .icon { width: 17px; height: 17px; }
.toast-success .toast-icon { color: var(--green); background: color-mix(in oklab, var(--green) 16%, transparent); }
.toast-error .toast-icon { color: var(--red); background: color-mix(in oklab, var(--red) 16%, transparent); }
.toast-info .toast-icon { color: var(--cyan); background: color-mix(in oklab, var(--cyan) 16%, transparent); }
.toast-x { border: none; background: none; color: var(--faint); font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 0 2px; transition: color var(--fast); }
.toast-x:hover { color: var(--text); }

/* ---- tooltip ---------------------------------------------------------- */

[data-tip] { position: relative; }
[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translate(-50%, 4px); white-space: nowrap; padding: 6px 10px; border-radius: 8px; background: #05060f; color: #fff; font-size: .78rem; font-weight: 500; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity var(--fast), transform var(--fast) var(--ease); }
[data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); }

/* ---- htmx swap transitions ------------------------------------------- */

.row-new { animation: row-in 420ms var(--spring); }
tr.htmx-swapping { animation: row-out 220ms var(--ease) forwards; }
.htmx-indicator { opacity: 0; transition: opacity var(--fast); }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---- keyframes -------------------------------------------------------- */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(7px); } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(.94); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(10px) scale(.96); } }
@keyframes drawer-in { from { transform: translateX(100%); } }
@keyframes drawer-out { to { transform: translateX(100%); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px) scale(.95); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(40px) scale(.95); height: 0; margin: 0; padding-top: 0; padding-bottom: 0; } }
@keyframes row-in { from { opacity: 0; transform: translateY(-8px); background: color-mix(in oklab, var(--green) 22%, transparent); } }
@keyframes row-out { to { opacity: 0; transform: translateX(20px); } }
@keyframes indeterminate { 0% { left: -40%; } 100% { left: 100%; } }

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