:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0efe8;
  --text: #1d2130;
  --muted: #646a7a;
  --line: #dedcd2;
  --blue: #1546a0;
  --blue-soft: #e5ecfa;
  --yellow: #ffd23f;
  --yellow-soft: #fff6d6;
  --green: #1d7a4d;
  --green-soft: #e3f4ea;
  --red: #b42318;
  --red-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(20 24 40 / 6%), 0 4px 16px rgb(20 24 40 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d;
    --surface: #1c1f28;
    --surface-2: #252935;
    --text: #eceef3;
    --muted: #a0a6b6;
    --line: #333849;
    --blue: #7ea6ff;
    --blue-soft: #1f2b47;
    --yellow-soft: #3a3217;
    --green: #6fd39f;
    --green-soft: #183326;
    --red: #ff8a80;
    --red-soft: #3b1d1b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--blue); }
code { font-size: 0.9em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 6px; word-break: break-all; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.6rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
[hidden] { display: none !important; }

/* ── шапка ─────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 3px solid var(--yellow);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--text); text-decoration: none; font-weight: 700; }
.brand-mark {
  display: grid; place-items: center;
  width: 2rem; height: 2rem; border-radius: 9px;
  background: var(--blue); color: var(--yellow); font-weight: 800;
}
.topbar-right { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; justify-content: flex-end; }
.link-muted { color: var(--muted); font-size: 0.9rem; }
.badge { font-size: 0.75rem; font-weight: 700; padding: 0.2rem 0.55rem; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-dry { background: var(--yellow); color: #3b2f00; }
.badge-demo { background: var(--blue-soft); color: var(--blue); }

/* ── сітка сторінки ────────────────────────────────── */

.page { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: auto auto 1fr;
  grid-template-areas:
    "add summary"
    "add pending"
    "add side";
  align-items: start;
}
.layout .add { grid-area: add; }
.layout .summary { grid-area: summary; }
.layout .pending { grid-area: pending; }
.layout .side { grid-area: side; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "summary" "add" "pending" "side"; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.card-head h2 { margin: 0; }

/* ── форми ─────────────────────────────────────────── */

label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.875rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0.6rem 0.7rem; min-height: 2.75rem; width: 100%;
}
input:focus, select:focus, .dropzone:focus-visible, .btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--blue) 35%, transparent);
  outline-offset: 1px; border-color: var(--blue);
}
select.needs-choice { border-color: #c98a00; background: var(--yellow-soft); }

.grid-2, .grid-3, .grid-name { display: grid; gap: 0.75rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 1rem 0; }
.grid-name { grid-template-columns: minmax(0, 1fr) 9rem; }
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-name { grid-template-columns: minmax(0, 1fr); }
}
.stack { display: grid; gap: 0.75rem; max-width: 640px; }
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.inline-form input[type=file] { width: auto; min-height: 0; border: 0; padding: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600; text-decoration: none;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  padding: 0.6rem 1rem; min-height: 2.75rem; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled, .btn.disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--blue) 88%, black); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0d1430; } }
.btn-ghost { background: transparent; }
.btn-small { min-height: 2.25rem; padding: 0.35rem 0.7rem; font-size: 0.875rem; }
.btn-wide { width: 100%; margin-top: 1rem; font-size: 1.05rem; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; margin-bottom: 1rem; }
.seg { font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 0.45rem 1rem; border-radius: 9px; cursor: pointer; min-height: 2.5rem; }
.seg.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ── зона чека ─────────────────────────────────────── */

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 1.25rem; cursor: pointer; background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--blue); background: var(--blue-soft); }
.dz-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.2rem; padding: 1.25rem 0; }
.dz-preview { display: flex; gap: 1rem; align-items: center; }
.dz-info { display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem; min-width: 0; }
.dz-info strong { word-break: break-all; }
.thumb { width: 7rem; height: 9rem; flex: none; border-radius: 10px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; }
.thumb img, .thumb object { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.pdf-badge { font-weight: 800; color: var(--red); letter-spacing: 0.05em; }

/* ── позиції ───────────────────────────────────────── */

.item {
  position: relative;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.9rem 1rem 1rem; margin: 0 0 0.75rem;
  display: grid; gap: 0.6rem;
}
.item legend { font-weight: 700; padding: 0 0.35rem; }
.item-remove { position: absolute; top: 0.35rem; right: 0.5rem; }
.i-examples { margin: -0.2rem 0 0; min-height: 1.2em; }
.item-more summary { cursor: pointer; color: var(--muted); font-size: 0.875rem; margin-bottom: 0.5rem; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; padding: 0.75rem 0; border-top: 1px solid var(--line); margin-top: 0.75rem; }
.total-row strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.file-name-row { display: grid; gap: 0.35rem; }

/* ── повідомлення ──────────────────────────────────── */

.alert { border-radius: 10px; padding: 0.6rem 0.8rem; margin: 0.75rem 0 0; font-size: 0.95rem; }
.alert-info { background: var(--blue-soft); }
.alert-warn { background: var(--yellow-soft); border-left: 4px solid #e0a800; }
.alert-error { background: var(--red-soft); color: var(--red); }
.alert-ok { background: var(--green-soft); color: var(--green); font-weight: 600; }
.error-list { color: var(--red); }
.warn-list { color: #8a6100; }
@media (prefers-color-scheme: dark) { .warn-list { color: #f3c969; } }

.result { margin-top: 1rem; border-radius: var(--radius); padding: 1rem; }
.result h3 { margin-bottom: 0.4rem; }
.result-ok { background: var(--green-soft); }
.result-ok h3 { color: var(--green); }
.result-dry { background: var(--yellow-soft); }
.result-error { background: var(--red-soft); }
.result-error h3 { color: var(--red); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── підсумок ──────────────────────────────────────── */

.summary select { width: auto; min-height: 2.4rem; padding: 0.3rem 0.6rem; }
.deadline { margin-bottom: 0.9rem; }
.deadline-pill { display: inline-block; background: var(--blue-soft); color: var(--blue); border-radius: 999px; padding: 0.3rem 0.75rem; font-size: 0.875rem; font-weight: 600; }
.deadline-pill.urgent { background: var(--yellow); color: #3b2f00; }
.numbers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
.numbers div { display: flex; flex-direction: column; }
.numbers .label { font-size: 0.8rem; color: var(--muted); }
.numbers strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.numbers strong.negative { color: var(--red); }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 0.8rem 0 0.4rem; }
.meter div { height: 100%; width: 0; background: var(--blue); border-radius: 999px; transition: width 0.3s; }
.meter div.over { background: var(--red); }
.by-category summary { cursor: pointer; font-size: 0.9rem; font-weight: 600; }
.by-category ul { list-style: none; padding: 0; margin: 0.5rem 0 0; display: grid; gap: 0.4rem; }
.by-category li { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.85rem; }
.by-category li strong { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ── чеки, яких бракує ─────────────────────────────── */

.pending-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem; align-items: center; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.pending-row:last-child { border-bottom: 0; }
.pending-text { display: flex; flex-direction: column; min-width: 0; }
.pending-form { grid-column: 1 / -1; display: grid; gap: 0.5rem; }
.pending-form input[type=file] { border: 0; padding: 0; min-height: 0; }

/* ── бокова колонка ───────────────────────────────── */

.side details + details { margin-top: 0.75rem; }
.side summary { cursor: pointer; font-weight: 600; }
.rules { padding-left: 1.1rem; font-size: 0.9rem; }
.log { list-style: none; padding: 0; margin: 0.5rem 0 0; font-size: 0.85rem; display: grid; gap: 0.35rem; max-height: 18rem; overflow-y: auto; }

/* ── майстер ───────────────────────────────────────── */

.steps { list-style: none; padding: 0; margin: 1.25rem 0; display: grid; gap: 1rem; }
.step { border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.step.done { border-left-color: var(--green); }
.step.locked { opacity: 0.6; }
.step h2 { margin-bottom: 0.4rem; }

dialog { border: 0; border-radius: var(--radius); padding: 1.25rem; max-width: min(520px, calc(100vw - 2rem)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 25%); }
dialog::backdrop { background: rgb(10 14 30 / 45%); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
