/* Style modelled on paywithme.xnoxstudio.in.th: monochrome "egg" surfaces, hairline borders,
   42px grid backdrop with a soft top glow, white pill buttons, LINE Seed Sans TH. */
:root, :root[data-theme="dark"] {
  --egg: #121212;
  --egg-soft: #212121;
  --egg-line: #1c1c1c;
  --card: #191919;
  --ink: #fafafa;
  --muted: #a3a3a3;
  --faint: #6b6b6b;
  --line: #262626;
  --on-ink: #121212;          /* text on a solid ink (white) button */
  --ok: #00d294;
  --warn: #fcbb00;
  --bad: #ff6b6b;
  --glow: #ffffff12;
  --pane-shadow: 0 30px 60px -24px #000000d9, inset 0 1px 0 #ffffff0f;
  --radius: 16px;
  --ease: cubic-bezier(.22, 1, .36, 1);       /* expo-out: fast start, long soft landing */
  --spring: cubic-bezier(.34, 1.4, .64, 1);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --egg: #fafafa;
  --egg-soft: #f0f0f0;
  --egg-line: #ececec;
  --card: #ffffff;
  --ink: #121212;
  --muted: #525252;
  --faint: #8a8a8a;
  --line: #e5e5e5;
  --on-ink: #fafafa;
  --ok: #059669;
  --warn: #b45309;
  --bad: #dc2626;
  --glow: #00000009;
  --pane-shadow: 0 24px 48px -28px #00000038, inset 0 1px 0 #ffffffcc;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { background: var(--egg); overscroll-behavior-y: none; scrollbar-gutter: stable; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  font: 15px/1.55 "LINE Seed Sans TH", ui-sans-serif, system-ui, "Leelawadee UI", Tahoma, sans-serif;
  background-color: var(--egg);
  background-image:
    radial-gradient(ellipse 65% 42% at 50% 0%, var(--glow), transparent 72%),
    linear-gradient(to right, var(--egg-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--egg-line) 1px, transparent 1px);
  background-size: 100% 100%, 42px 42px, 42px 42px;
  background-position: top;
  background-attachment: fixed;
}
[hidden] { display: none !important; }
.sprite { position: absolute; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
::selection { background: color-mix(in oklab, var(--ink) 25%, transparent); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
body, .card, input, select, button, td, th { transition: background-color .25s, border-color .2s, color .2s, box-shadow .25s, transform .15s, opacity .2s; }

/* Surfaces */
.card {
  background: linear-gradient(to bottom, var(--card), var(--egg));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--pane-shadow);
}

/* Login / setup */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(400px, 100%); padding: 28px; display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.brand .logo { width: 48px; height: 48px; }
.brand.small .logo { width: 28px; height: 28px; }
.wordmark { font-weight: 800; font-size: 24px; line-height: 1; letter-spacing: .32em; color: var(--ink); }
.brand.small .wordmark { font-size: 16px; letter-spacing: .24em; }
#g-gold stop:first-child { stop-color: var(--ink); }
#g-gold stop:last-child { stop-color: var(--faint); }
.dia { fill: var(--ink); }

/* Forms */
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, select {
  font: inherit; color: var(--ink); background: var(--egg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 13px; outline: none;
}
input::placeholder { color: var(--faint); }
input:hover, select:hover { border-color: var(--faint); }
input:focus, select:focus { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ink) 12%, transparent); }

/* Buttons: ghost chips, solid white pill for the primary action */
button {
  position: relative; font: inherit; font-weight: 600; cursor: pointer; border-radius: 999px; padding: 9px 18px;
  border: 1px solid var(--line); color: var(--ink); background: var(--egg-soft);
}
button:hover:not(:disabled) { border-color: var(--faint); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px) scale(.98); }
button.gold { color: var(--on-ink); background: var(--ink); border-color: var(--ink); box-shadow: 0 8px 24px -10px color-mix(in oklab, var(--ink) 55%, transparent); }
button.gold:hover:not(:disabled) { opacity: .9; border-color: var(--ink); }
button.ghost { background: transparent; }
button.ghost:hover:not(:disabled) { background: var(--egg-soft); }
button.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }
button.small { padding: 4px 11px; font-size: 12px; font-weight: 500; }

