/* WaterProxy — shared design tokens and components
   Palette: violet-biased neutrals + one brand violet (#5A4AE3 from the logo).
   Type: Mona Sans (variable width: expanded for display, normal for text) + Geist Mono for machine strings. */

@font-face {
  font-family: 'Mona Sans';
  src: url('/assets/fonts/mona-sans-latin.woff2') format('woff2-variations');
  font-weight: 200 900;
  font-stretch: 75% 125%;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/assets/fonts/geist-mono-latin.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-sans: 'Mona Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;

  /* light palette */
  --bg: #f6f6f9;
  --bg-2: #eeedf3;
  --surface: #ffffff;
  --surface-2: #fafafc;
  --ink: #121119;
  --ink-2: #4a4958;
  --ink-3: #7a798b;
  --line: #e5e4ec;
  --line-2: #d6d5e0;
  --brand: #5a4ae3;
  --brand-hover: #4b3bd5;
  --brand-text: #4e3ed9;
  --brand-ink: #ffffff;
  --brand-soft: rgba(90, 74, 227, 0.08);
  --brand-soft-2: rgba(90, 74, 227, 0.14);
  --brand-line: rgba(90, 74, 227, 0.32);
  --brand-glow: rgba(90, 74, 227, 0.45);
  --ok: #0c8f63;
  --ok-soft: rgba(12, 143, 99, 0.1);
  --warn: #b16c00;
  --warn-soft: rgba(177, 108, 0, 0.1);
  --bad: #cf3340;
  --bad-soft: rgba(207, 51, 64, 0.09);
  --shadow-1: 0 1px 2px rgba(18, 17, 25, 0.05), 0 1px 1px rgba(18, 17, 25, 0.03);
  --shadow-2: 0 18px 40px -22px rgba(40, 28, 120, 0.28), 0 2px 6px rgba(18, 17, 25, 0.04);
  --shadow-3: 0 30px 80px -30px rgba(40, 28, 120, 0.35), 0 4px 14px rgba(18, 17, 25, 0.06);
  --overlay: rgba(14, 13, 22, 0.42);
  --ring: 0 0 0 3px rgba(90, 74, 227, 0.32);
  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 18px;
  --radius-xl: 26px;
  --nav-h: 64px;
  --gutter: clamp(16px, 4vw, 40px);
  --maxw: 1200px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090e;
    --bg-2: #101017;
    --surface: #121219;
    --surface-2: #16161f;
    --ink: #eeedf6;
    --ink-2: #a5a4b8;
    --ink-3: #6f6e83;
    --line: #22212d;
    --line-2: #2f2e3d;
    --brand: #6353ec;
    --brand-hover: #7263f2;
    --brand-text: #a59bfa;
    --brand-ink: #ffffff;
    --brand-soft: rgba(124, 110, 246, 0.1);
    --brand-soft-2: rgba(124, 110, 246, 0.17);
    --brand-line: rgba(140, 126, 250, 0.36);
    --brand-glow: rgba(110, 95, 245, 0.55);
    --ok: #3ccf98;
    --ok-soft: rgba(60, 207, 152, 0.12);
    --warn: #f0ae45;
    --warn-soft: rgba(240, 174, 69, 0.12);
    --bad: #ff6b76;
    --bad-soft: rgba(255, 107, 118, 0.12);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 18px 40px -20px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.02);
    --shadow-3: 0 30px 80px -30px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.03);
    --overlay: rgba(4, 4, 8, 0.66);
    --ring: 0 0 0 3px rgba(140, 126, 250, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #09090e;
  --bg-2: #101017;
  --surface: #121219;
  --surface-2: #16161f;
  --ink: #eeedf6;
  --ink-2: #a5a4b8;
  --ink-3: #6f6e83;
  --line: #22212d;
  --line-2: #2f2e3d;
  --brand: #6353ec;
  --brand-hover: #7263f2;
  --brand-text: #a59bfa;
  --brand-ink: #ffffff;
  --brand-soft: rgba(124, 110, 246, 0.1);
  --brand-soft-2: rgba(124, 110, 246, 0.17);
  --brand-line: rgba(140, 126, 250, 0.36);
  --brand-glow: rgba(110, 95, 245, 0.55);
  --ok: #3ccf98;
  --ok-soft: rgba(60, 207, 152, 0.12);
  --warn: #f0ae45;
  --warn-soft: rgba(240, 174, 69, 0.12);
  --bad: #ff6b76;
  --bad-soft: rgba(255, 107, 118, 0.12);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 18px 40px -20px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.02);
  --shadow-3: 0 30px 80px -30px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.03);
  --overlay: rgba(4, 4, 8, 0.66);
  --ring: 0 0 0 3px rgba(140, 126, 250, 0.4);
  color-scheme: dark;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  font-weight: 420;
  font-stretch: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg, canvas, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
p { margin: 0; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.1; text-wrap: balance; }
ul, ol { margin: 0; padding: 0; }
[hidden] { display: none !important; }
::selection { background: var(--brand-soft-2); color: var(--ink); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }

.mono { font-family: var(--font-mono); font-feature-settings: 'zero' 1; letter-spacing: -0.01em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.brand-text { color: var(--brand-text); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- logo ---------- */
.logo { display: inline-flex; align-items: center; gap: 9px; color: var(--brand-text); }
.logo svg { height: 26px; width: auto; }
.logo .logo-mark { height: 22px; }
.logo .logo-word { height: 19px; }
:root:not([data-theme="light"]) .logo, :root[data-theme="dark"] .logo { color: var(--brand-text); }

/* ---------- buttons ---------- */
.btn {
  --h: 42px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h); padding: 0 18px;
  border-radius: 11px; border: 1px solid transparent;
  font-size: 15px; font-weight: 600; font-stretch: 104%; letter-spacing: -0.005em; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .15s ease, box-shadow .2s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--brand); color: var(--brand-ink); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .16), 0 8px 20px -10px var(--brand-glow); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink); box-shadow: var(--shadow-1); }
