/* Layout: one calm column (max ~56rem), big tap targets, numbered steps in the quote editor.
   Palette borrows from a builder's toolbox: bottle-green primary, spirit-level yellow for the total. */
:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --ink: #18211d;
  --muted: #4d5a53;
  --line: #c9d2cc;
  --accent: #1f5f4a;
  --accent-ink: #ffffff;
  --accent-soft: #e2eee8;
  --level: #f6d55c;
  --level-ink: #2a2306;
  --danger: #a3261b;
  --danger-soft: #fbe9e6;
  --focus: #1b6dd1;

  --font: "Lexend", "Segoe UI", Roboto, Arial, sans-serif;
  --radius: 10px;
  --tap: 3.25rem;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #121714;
  --surface: #1b221e;
  --ink: #eef3ef;
  --muted: #b3c0b8;
  --line: #36423b;
  --accent: #5fbf98;
  --accent-ink: #0d1a14;
  --accent-soft: #223a30;
  --level: #e9c84a;
  --level-ink: #1d1803;
  --danger: #ff8a7d;
  --danger-soft: #3a1f1c;
  --focus: #7db5ff;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.125rem;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: 1.9rem; font-weight: 700; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--accent); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 56rem; margin: 0 auto;
  padding-block: 0.6rem;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem;
}
.brand {
  font-weight: 700; font-size: 1.35rem; color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; gap: 0.5rem;
}
.brand::before {
  content: ""; width: 1.1rem; height: 1.1rem; border-radius: 3px;
  background: var(--level); box-shadow: inset 0 0 0 2px var(--level-ink);
}
.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; flex: 1 1 auto; }
.tabs a {
  display: inline-flex; align-items: center; min-height: 2.9rem;
  padding: 0 1rem; border-radius: 999px;
  color: var(--ink); text-decoration: none; font-weight: 600;
  border: 2px solid transparent;
}
.tabs a:hover { background: var(--accent-soft); }
.tabs a.is-active { background: var(--accent); color: var(--accent-ink); }
.prefs { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.pref-group { display: flex; align-items: center; gap: 0.3rem; }
.pref-label { color: var(--muted); font-size: 0.95rem; }
.pref-group button {
  min-width: 2.75rem; min-height: 2.75rem; padding: 0 0.5rem;
  border: 2px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer;
}
.pref-group button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Page ---------- */
.page {
  max-width: 56rem; margin: 0 auto;
  padding-block: 1.5rem 6rem;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 1.25rem;
}
.page:focus { outline: none; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem;
}
.head-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.back { display: inline-block; margin-bottom: 0.4rem; font-weight: 600; font-size: 1.05rem; }
.lead { color: var(--muted); max-width: 40rem; }
.muted { color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.panel h2 { display: flex; align-items: center; gap: 0.6rem; }
.step-no {
  display: inline-grid; place-items: center;
  width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 1.05rem;
}

.hint {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem;
  background: var(--accent-soft); border-radius: var(--radius); padding: 1rem 1.25rem;
}
.hint p { flex: 1 1 18rem; }

.empty {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 2rem 1.25rem; text-align: center; display: flex; flex-direction: column; gap: 0.5rem;
}
.empty-title { font-size: 1.3rem; font-weight: 700; }
.empty-inline { color: var(--muted); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.lbl { font-weight: 600; font-size: 1rem; color: var(--ink); }

input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line); border-radius: 8px;
  min-height: var(--tap); padding: 0.5rem 0.75rem; width: 100%;
}
textarea { resize: vertical; min-height: 6rem; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid var(--focus); outline-offset: 1px; }
input[inputmode="decimal"], input[inputmode="numeric"] { font-variant-numeric: tabular-nums; }
.search { max-width: 28rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 3rem; padding: 0.5rem 1.1rem;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  border: 2px solid var(--accent); border-radius: 8px;
  background: var(--surface); color: var(--accent);
}
.btn:hover { background: var(--accent-soft); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn-big { min-height: var(--tap); padding: 0.6rem 1.4rem; font-size: 1.1rem; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-danger-outline { border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-soft); }
.file-btn { cursor: pointer; }

.link-btn {
  background: none; border: 0; padding: 0.4rem 0.2rem; min-height: 2.75rem;
  font: inherit; font-weight: 600; color: var(--accent); text-decoration: underline; cursor: pointer;
}
.link-btn.danger { color: var(--danger); }
.link-btn:disabled { color: var(--muted); text-decoration: none; cursor: default; opacity: 0.6; }

.add-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }

/* ---------- Quote list ---------- */
.quote-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.quote-card {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.25rem; color: var(--ink); text-decoration: none;
}
.quote-card:hover { border-color: var(--accent); }
.quote-card-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; flex: 1 1 18rem; }
.quote-card-title { font-weight: 700; font-size: 1.2rem; }
.quote-card-client { overflow-wrap: anywhere; }
.quote-card-meta { color: var(--muted); font-size: 0.95rem; }
.quote-card-sum { font-weight: 700; font-size: 1.3rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Quote items ---------- */
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.item {
  display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: 0.5rem;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
  background: var(--bg);
}
.item-num { font-weight: 700; font-size: 1.2rem; padding-top: 1.9rem; color: var(--muted); }
.item-body { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.item-name { font-weight: 600; }
.item-grid {
  display: grid; grid-template-columns: minmax(10rem, 1.3fr) minmax(6rem, 0.8fr) minmax(7rem, 1fr) minmax(7rem, 1fr);
  gap: 0.75rem; align-items: end;
}
.stepper { display: grid; grid-template-columns: var(--tap) minmax(3rem, 1fr) var(--tap); }
.stepper input { border-radius: 0; text-align: center; border-left: 0; border-right: 0; }
.step {
  min-height: var(--tap); font: inherit; font-size: 1.5rem; font-weight: 700; line-height: 1;
  border: 2px solid var(--line); background: var(--accent-soft); color: var(--ink); cursor: pointer;
}
.step:first-child { border-radius: 8px 0 0 8px; }
.step:last-child { border-radius: 0 8px 8px 0; }
.item-sum output {
  display: flex; align-items: center; min-height: var(--tap);
  font-weight: 700; font-size: 1.2rem; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.item-actions { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; }

/* ---------- Online status in settings ---------- */
.sync-wrap { display: flex; flex-direction: column; gap: 0.75rem; }
.sync-state { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.9rem 1rem; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
.sync-dot { flex: none; width: 0.9rem; height: 0.9rem; margin-top: 0.35rem; border-radius: 50%; background: var(--muted); }
.sync-state.is-on .sync-dot { background: var(--accent); }
.sync-state.is-warn .sync-dot { background: var(--level); box-shadow: 0 0 0 2px var(--level-ink); }
.sync-state strong { display: block; }

/* ---------- Login ---------- */
.login { max-width: 30rem; display: flex; flex-direction: column; gap: 1rem; }
.login-form .btn { width: 100%; }
.check { display: inline-flex; align-items: center; gap: 0.6rem; font-weight: 600; cursor: pointer; min-height: 2.75rem; }
.check input { width: 1.5rem; height: 1.5rem; min-height: 0; accent-color: var(--accent); }
.form-error { color: var(--danger); font-weight: 600; }
.form-error:empty { display: none; }

/* ---------- Clients ---------- */
.client-bar { display: flex; flex-direction: column; gap: 0.6rem; }
.client-linked { color: var(--accent); font-weight: 700; }
.client-suggest { display: flex; flex-direction: column; gap: 0.4rem; }
.client-suggest:empty { display: none; }
.client-suggest .lbl { margin-top: 0.3rem; }
#client-list { gap: 0.5rem; }
.client-item { flex-direction: column; align-items: flex-start; }
.client-item-main { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; overflow-wrap: anywhere; }
.client-item-main span, .client-item-last { color: var(--muted); font-size: 0.95rem; }
.totals-rest dt { color: var(--ink); font-weight: 700; }
.totals-rest dd { font-weight: 700; }

/* ---------- Discounts ---------- */
.before-discount { display: block; font-size: 0.85rem; font-weight: 400; color: var(--muted); }
.item-sum output { flex-direction: column; align-items: flex-start; justify-content: center; }
.item-discount { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 1rem; }
.item-discount .field { width: 14rem; max-width: 100%; }
.discount-box { display: flex; flex-direction: column; gap: 0.75rem; }
.discount-type { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.discount-type legend { padding: 0; margin-bottom: 0.4rem; }
.segmented { display: inline-flex; flex-wrap: wrap; border: 2px solid var(--accent); border-radius: 8px; overflow: hidden; width: fit-content; max-width: 100%; }
.segmented button {
  min-height: 3rem; padding: 0.4rem 1.1rem; font: inherit; font-weight: 700; cursor: pointer;
  background: var(--surface); color: var(--accent); border: 0;
}
.segmented button + button { border-left: 2px solid var(--accent); }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.discount-input { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1rem; }
.discount-input .field { width: 14rem; max-width: 100%; }
.quick { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  min-height: var(--tap); min-width: 4rem; padding: 0.4rem 1rem; font: inherit; font-weight: 700; cursor: pointer;
  border: 2px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.totals-saving { margin-top: 0.6rem; color: var(--accent); font-weight: 700; }

/* ---------- Totals ---------- */
.totals {
  margin: 0; display: flex; flex-direction: column;
  border-top: 2px solid var(--line);
}
.totals-row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.6rem 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.totals-row dt { color: var(--muted); }
.totals-row dd { margin: 0; font-weight: 600; white-space: nowrap; }
.totals-grand {
  background: var(--level); color: var(--level-ink);
  padding: 0.9rem 1rem; margin-top: 0.75rem; border-radius: 8px; border: 0;
  font-size: 1.45rem; font-weight: 700;
}
.totals-grand dt { color: var(--level-ink); }
.totals-grand dd { font-weight: 700; }

.editor-foot { display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* ---------- Price list ---------- */
.cat-head { display: flex; flex-direction: column; gap: 0.3rem; }
.cat-name { font-size: 1.3rem; font-weight: 700; }
.svc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.svc {
  display: grid; grid-template-columns: minmax(0, 1fr) 8rem 9rem auto; gap: 0.75rem; align-items: end;
  padding-bottom: 0.75rem; border-bottom: 1px solid var(--line);
}
.svc-del { align-self: end; }

/* ---------- Dialogs ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--ink);
  width: min(40rem, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);
}
dialog::backdrop { background: rgb(10 20 15 / 0.55); }

.picker[open] { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.picker-head { padding: 1.25rem 1.25rem 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; border-bottom: 1px solid var(--line); }
.picker-added { color: var(--accent); font-weight: 600; min-height: 1.5em; }
.picker-list { overflow-y: auto; padding: 0.75rem 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.picker-group { display: flex; flex-direction: column; gap: 0.4rem; }
.picker-group h3 { color: var(--muted); font-size: 1rem; text-transform: uppercase; letter-spacing: 0.04em; }
.picker-group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.picker-item {
  width: 100%; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.25rem 1rem;
  text-align: left; min-height: var(--tap); padding: 0.6rem 0.9rem;
  font: inherit; color: var(--ink); background: var(--bg);
  border: 2px solid var(--line); border-radius: 8px; cursor: pointer;
}
.picker-item:hover { border-color: var(--accent); }
.picker-item.is-added { border-color: var(--accent); background: var(--accent-soft); }
.picker-item.is-added::after { content: "✓ dodano"; color: var(--accent); font-weight: 700; flex-basis: 100%; }
.picker-price { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.picker-foot { padding: 0.75rem 1.25rem 1.25rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }

.confirm { padding: 1.5rem; }
.confirm p { font-size: 1.2rem; margin-bottom: 1.25rem; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* ---------- Status & toast ---------- */
.save-status {
  position: fixed; z-index: 6;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); color: var(--accent); border: 1px solid var(--line);
  padding: 0.4rem 0.8rem; border-radius: 999px; font-weight: 600; font-size: 0.95rem;
  font-family: inherit; max-width: calc(100vw - 32px); text-align: left;
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.save-status.is-visible { opacity: 1; }
.save-status:not(:disabled) { pointer-events: auto; cursor: pointer; text-decoration: underline; }
.save-status.is-warn { color: var(--level-ink); background: var(--level); border-color: var(--level); }
.save-status.is-error { color: var(--danger); opacity: 1; }
.toast {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
  width: max-content; max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg);
  padding: 0.9rem 1.25rem; border-radius: 10px; font-weight: 600; font-size: 1.1rem;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.3);
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Narrow screens ---------- */
@media (max-width: 720px) {
  .topbar { position: static; }
  .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .svc { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .svc-name { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  h1 { font-size: 1.6rem; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .item { grid-template-columns: minmax(0, 1fr); }
  .item-num { padding-top: 0; }
  .item-grid { grid-template-columns: minmax(0, 1fr); }
  .page-head .btn-big, .editor-foot .btn, .add-row .btn { width: 100%; }
  .head-actions { width: 100%; }
  .pref-label { display: none; }
}

/* ---------- Printout ---------- */
.print { display: none; }

@media print {
  @page { size: A4; margin: 16mm 14mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  body > *:not(.print) { display: none !important; }
  .print { display: block; color: #000; font-family: var(--font); }
  .pr-head { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 1.5rem; }
  .pr-company { line-height: 1.45; }
  .pr-company::first-line { font-weight: 700; }
  .pr-meta { text-align: right; line-height: 1.6; }
  .pr-title { font-size: 18pt; margin-bottom: 0.2rem; }
  .pr-subject { font-size: 13pt; margin-bottom: 1rem; }
  .pr-client { display: flex; gap: 0.75rem; margin-bottom: 1.25rem; line-height: 1.45; }
  .pr-label { font-weight: 700; }
  .pr-table, .pr-totals { width: 100%; border-collapse: collapse; }
  .pr-table th, .pr-table td { border: 1px solid #777; padding: 5px 7px; text-align: left; vertical-align: top; }
  .pr-table th { background: #eee; font-size: 10pt; }
  .pr-table tr { break-inside: avoid; }
  .num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .pr-totals { width: 55%; margin: 0.75rem 0 0 auto; }
  .pr-totals td { padding: 4px 7px; border-bottom: 1px solid #ccc; }
  .pr-grand td { font-weight: 700; font-size: 13pt; border-top: 2px solid #000; border-bottom: 2px solid #000; }
  .pr-words { margin-top: 0.75rem; text-align: right; }
  .pr-saving { margin-top: 0.3rem; text-align: right; font-weight: 700; }
  .pr-small { margin-top: 0.4rem; font-size: 10pt; }
  .pr-notes { margin-top: 1.25rem; }
  .pr-sign { display: flex; justify-content: space-between; gap: 3rem; margin-top: 3.5rem; break-inside: avoid; }
  .pr-sign div { flex: 1; border-top: 1px dotted #000; padding-top: 0.3rem; text-align: center; font-size: 10pt; }
}
