/* =====================================================================
   eargs — bespoke stylesheet (no framework, token-based).
   Light theme is the default; a safe dark theme is applied via
   @media (prefers-color-scheme: dark) purely through CSS variables, so
   every component re-skins itself with zero duplicated selectors.
   All blended tints are precomputed as variables (no color-mix()) so the
   UI renders identically on old and new engines.
   ===================================================================== */

/* --------------------------------------------------------------- tokens */
:root {
  --bg:            #f4f6f8;
  --bg-soft:       #f8fafc;
  --panel:         #ffffff;
  --border:        #e6e9ef;
  --border-strong: #d3dae3;

  --text:          #1a2030;
  --text-2:        #475069;
  --muted:         #6b7280;

  --accent:        #4f46e5;
  --accent-hover:  #4338ca;
  --accent-soft:   #eef2ff;
  --accent-soft-strong: #e0e7ff;
  --accent-ring:   rgba(79,70,229,.20);
  --accent-border: rgba(79,70,229,.30);
  --accent-contrast: #ffffff;

  --ok:      #16a34a; --ok-soft:   #e7f6ec; --ok-text:   #15803d;
  --ok-hover:#15803d; --ok-border: rgba(22,163,74,.34);
  --warn:    #d97706; --warn-soft: #fef4e6; --warn-text: #92400e;
  --warn-border: rgba(217,119,6,.40);
  --bad:     #dc2626; --bad-soft:  #fdecec; --bad-text:  #991b1b;
  --bad-border: rgba(220,38,38,.34);
  --info:    #0284c7; --info-soft: #e5f3fb; --info-text: #075985;
  --info-border: rgba(2,132,199,.32);
  --ok-contrast:   #ffffff;
  --bad-contrast:  #ffffff;

  --radius:      12px;
  --radius-sm:   8px;
  --nav-h:       60px;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow:    0 1px 3px rgba(16,24,40,.09), 0 1px 2px rgba(16,24,40,.05);
  --shadow-lg: 0 10px 28px rgba(16,24,40,.14);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0d1017;
    --bg-soft:       #10151d;
    --panel:         #151a23;
    --border:        #262e3b;
    --border-strong: #343e4f;

    --text:          #e7ebf2;
    --text-2:        #b6bfce;
    --muted:         #8791a3;

    --accent:        #818cf8;
    --accent-hover:  #a5b4fc;
    --accent-soft:   #232a3d;
    --accent-soft-strong: #2b3450;
    --accent-ring:   rgba(129,140,248,.30);
    --accent-border: rgba(129,140,248,.38);
    --accent-contrast: #0d1017;

    --ok:      #4ade80; --ok-soft:   #12241a; --ok-text:   #86efac;
    --ok-hover:#34d073; --ok-border: rgba(74,222,128,.38);
    --warn:    #fbbf24; --warn-soft: #2a2413; --warn-text: #fcd34d;
    --warn-border: rgba(251,191,36,.44);
    --bad:     #f87171; --bad-soft:  #2a1515; --bad-text:  #fca5a5;
    --bad-border: rgba(248,113,113,.40);
    --info:    #38bdf8; --info-soft: #0f2430; --info-text: #7dd3fc;
    --info-border: rgba(56,189,248,.38);
    --ok-contrast:   #06210f;
    --bad-contrast:  #2a0808;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.45);
    --shadow:    0 1px 3px rgba(0,0,0,.55);
    --shadow-lg: 0 12px 30px rgba(0,0,0,.55);
  }
}

/* ------------------------------------------------------------ reset/base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-soft); color: var(--accent-hover); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt8 { margin-top: 8px; }
.num { font-variant-numeric: tabular-nums; }
.legend { line-height: 2.1; margin: 4px 0 0; }

/* ----------------------------------------------------------------- nav */
.nav {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow-sm);
}
.navInner {
  max-width: 1200px; margin: 0 auto; padding: 10px 16px;
  min-height: var(--nav-h);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.navBrand { font-size: 19px; font-weight: 800; color: var(--text); letter-spacing: .3px; }
.navBrand:hover { text-decoration: none; }
.navBrand span { color: var(--accent); }
.navLinks { display: flex; gap: 2px; flex-wrap: wrap; margin-left: auto; }
.navLinks a {
  padding: 7px 13px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 600; transition: background .12s, color .12s;
}
.navLinks a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

/* ---------------------------------------------------------------- footer */
.foot {
  border-top: 1px solid var(--border);
  margin-top: 40px;
  background: var(--panel);
}
.footInner { height: auto; padding: 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.footBrand { font-weight: 800; font-size: 15px; color: var(--text); }
.footBrand span { color: var(--accent); }
.footTag { font-size: 12.5px; }

/* ------------------------------------------------------------ layout */
.container { max-width: 1200px; margin: 0 auto; padding: 22px 16px 20px; }
.grid2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid2 { grid-template-columns: minmax(0,1fr); } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px 18px;
  margin-bottom: 16px;
}
.panel-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: .1px; }
.panel-sub { margin-bottom: 14px; }
.panel h2 { margin: 0 0 12px; font-size: 16px; font-weight: 700; }
.panel h3 {
  margin: 18px 0 8px; font-size: 12px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .6px;
}
.groupTitle { margin: 22px 0 10px; font-size: 15px; font-weight: 700; }
.groupTitle:first-child { margin-top: 0; }