.btn-ghost:hover:not(:disabled) { border-color: var(--brand-line); background: var(--surface-2); }
.btn-quiet { background: transparent; color: var(--ink-2); }
.btn-quiet:hover:not(:disabled) { background: var(--bg-2); color: var(--ink); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.06); }
.btn-soft { background: var(--brand-soft); color: var(--brand-text); }
.btn-soft:hover:not(:disabled) { background: var(--brand-soft-2); }
.btn-lg { --h: 50px; padding: 0 24px; font-size: 16px; border-radius: 13px; }
.btn-sm { --h: 34px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn-xs { --h: 28px; padding: 0 10px; font-size: 13px; border-radius: 8px; gap: 6px; }
.btn-xs svg, .btn-sm svg { width: 15px; height: 15px; }
.btn-icon { width: var(--h); padding: 0; }
.btn-block { width: 100%; }
.btn .spinner { width: 16px; height: 16px; }

.link { color: var(--brand-text); font-weight: 560; text-decoration: underline; text-decoration-color: var(--brand-line); text-underline-offset: 3px; }
.link:hover { text-decoration-color: currentColor; }

/* ---------- form controls ---------- */
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; align-content: start; min-width: 0; }
.field > span:not(.hint):not(.pw-wrap):not(.money-input), .label { font-size: 14px; font-weight: 560; color: var(--ink); }
.hint { font-size: 13px; font-weight: 420; color: var(--ink-3); }
.hint-warn { color: var(--warn); }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 13px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 11px;
  font-size: 15px; line-height: 1.4;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:hover, .select:hover, .textarea:hover { border-color: color-mix(in srgb, var(--brand) 30%, var(--line-2)); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.textarea { min-height: 120px; resize: vertical; }
.select { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input.mono { font-family: var(--font-mono); font-size: 14px; }
.input-group { display: flex; gap: 8px; align-items: stretch; }
.input-group > .input { flex: 1; min-width: 0; }
.code-input { font-family: var(--font-mono); font-size: 26px; letter-spacing: .5em; text-align: center; padding-left: .5em; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { position: relative; width: 38px; height: 22px; border-radius: 99px; background: var(--line-2); transition: background .18s ease; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .18s ease; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }
.switch input:disabled + .track { opacity: .5; }

/* segmented control */
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); gap: 2px; }
.seg button { border: 0; background: transparent; height: 34px; padding: 0 14px; border-radius: 9px; font-size: 14px; font-weight: 580; color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.seg button:hover:not([aria-pressed="true"]) { color: var(--ink); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 560; cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--brand); color: var(--brand-text); background: var(--brand-soft); }
.chip:hover { color: var(--ink); }

/* ---------- badges & status ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 7px; font-size: 12px; font-weight: 620; letter-spacing: .01em; background: var(--bg-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.brand { background: var(--brand-soft); color: var(--brand-text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.dot.live { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 3px var(--ok-soft); } 50% { box-shadow: 0 0 0 6px transparent; } }
@media (prefers-reduced-motion: reduce) { .dot.live { animation: none; } }

.kbd { font-family: var(--font-mono); font-size: 12px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--surface-2); }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); }
.panel-pad { padding: 22px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

/* code block */
.code {
  position: relative;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.65;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; white-space: pre; color: var(--ink);
}
.code .c-key { color: var(--brand-text); }
.code .c-str { color: var(--ok); }
.code .c-dim { color: var(--ink-3); }

/* ---------- toasts ---------- */
.toasts { position: fixed; z-index: 90; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 13px;
  background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow-3); font-size: 14px; line-height: 1.45;
  animation: toast-in .22s ease-out;
}
.toast svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast.ok svg { color: #3ccf98; }
.toast.bad svg { color: #ff8a92; }
@keyframes toast-in { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ---------- dialogs ---------- */
dialog.dlg {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-3);
}
dialog.dlg::backdrop { background: var(--overlay); backdrop-filter: blur(3px); }
dialog.dlg[open] { animation: dlg-in .18s ease-out; }
@keyframes dlg-in { from { transform: translateY(10px) scale(.985); opacity: .5; } to { transform: none; opacity: 1; } }
.dlg-head { padding: 20px 22px 0; }
.dlg-head h2 { font-size: 20px; font-stretch: 112%; letter-spacing: -0.02em; }
.dlg-body { padding: 14px 22px 4px; display: grid; gap: 14px; color: var(--ink-2); font-size: 15px; }
.dlg-foot { padding: 18px 22px 20px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@media (prefers-reduced-motion: reduce) { dialog.dlg[open], .toast { animation: none; } }

/* spinner */
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* skeleton */
.skel { background: linear-gradient(90deg, var(--bg-2), var(--line), var(--bg-2)); background-size: 200% 100%; animation: skel 1.3s ease-in-out infinite; border-radius: 8px; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* theme toggle icon swap */
.theme-toggle .i-sun { display: none; }
.theme-toggle .i-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}

/* table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; font-family: var(--font-mono); }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl .r { text-align: right; }
.tbl .nowrap { white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-3); font-size: 15px; }
