:root {
  color-scheme: light;
  --page: #f5f5f2; --surface: #fcfcfb; --surface2: #f0efec; --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,0.10); --hover: rgba(11,11,11,0.04);
  --accent: #2a78d6; --accent-ink: #ffffff;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --good: #006300; --warn-bg: #fff4d6; --warn-ink: #7a5300; --bad: #d03b3b; --bad-bg: #fde8e8;
  --shadow: 0 6px 24px rgba(0,0,0,.10);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface2: #262624; --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10); --hover: rgba(255,255,255,0.05);
    --accent: #3987e5; --accent-ink: #ffffff;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --good: #0ca30c; --warn-bg: #3a2e10; --warn-ink: #f5c95c; --bad: #e66767; --bad-bg: #3a1c1c;
    --shadow: 0 6px 24px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface2: #262624; --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10); --hover: rgba(255,255,255,0.05);
  --accent: #3987e5; --accent-ink: #ffffff;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --good: #0ca30c; --warn-bg: #3a2e10; --warn-ink: #f5c95c; --bad: #e66767; --bad-bg: #3a1c1c;
  --shadow: 0 6px 24px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }

.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 17px; padding: 4px 10px 16px; letter-spacing: .2px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink2); font-weight: 500; }
.nav a:hover { background: var(--hover); text-decoration: none; }
.nav a.on { background: var(--surface2); color: var(--ink); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.side-foot { margin-top: auto; padding: 10px; color: var(--muted); font-size: 12px; }

.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 18px; margin: 0; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view { padding: 20px 24px 48px; max-width: 1280px; }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.iconbtn { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; line-height: 0; }
.iconbtn:hover { background: var(--hover); color: var(--ink); }

input[type=text], input[type=search], input[type=email], input[type=tel], input[type=number], input[type=date], select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink2); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.small { font-size: 12.5px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.tile { padding: 14px 16px; }
.tile .l { color: var(--ink2); font-size: 13px; }
.tile .v { font-size: 25px; font-weight: 650; margin-top: 2px; }
.tile .d { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.up { color: var(--good); } .down { color: var(--bad); }
.card { padding: 16px 18px; margin-bottom: 16px; }
.card h2 { font-size: 15.5px; margin: 0 0 4px; font-weight: 600; }
.card .note { color: var(--ink2); font-size: 13px; margin: 0 0 10px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; flex: 1; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 16px; }

table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th, .t td { padding: 8px 8px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: middle; }
.t th { color: var(--ink2); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.t th.num, .t td.num { text-align: right; }
.t tbody tr.click { cursor: pointer; }
.t tbody tr.click:hover { background: var(--hover); }
.t tr.me td { background: var(--hover); font-weight: 600; }
.t tfoot td { font-weight: 650; border-bottom: none; }
.tablewrap { overflow-x: auto; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface2); color: var(--ink2); white-space: nowrap; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.demo { background: transparent; border: 1px dashed var(--axis); color: var(--muted); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; font-size: 11.5px; font-weight: 650; background: var(--bad); color: #fff; text-align: center; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.av { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; font-size: 11px; font-weight: 700; color: #fff; flex: none; }

.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink2); margin-bottom: 6px; flex-wrap: wrap; }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
svg.chart .gl { stroke: var(--grid); stroke-width: 1; }
svg.chart .base { stroke: var(--axis); stroke-width: 1; }
svg.chart .hit { fill: transparent; }
svg.chart .hit:hover { fill: var(--hover); }

#tip { position: fixed; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: var(--shadow); display: none; z-index: 50; min-width: 180px; }
#tip b { display: block; margin-bottom: 4px; }
#tip .r { display: flex; justify-content: space-between; gap: 14px; color: var(--ink2); }
#tip .r span:last-child { color: var(--ink); font-variant-numeric: tabular-nums; }

/* Kliento kortelė */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.list li:last-child { border-bottom: 0; }
.list .grow { min-width: 0; }
.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.act-type { font-size: 12px; color: var(--muted); }

/* Pipeline */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface2); border-radius: 12px; padding: 10px; min-height: 240px; display: flex; flex-direction: column; gap: 8px; }
.col.over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.col-h { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 6px; }
.col-h b { font-size: 13.5px; }
.col-h span { font-size: 12.5px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.dcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px; cursor: grab; }
.dcard:hover { box-shadow: var(--shadow); }
.dcard.dragging { opacity: .5; }
.dcard .t1 { font-weight: 600; font-size: 13.5px; }
.dcard .t2 { font-size: 12.5px; color: var(--ink2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dcard .t3 { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; font-size: 12.5px; }

/* Užduotys */
.task { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--grid); }
.task:last-child { border-bottom: 0; }
.task input[type=checkbox] { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.task.done .tt { text-decoration: line-through; color: var(--muted); }
.task .tt { font-weight: 500; }
.task .ts { font-size: 12.5px; color: var(--ink2); }
.sec-h { font-size: 13px; font-weight: 650; color: var(--ink2); margin: 14px 0 2px; text-transform: none; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; z-index: 40; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 480px; padding: 18px 20px; }
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--ink2); }
.form label > * { width: 100%; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal .actions .left { margin-right: auto; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; font-size: 13px; color: var(--ink2); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page); padding: 9px 16px; border-radius: 10px; font-size: 13.5px; z-index: 60; box-shadow: var(--shadow); }

.login-bg { position: fixed; inset: 0; background: var(--page); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.login { width: 100%; max-width: 340px; padding: 24px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 12px; gap: 2px; }
  .brand { padding: 0 10px 0 4px; font-size: 15px; }
  .brand small, .side-foot { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 6px 9px; white-space: nowrap; }
  .top { padding: 10px 16px; position: static; }
  .view { padding: 16px 16px 40px; }
  .cols { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
}
