/* Kainų sekiklis
 * Dizaino idėja: parduotuvės lentynos kainų etiketė. Pagrindinis akcentas yra viena geltona kainos etiketė
 * ties pasirinkta preke; likusi sąsaja rami: plokščios plokštės su plonomis linijomis, jokių šešėlių ir kortelių.
 * Spalvos: grafikų serijos ir būsenos paimtos iš patikrintos (validate_palette) paletės, abiem temoms.
 */

:root {
  color-scheme: light;
  --page: #e8edeb;
  --surface: #fcfcfb;
  --ink: #14211d;
  --ink-2: #44524d;
  --muted: #66736e;
  --hair: #dbe2df;
  --hair-strong: #b9c4bf;
  --grid: #e4e9e7;
  --axis: #c3cbc7;
  --series-1: #2a78d6;
  --crit: #d03b3b;
  --good: #0ca30c;
  --good-text: #006300;
  --bad-text: #b3261e;
  --action: #1c5cab;
  --on-action: #ffffff;
  --tag: #ffd23f;
  --on-tag: #14211d;
  --sel: #e6eff8;
  --alert-bg: #fbeeed;
  --focus: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0e1211;
    --surface: #1a1a19;
    --ink: #eef2f0;
    --ink-2: #bcc7c2;
    --muted: #98a39e;
    --hair: #2c3230;
    --hair-strong: #434b48;
    --grid: #2c2c2a;
    --axis: #383835;
    --series-1: #3987e5;
    --crit: #d03b3b;
    --good: #0ca30c;
    --good-text: #3fcf3f;
    --bad-text: #ff8a85;
    --action: #3987e5;
    --on-action: #06101f;
    --sel: #1f2a36;
    --alert-bg: #2b1a1a;
    --focus: #6da7ec;
    --band-op: .2;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0 0 10px; }
a { color: var(--action); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
.inline { display: inline; margin: 0; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ mygtukai, laukai */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--hair-strong); border-radius: 6px;
  background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--action); border-color: var(--action); color: var(--on-action); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad-text); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--action); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.linkbtn.name { color: var(--ink); font-weight: 600; text-decoration: none; text-align: left; }
.linkbtn.name:hover { text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 26px; line-height: 1; padding: 4px 10px; cursor: pointer; color: var(--ink-2); border-radius: 6px; }
.icon-btn:hover { background: var(--hair); }

input, select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--hair-strong); border-radius: 6px;
  padding: 9px 10px; min-height: 40px;
}
input[type="radio"] { width: auto; min-height: 0; margin: 4px 0 0; accent-color: var(--action); }
input.code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
label { display: grid; gap: 4px; font-weight: 600; }
label .hint { font-weight: 400; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
label.opt { display: flex; gap: 10px; font-weight: 400; align-items: flex-start; }
label.opt strong { font-weight: 600; }

/* ------------------------------------------------------------------- viršus */
.top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1360px; margin: 0 auto; padding: 18px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 22px; letter-spacing: -.01em; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.strip {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  max-width: 1360px; margin: 0 auto 14px; padding: 6px 16px;
}
.stat { padding: 6px 18px; border-left: 1px solid var(--hair-strong); min-width: 0; }
.stat:first-child { border-left: 0; padding-left: 0; }
.stat-label { color: var(--ink-2); font-size: 13px; }
.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; overflow-wrap: anywhere; }
.stat-note { font-size: 12.5px; color: var(--muted); }
.stat-note.warn { color: var(--bad-text); font-weight: 600; }