/* App shell */
#view-app { max-width: 1280px; margin: 0 auto; padding: 18px 16px 40px; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin: -18px -16px 18px; padding: 12px 16px;
  background: color-mix(in oklab, var(--egg) 72%, transparent);
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--line);
  transition: box-shadow .3s, background-color .3s;
}
.topbar.scrolled { box-shadow: 0 10px 30px -18px #000000b3; background: color-mix(in oklab, var(--egg) 86%, transparent); }
.app-picker { display: flex; gap: 8px; flex: 1; justify-content: center; }
.app-picker select { min-width: 220px; border-radius: 999px; }
.user { display: flex; align-items: center; gap: 10px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 14px; }
.stat { position: relative; padding: 18px 20px; overflow: hidden; }
.stat:hover { transform: translateY(-3px); border-color: var(--faint); }
.stat .muted { font-size: 13px; }
.num { font-weight: 800; font-size: 32px; line-height: 1.2; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--ink); }
.num.ok { color: var(--ok); }
.num.bad { color: var(--bad); }

.seg.ok, .swatch.ok { background: var(--ok); }
.seg.gold, .swatch.gold { background: var(--warn); }
.seg.dim, .swatch.dim { background: var(--faint); }
.seg.bad, .swatch.bad { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { background: transparent; border-color: transparent; color: var(--muted); }
.tab:hover:not(:disabled) { color: var(--ink); border-color: transparent; background: var(--egg-soft); }
.tab.active { color: var(--on-ink); background: var(--ink); border-color: var(--ink); }

.panel { padding: 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input { flex: 1; min-width: 200px; border-radius: 999px; padding-left: 16px; }
.toolbar select { border-radius: 999px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--faint); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tr:hover td { background: color-mix(in oklab, var(--ink) 3%, transparent); }
td.name { font-weight: 700; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: 4px; opacity: .7; }
tr:hover td.actions button { opacity: 1; }

.pill { display: inline-block; padding: 2px 11px; border-radius: 999px; font-size: 12px; font-weight: 500; border: 1px solid; }
.pill.ok { color: var(--ok); border-color: color-mix(in oklab, var(--ok) 35%, transparent); background: color-mix(in oklab, var(--ok) 9%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in oklab, var(--bad) 35%, transparent); background: color-mix(in oklab, var(--bad) 9%, transparent); }
.pill.dim { color: var(--muted); border-color: var(--line); background: var(--egg-soft); }
.pill.gold { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 35%, transparent); background: color-mix(in oklab, var(--warn) 9%, transparent); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 6px; animation: pulse 1.8s ease-in-out infinite; }

/* Settings */
h3 { margin: 6px 0 12px; font-size: 16px; font-weight: 700; }
.switch-row { display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); color: var(--ink); font-size: 14px; }
.switch-row small { grid-column: 2; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--ink); }
pre { background: var(--egg); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow-x: auto; color: var(--muted); font-size: 12.5px; }