/* --------------------------------------------------------------- forms */
input[type=text], input[type=password], input[type=number], input:not([type]),
select, textarea {
  font: inherit; color: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 11px; background: var(--bg-soft); width: 100%;
  transition: border-color .12s, box-shadow .12s, background .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
  background: var(--panel);
}
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.formRow { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.formRow > div { flex: 1 1 120px; min-width: 120px; }
.formRow .fixed { flex: 0 0 auto; min-width: 0; }

/* --------------------------------------------------------------- buttons */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); text-align: center;
  transition: background .12s, border-color .12s, color .12s, transform .05s, box-shadow .12s;
}
.btn:hover { background: var(--bg-soft); border-color: var(--border-strong); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-success { background: var(--ok); border-color: var(--ok); color: var(--ok-contrast); }
.btn-success:hover { background: var(--ok-hover); border-color: var(--ok-hover); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btnGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }

/* -------------------------------------------------- bespoke viz table */
.vt { width: 100%; }
.vt-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.vt-filter { flex: 1; min-width: 160px; background: var(--bg-soft); }
.vt-filter::placeholder { color: var(--muted); }
.vt-count {
  font-size: 12px; font-weight: 600; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 999px;
}
.vt-scroll {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.vt-nodata { color: var(--muted); text-align: center; padding: 26px 12px !important; font-style: italic; }
.vt-empty { padding: 26px 12px; text-align: center; color: var(--muted); font-style: italic; }
.vt-empty[hidden] { display: none; }

.tbl { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.tbl th, .tbl td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.tbl thead th {
  background: var(--bg-soft);
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 700; white-space: nowrap;
}
.tbl tbody tr { transition: background .08s; }
.tbl tbody tr:hover { background: var(--bg-soft); }
.tbl tbody tr:last-child td { border-bottom: none; }
/* sticky header only inside a scroll frame (page-flow tables scroll with the page) */
.vt-scroll .tbl thead th, .tblWrap .tbl thead th { position: sticky; top: 0; z-index: 3; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td:first-child.num { color: var(--text-2); }
.tbl .pos { color: var(--ok-text); }
.tbl .neg { color: var(--bad); font-weight: 600; }
.al-left { text-align: left !important; }
.al-center { text-align: center !important; }
.al-right { text-align: right !important; }
.tblWrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* --------------------------------------------------------------- lyrics */
.song { scroll-margin-top: calc(var(--nav-h) + 14px); }
.songHead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.songHead h2 { margin: 0; font-size: 20px; font-weight: 700; }
.songLang { color: var(--muted); font-size: 13px; }
.lyrics {
  white-space: pre-wrap; overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13.5px; line-height: 1.7;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 20px; color: var(--text-2);
}
.songNav { display: flex; gap: 6px; flex-wrap: wrap; }
.songNav a {
  background: var(--accent-soft); color: var(--accent);
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  transition: background .12s;
}
.songNav a:hover { background: var(--accent-soft-strong); text-decoration: none; }

/* -------------------------------------------------------------- entries */
.entries-list { display: flex; flex-direction: column; gap: 10px; }
.entry {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px 12px;
  background: var(--panel);
}
.entry-head {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px dashed var(--border);
}
.entry-id { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.entry-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.entry-descr { color: var(--text-2); }
.entry-lines { display: flex; flex-direction: column; gap: 3px; }
.entry-line-row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.entry-line { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-line.credit { text-align: right; }
.line-no { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
@media (max-width: 640px) {
  .entry-line-row { grid-template-columns: 1fr; }
  .entry-line.credit { text-align: left; }
}
.entry-empty { padding: 14px 4px; font-style: italic; }
.entry-actions { margin-left: auto; display: inline-flex; gap: 6px; }
.entry-del {
  background: transparent; border-color: var(--bad-border); color: var(--bad-text);
}
.entry-del:hover { background: var(--bad-soft); border-color: var(--bad); }
.entry-del:disabled { opacity: .5; cursor: progress; }
.entry-edit {
  background: transparent; border-color: var(--accent-border); color: var(--accent);
}
.entry-edit:hover { background: var(--accent-soft); border-color: var(--accent); }

/* entry edit form */
.entry-edit-form { display: flex; flex-direction: column; gap: 2px; }
.ee-lines { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.ee-line-row {
  display: grid; grid-template-columns: minmax(140px, 1fr) 120px 100px auto;
  gap: 6px; align-items: center;
}
.ee-line-row .ee-amt { min-width: 0; }
@media (max-width: 640px) {
  .ee-line-row { grid-template-columns: 1fr 1fr; }
  .ee-line-row .ee-acc { grid-column: 1 / -1; }
}

/* --------------------------------------------------------------- badges */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; line-height: 1.6; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-neutral { background: var(--bg-soft); color: var(--text-2); border-color: var(--border); }
.badge-ok      { background: var(--ok-soft);   color: var(--ok-text);   border-color: var(--ok-border); }
.badge-warn    { background: var(--warn-soft); color: var(--warn-text); border-color: var(--warn-border); }
.badge-bad     { background: var(--bad-soft);  color: var(--bad-text);  border-color: var(--bad-border); }
.badge-info    { background: var(--info-soft); color: var(--info-text); border-color: var(--info-border); }
.badge-accent  { background: var(--accent-soft); color: var(--accent-hover); border-color: var(--accent-border); }

/* ----------------------------------------------------------------- plot */
.plot { margin: 12px 0 4px; }
.plot img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }

/* -------------------------------------------------------- callouts */
.warnBox {
  background: var(--bad-soft); border: 1px solid var(--bad-border);
  color: var(--bad-text); padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 10px;
}
.okBox {
  background: var(--ok-soft); border: 1px solid var(--ok-border);
  color: var(--ok-text); padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 10px;
}

/* ---------------------------------------------------------------- toasts */
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--text); color: var(--bg);
  padding: 11px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 600; max-width: 340px;
  animation: toastIn .18s ease-out;
}
.toast.err { background: var(--bad); color: var(--bad-contrast); }
.toast.ok  { background: var(--ok); color: var(--ok-contrast); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