/* ------------------------------------------------------------------ išdėstymas */
.layout {
  display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 14px;
  max-width: 1360px; margin: 0 auto; padding: 0 16px 40px; align-items: start;
}
.list-pane, .detail {
  background: var(--surface); border: 1px solid var(--hair); border-radius: 8px;
}
.list-pane { overflow: hidden; position: sticky; top: 12px; max-height: calc(100vh - 24px); display: flex; flex-direction: column; }
.list-head { padding: 10px; border-bottom: 1px solid var(--hair); }
.plist { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.plist li + li { border-top: 1px solid var(--hair); }
.plist-empty { padding: 20px 16px; color: var(--muted); }
.detail { padding: 20px 22px 26px; min-height: 360px; }
.detail:focus { outline: none; }
.loading { color: var(--muted); }

/* ------------------------------------------------------------- prekių eilutės */
.prow {
  display: grid; grid-template-columns: 5px minmax(0, 1fr) auto; grid-template-areas: "band main side" "band spark side";
  column-gap: 12px; align-items: center; width: 100%; text-align: left;
  background: none; border: 0; padding: 0; cursor: pointer;
}
.prow:hover { background: var(--sel); }
.prow[aria-current="true"] { background: var(--sel); }
.prow[aria-current="true"] .prow-name { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.prow-band { grid-area: band; align-self: stretch; background: var(--hair-strong); }
.trend-down .prow-band { background: var(--good); }
.trend-up .prow-band { background: var(--bad-text); }
.trend-err .prow-band { background: var(--crit); }
.prow-main { grid-area: main; padding: 12px 0 0; min-width: 0; display: grid; gap: 1px; }
.prow-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; min-width: 0; }
.prow-sub > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-spark { grid-area: spark; padding-bottom: 8px; height: 38px; }
.prow-side { grid-area: side; padding: 12px 14px 8px 0; display: grid; justify-items: end; gap: 2px; align-content: start; }
.prow-price { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.prow.is-off { opacity: .62; }
.tag { font-size: 11.5px; padding: 0 6px; border-radius: 4px; background: var(--hair); color: var(--ink-2); white-space: nowrap; flex: none; }
.tag.err { background: var(--alert-bg); color: var(--bad-text); font-weight: 600; }
.spark { display: block; }
.spark-line { fill: none; stroke: var(--muted); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.prow:hover .spark-dot, .prow[aria-current="true"] .spark-dot { stroke: var(--sel); }

.delta { font-size: 12.5px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.down { color: var(--good-text); }
.delta.up { color: var(--bad-text); }
.delta.flat { color: var(--muted); font-weight: 500; }

/* ------------------------------------------------------------ prekės langas */
.pv-top { margin-bottom: 8px; display: none; }
.pv-head { display: grid; gap: 16px; margin-bottom: 18px; }
.pv-title h2 { font-size: 22px; overflow-wrap: anywhere; }
.pv-title a { font-size: 13.5px; }
.pricetag { display: inline-grid; gap: 6px; justify-items: start; }
.pricetag-price {
  position: relative; background: var(--tag); color: var(--on-tag);
  font-size: clamp(40px, 7vw, 56px); font-weight: 700; letter-spacing: -.02em; line-height: 1.05;
  padding: 10px 24px 10px 40px; clip-path: polygon(20px 0, 100% 0, 100% 100%, 20px 100%, 0 50%);
  font-variant-numeric: tabular-nums;
}
.pricetag-price::before {
  content: ""; position: absolute; left: 22px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px;
  border-radius: 50%; background: var(--surface);
}
.pricetag-note { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; font-size: 13.5px; }
.pt-note { color: var(--ink-2); }
.pv-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.alert { border-left: 4px solid var(--crit); background: var(--alert-bg); padding: 10px 14px; margin: 0 0 16px; border-radius: 0 6px 6px 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 24px; margin: 0 0 8px; }
.fact { padding: 10px 0; border-top: 1px solid var(--hair); }
.fact dt { font-size: 13px; color: var(--ink-2); }
.fact dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.range-row { margin: 16px 0 4px; }

.ov-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.ov-head h2 { font-size: 22px; }
.seg { display: inline-flex; border: 1px solid var(--hair-strong); border-radius: 6px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 7px 12px; cursor: pointer; color: var(--ink-2); min-height: 36px; }
.seg button + button { border-left: 1px solid var(--hair-strong); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); font-weight: 600; }
.empty-state { padding: 28px 0 8px; max-width: 520px; }
.empty-title { font-size: 18px; font-weight: 600; }

.chart-sec { margin-top: 24px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.sec-head h3 { font-size: 16px; }
.sec-note { color: var(--ink-2); font-size: 13.5px; margin: 0 0 6px; }
.chart-host { min-height: 60px; }

/* ----------------------------------------------------------------- lentelės */
.tbl-scroll { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 500; font-size: 13px; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--hair-strong); white-space: nowrap; }
.tbl th.num { text-align: right; }
.tbl td, .tbl tbody th { padding: 9px 10px; border-bottom: 1px solid var(--hair); vertical-align: top; }
.tbl tbody th { font-size: 14px; color: var(--ink); }
.tbl tr.is-off td, .tbl tr.is-off th { opacity: .65; }
.cell-sub { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; }
.st-ok { color: var(--good-text); }
.st-err { color: var(--bad-text); }
.more-row { margin-top: 12px; }
.ch-table { margin-top: 6px; }

/* ----------------------------------------------------------------- grafikai */
.ch-wrap { position: relative; }
.ch-svg { display: block; max-width: 100%; overflow: visible; touch-action: pan-y; }
.ch-svg text { font-family: inherit; }
.ch-grid { stroke: var(--grid); stroke-width: 1; }
.ch-axis { stroke: var(--axis); stroke-width: 1; }
.ch-tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ch-label { fill: var(--ink); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.ch-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch-band { fill: var(--series-1); fill-opacity: var(--band-op, .12); }
.ch-range { stroke: var(--series-1); stroke-opacity: .4; stroke-width: 2; stroke-linecap: round; }
.ch-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.ch-cross { stroke: var(--hair-strong); stroke-width: 1; }
.ch-hit { fill: transparent; cursor: crosshair; }
.ch-hl { fill: var(--series-1); fill-opacity: .09; }
.ch-bar { fill: var(--series-1); }
.ch-bar-err { fill: var(--crit); }
.ch-empty { color: var(--muted); padding: 22px 0; margin: 0; }
.ch-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 4px 0 6px; font-size: 13px; color: var(--ink-2); }
.ch-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.ch-key { display: inline-block; flex: none; }
.k-line { width: 14px; height: 3px; border-radius: 2px; background: var(--series-1); }
.k-band { width: 14px; height: 10px; border-radius: 2px; background: var(--series-1); opacity: .22; }
.k-low, .k-high { width: 14px; height: 2px; background: var(--muted); }
.k-bar { width: 10px; height: 10px; border-radius: 2px; background: var(--series-1); }
.k-err { width: 10px; height: 10px; border-radius: 2px; background: var(--crit); }
.ch-tip {
  position: absolute; z-index: 3; pointer-events: none; min-width: 150px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--hair-strong); border-radius: 6px;
  padding: 8px 11px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(0, 0, 0, .14);
}
.tip-title { font-weight: 600; margin-bottom: 3px; }
.tip-row { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.tip-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.tip-name { color: var(--ink-2); }
.tip-note { margin-top: 5px; color: var(--ink-2); border-top: 1px solid var(--hair); padding-top: 4px; }

/* ------------------------------------------------------------------ dialogai */
dialog.dlg {
  border: 0; border-radius: 8px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(660px, calc(100vw - 20px)); max-height: calc(100vh - 20px);
}
dialog.dlg::backdrop { background: rgba(8, 16, 12, .55); }
dialog.dlg[open] { display: flex; flex-direction: column; }
dialog.dlg form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 12px 20px; border-bottom: 1px solid var(--hair); }
.dlg-head h2 { font-size: 18px; }
.dlg-body { overflow-y: auto; padding: 16px 20px; display: grid; gap: 14px; align-content: start; }
.dlg-body h3 { font-size: 15px; margin-top: 6px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--hair); }
.picker-frame { border: 1px solid var(--hair-strong); border-radius: 6px; overflow: hidden; background: #fff; }
.picker-frame iframe { display: block; width: 100%; height: 420px; border: 0; background: #fff; }
.test-row { display: grid; gap: 8px; justify-items: start; }
#test-result { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
#test-result.ok { color: var(--good-text); font-weight: 600; }
#test-result.err { color: var(--bad-text); font-weight: 600; }
.form-error { margin: 0; color: var(--bad-text); font-weight: 600; }
.copybox { display: grid; gap: 4px; }
.copybox-label { font-size: 13px; color: var(--ink-2); }
.copybox-row { display: flex; gap: 8px; align-items: stretch; }
.copybox-row code { flex: 1; min-width: 0; padding: 8px 10px; background: var(--page); border: 1px solid var(--hair); border-radius: 6px; font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.ok-line { color: var(--good-text); font-weight: 600; }
.warn-line { color: var(--bad-text); font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 100;
  max-width: min(560px, calc(100vw - 24px)); padding: 11px 16px; border-radius: 8px;
  background: var(--ink); color: var(--surface); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
#toast.show { opacity: 1; }
#toast.ok::before { content: "✓ "; }
#toast.err::before { content: "⚠ "; }

/* --------------------------------------------------------------- prisijungimas */
.auth-body { display: grid; place-items: start center; min-height: 100vh; padding: 8vh 16px 24px; }
.auth { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--hair); border-radius: 8px; padding: 26px 26px 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.auth h1 { font-size: 22px; margin-bottom: 10px; }
.auth-lead { color: var(--ink-2); }
.auth-form { display: grid; gap: 14px; margin-top: 14px; }
.auth-error { color: var(--bad-text); font-weight: 600; }

/* ---------------------------------------------------------------- siauri ekranai */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .list-pane { position: static; max-height: none; }
  .plist { max-height: 46vh; }
  .strip { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 8px; }
  .stat:nth-child(odd) { border-left: 0; padding-left: 0; }
  .pv-top { display: block; }
  .detail { padding: 16px 14px 22px; }
}
@media (max-width: 520px) {
  .top { padding-top: 14px; }
  .top-actions .btn { flex: 1 1 auto; }
  .pv-actions .btn { flex: 1 1 calc(50% - 8px); }
  .ch-tip { min-width: 130px; }
  .dlg-foot .btn { flex: 1; }
  .copybox-row { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