/* Dialog & toast */
dialog {
  color: var(--ink); padding: 24px; width: min(460px, calc(100vw - 32px));
  opacity: 0; transform: translateY(18px) scale(.96);
  transition: opacity .25s var(--ease), transform .35s var(--ease), overlay .35s allow-discrete, display .35s allow-discrete;
}
dialog[open] { opacity: 1; transform: none; }
@starting-style { dialog[open] { opacity: 0; transform: translateY(18px) scale(.96); } }
dialog::backdrop { background: rgba(0, 0, 0, 0); backdrop-filter: blur(0); transition: background .3s, backdrop-filter .3s, overlay .3s allow-discrete, display .3s allow-discrete; }
dialog[open]::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
@starting-style { dialog[open]::backdrop { background: rgba(0, 0, 0, 0); backdrop-filter: blur(0); } }
#dialog-body { display: grid; gap: 12px; margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.keys-out { max-height: 260px; overflow: auto; margin: 0; color: var(--ink); }
.warn { color: var(--warn); font-size: 13px; margin: 0; }
.toast {
  position: fixed; right: 18px; bottom: 18px; padding: 12px 18px; border-radius: 999px; z-index: 10;
  background: var(--card); border: 1px solid var(--faint); box-shadow: var(--pane-shadow);
}
.toast.bad { border-color: var(--bad); color: var(--bad); }
.toast { opacity: 0; transform: translateX(24px) scale(.97); pointer-events: none; transition: opacity .25s var(--ease), transform .4s var(--ease); }
.toast.show { opacity: 1; transform: none; }

/* Motion */
@property --beam { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(18px) scale(.96); } }
@keyframes row-in { from { opacity: 0; transform: translateX(-8px); } }
@keyframes grow { from { transform: scaleY(0); } }
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes spin { to { --beam: 360deg; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--ok) 55%, transparent); } 50% { box-shadow: 0 0 0 5px transparent; } }

.topbar { animation: fade .4s backwards; }
.stats .stat { animation: rise .5s var(--ease) backwards; }
.stats .stat:nth-child(2) { animation-delay: .06s; } .stats .stat:nth-child(3) { animation-delay: .12s; }
.charts { animation: rise .5s .16s var(--ease) backwards; }
.tabs { animation: rise .5s .2s var(--ease) backwards; }
.panel { animation: rise .45s var(--ease) backwards; }
#tab-keys { animation-delay: .24s; }
tbody.enter tr { animation: row-in .35s var(--ease) backwards; }
tbody.enter tr:nth-child(2) { animation-delay: .03s; } tbody.enter tr:nth-child(3) { animation-delay: .06s; }
tbody.enter tr:nth-child(4) { animation-delay: .09s; } tbody.enter tr:nth-child(5) { animation-delay: .12s; }
tbody.enter tr:nth-child(n+6) { animation-delay: .15s; }
.login {
  border-color: transparent;
  background: linear-gradient(var(--card), var(--egg)) padding-box,
    conic-gradient(from var(--beam), var(--line) 0 70%, var(--ink) 92%, var(--line) 100%) border-box;
  animation: pop .55s var(--spring) backwards, spin 7s linear infinite;
}


@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* GPU-friendly hints on things that move */
.stat, .login, button, dialog, .toast, button, .stat { backface-visibility: hidden; }
/* theme switch: soft crossfade (View Transitions API) */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .35s; animation-timing-function: var(--ease); }

/* ================================================================= charts */
.charts { display: grid; grid-template-columns: minmax(220px, 300px) 1fr; gap: 28px; padding: 20px 22px; margin-bottom: 14px; }
@media (max-width: 760px) { .charts { grid-template-columns: 1fr; } }
.swatch.line-a, .line-a { --c: var(--ink); }
.swatch.line-b, .line-b { --c: var(--ok); }
.swatch.line-a { background: var(--ink); } .swatch.line-b { background: var(--ok); }

/* donut */
.donut-side { display: grid; gap: 10px; align-content: start; }
.donut-box { position: relative; width: min(190px, 100%); aspect-ratio: 1; margin: 6px auto 4px; }
#donut { width: 100%; height: 100%; overflow: visible; }
#donut circle { fill: none; stroke-width: 11; }
.donut-track { stroke: var(--egg-soft); }
.dseg { stroke-linecap: round; transition: stroke-dasharray 1s var(--ease), opacity .2s, stroke-width .2s; cursor: pointer; }
.dseg.ok { stroke: var(--ok); } .dseg.gold { stroke: var(--warn); } .dseg.dim { stroke: var(--faint); } .dseg.bad { stroke: var(--bad); }
g.hover .dseg:not(.on) { opacity: .3; }
.dseg.on { stroke-width: 14; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center .num { font-size: 30px; }
.donut-center .muted { font-size: 12px; }
.donut-side .legend { justify-content: center; }

/* line / area chart */
.line-side { min-width: 0; display: grid; gap: 8px; align-content: start; }
.chart-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.chart-head select { margin-left: auto; padding: 3px 10px; font-size: 12px; border-radius: 999px; }
.chart-box { position: relative; }
.chart { display: block; width: 100%; height: 190px; touch-action: pan-y; }
.gline { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
.gtext { fill: var(--faint); font-size: 10.5px; }
.line { fill: none; stroke: var(--c); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 0; animation: draw 1.3s var(--ease) backwards; }
.area { opacity: .9; animation: fade 1.2s .2s var(--ease) backwards; }
.fa0 { stop-color: var(--ink); stop-opacity: .22; } .fa1 { stop-color: var(--ink); stop-opacity: 0; }
.fb0 { stop-color: var(--ok); stop-opacity: .20; } .fb1 { stop-color: var(--ok); stop-opacity: 0; }
.cursor { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 3 3; transition: opacity .15s; }
.pt { fill: var(--egg); stroke: var(--c); stroke-width: 2.4; transition: opacity .15s; pointer-events: none; }
.chart-tip {
  position: absolute; z-index: 2; min-width: 150px; padding: 8px 12px; border-radius: 12px; font-size: 12.5px; pointer-events: none;
  background: color-mix(in oklab, var(--card) 88%, transparent); border: 1px solid var(--line); box-shadow: var(--pane-shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); display: grid; gap: 2px;
}
.chart-tip .swatch { margin-right: 7px; }
@keyframes draw { from { stroke-dashoffset: 1; } }

/* ================================================================= roles, vault, admins */
/* Cosmetic only: hiding controls is convenience. The server checks every permission. */
body.role-viewer .needs-admin, body.role-viewer td.actions .needs-admin { display: none !important; }
body:not(.role-owner) .needs-owner { display: none !important; }
body.role-viewer #tab-keys td.actions { display: none; }

.account-btn { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; }
.role-chip { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; background: var(--egg-soft); border: 1px solid var(--line); color: var(--muted); }
body.role-owner .role-chip { color: var(--on-ink); background: var(--ink); border-color: var(--ink); }

.note { margin: -2px 0 12px; font-size: 12.5px; color: var(--faint); line-height: 1.6; }
.grow { flex: 1; margin: 0; align-self: center; }
.section-gap { margin-top: 26px; }
h4 { margin: 6px 0 0; font-size: 13.5px; font-weight: 700; color: var(--ink); }
textarea {
  font: inherit; color: var(--ink); background: var(--egg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 13px; outline: none; resize: vertical; min-height: 64px;
}
textarea:hover { border-color: var(--faint); }
textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in oklab, var(--ink) 12%, transparent); }
.mono, td.value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
td.value { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.masked { letter-spacing: .12em; color: var(--faint); }
.masked .fp { letter-spacing: 0; }
.slot { display: grid; }
label.check { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; color: var(--ink); font-size: 13px; }
label.check input { width: 17px; height: 17px; margin-top: 1px; accent-color: var(--ink); }
label.check input:disabled + span { color: var(--faint); }
td .sub { font-size: 11.5px; font-weight: 400; margin-top: 2px; white-space: normal; }
tr.dimmed td { opacity: .5; }
tr.flag td:nth-child(2) { color: var(--bad); }
.pill.tiny { margin-left: 6px; padding: 0 7px; font-size: 10.5px; }
.history { max-height: 360px; }
dialog:has(.history) { width: min(640px, calc(100vw - 32px)); }
#admin-rows select { padding: 4px 10px; font-size: 12.5px; border-radius: 999px; }
input:disabled, select:disabled { opacity: .5; cursor: not-allowed; }
