/* Mieszkanko — wygląd (wersja zwarta)
   Układ: jedna kolumna (do 760 px), przyklejony pasek z sumą i zakładkami,
   pomieszczenia jako zwijane sekcje, propozycje jako gęsta lista pod elementem. */
:root {
  --bg: #eef0ec;          /* gips */
  --surface: #ffffff;
  --surface-2: #f6f7f4;
  --ink: #1d2320;
  --muted: #646c67;
  --line: #dde0d9;
  --accent: #2f5d50;      /* butelkowa zieleń */
  --accent-ink: #ffffff;
  --accent-soft: #e1ebe6;
  --tape: #f2c94c;        /* taśma malarska — wybrana opcja */
  --tape-soft: #fdf6dc;
  --tape-ink: #3a2f05;
  --danger: #a3362b;
  --danger-soft: #f6e1de;
  --warn: #8a5a00;
  --warn-soft: #f8eed7;

  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --r: 6px;
  --r-sm: 4px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131615; --surface: #1b1f1d; --surface-2: #212624; --ink: #e7eae4; --muted: #9aa39d;
    --line: #2d3330; --accent: #80bca9; --accent-ink: #0f1a16; --accent-soft: #22332d;
    --tape: #e3bb45; --tape-soft: #2c2714; --tape-ink: #241c00; --danger: #ef8f84; --danger-soft: #3a2220;
    --warn: #e7b65a; --warn-soft: #332812;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131615; --surface: #1b1f1d; --surface-2: #212624; --ink: #e7eae4; --muted: #9aa39d;
  --line: #2d3330; --accent: #80bca9; --accent-ink: #0f1a16; --accent-soft: #22332d;
  --tape: #e3bb45; --tape-soft: #2c2714; --tape-ink: #241c00; --danger: #ef8f84; --danger-soft: #3a2220;
  --warn: #e7b65a; --warn-soft: #332812;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--f-body); font-size: 14px; line-height: 1.35;
  font-variant-numeric: tabular-nums;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 30; background: var(--surface);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.num { font-weight: 600; }
.muted { color: var(--muted); }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }

.wrap {
  max-width: 760px; margin: 0 auto;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
}
@media (min-width: 420px) {
  .wrap { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
}

/* --- nagłówek ----------------------------------------------------------- */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.top .wrap { display: grid; gap: 6px; padding-block: 8px 0; }
.brand-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.brand { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.grand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.grand .value { font-size: 17px; font-weight: 600; white-space: nowrap; }
.grand .split { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 2px; margin-bottom: -1px; }
.tabs button {
  border: 0; border-bottom: 2px solid transparent; background: transparent; padding: 6px 10px 7px;
  cursor: pointer; font-size: 14px; font-weight: 500; color: var(--muted); white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.demo-bar { background: var(--warn-soft); color: var(--warn); font-size: 12px; }
.demo-bar .btn.link { color: var(--warn); font-size: 12px; }
.demo-bar .wrap { padding-block: 5px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; justify-content: space-between; }

main .wrap { display: grid; gap: 8px; padding-block: 10px 32px; }

/* --- przyciski ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--r-sm); padding: 4px 10px; cursor: pointer; font-size: 13px; font-weight: 500;
  text-decoration: none; min-height: 30px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); padding-inline: 6px; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 26px; padding: 2px 8px; font-size: 12px; }
.btn.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; font-weight: 400; }
.icon-btn {
  border: 0; background: transparent; width: 28px; height: 28px; border-radius: var(--r-sm);
  display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); flex: none; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }
.btn svg { width: 14px; height: 14px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- pomieszczenie / grupa (sekcja) -------------------------------------- */
.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.section-head { display: flex; align-items: center; gap: 6px; padding: 7px 10px 7px 6px; cursor: pointer; user-select: none; }
.chev { display: inline-grid; place-items: center; color: var(--muted); flex: none; transition: transform .12s ease; }
.chev svg { width: 16px; height: 16px; }
.section[data-open="true"] > .section-head .chev { transform: rotate(90deg); }
.section-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.section-title h2 { margin: 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.section-title .meta { font-size: 12px; color: var(--muted); }
.section-sum { text-align: right; flex: none; line-height: 1.2; }
.section-sum .value { font-size: 15px; font-weight: 600; }
.section-sum .split { font-size: 11px; color: var(--muted); }
.section-body { border-top: 1px solid var(--line); display: grid; }
.section[data-open="false"] .section-body { display: none; }

.sub-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  border-top: 1px solid var(--line);
}
.sub-head .num { text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--ink); }
.section-foot { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 10px 8px; border-top: 1px solid var(--line); background: var(--surface-2); }
.section-foot .spacer { flex: 1; }
.empty { padding: 8px 10px; color: var(--muted); font-size: 13px; }

/* --- element ------------------------------------------------------------ */
.item + .item { border-top: 1px solid var(--line); }
.item-row { display: flex; gap: 8px; align-items: center; padding: 5px 10px 5px 6px; cursor: pointer; min-height: 42px; }
.item-row .chev svg { width: 14px; height: 14px; }
.item[data-open="true"] > .item-row .chev { transform: rotate(90deg); }
.thumb {
  width: 32px; height: 32px; border-radius: var(--r-sm); flex: none; background: var(--surface-2);
  border: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb svg { width: 16px; height: 16px; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 500; overflow-wrap: anywhere; }
.item-sub { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 6px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; font-size: 11px; padding: 0 6px; border-radius: 999px; line-height: 17px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500; white-space: nowrap;
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.room { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); line-height: 15px; }
.item-cost { text-align: right; flex: none; line-height: 1.25; }
.item-cost .value { font-weight: 600; white-space: nowrap; }
.item-cost .range { font-size: 11px; color: var(--muted); white-space: nowrap; }

.item-detail { background: var(--surface-2); border-top: 1px solid var(--line); padding: 4px 10px 6px 34px; display: grid; gap: 4px; }
.item[data-open="false"] .item-detail { display: none; }
.item-notes { font-size: 12px; color: var(--muted); white-space: pre-wrap; padding-top: 2px; }
.item-actions { display: flex; gap: 4px; justify-content: space-between; align-items: center; }

/* --- propozycja --------------------------------------------------------- */
.proposals { display: grid; }
.prop {
  display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 5px 4px; border-bottom: 1px solid var(--line);
}
.prop.noimg { grid-template-columns: auto minmax(0, 1fr) auto; }
.prop[data-chosen="true"] { background: var(--tape-soft); box-shadow: inset 3px 0 0 var(--tape); }
.prop-main { min-width: 0; }
.prop-title { overflow-wrap: anywhere; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.prop-title a { color: var(--ink); text-decoration: none; }
.prop-title a:hover { text-decoration: underline; }
.prop-title svg { color: var(--muted); vertical-align: -1px; }
.prop-meta { font-size: 11px; color: var(--muted); }
.prop-notes { font-size: 11px; color: var(--muted); white-space: pre-wrap; }
.prop-side { text-align: right; display: grid; justify-items: end; line-height: 1.25; }
.prop-price { font-weight: 600; white-space: nowrap; }
.prop-total { font-size: 11px; color: var(--muted); white-space: nowrap; }
.prop-tools { display: flex; margin-right: -4px; }
.prop-tools .icon-btn { width: 24px; height: 24px; }
.prop-tools .icon-btn svg { width: 14px; height: 14px; }
.tag-best { color: var(--accent); font-weight: 600; }

.pick {
  width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--muted); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; padding: 0; flex: none; color: var(--tape-ink);
}
.pick svg { width: 12px; height: 12px; opacity: 0; }
.pick[aria-pressed="true"] { background: var(--tape); border-color: var(--tape); }
.pick[aria-pressed="true"] svg { opacity: 1; }
.pick:hover { border-color: var(--tape); }

/* --- robocizna ---------------------------------------------------------- */
.labor { display: flex; align-items: center; gap: 8px; padding: 3px 6px 3px 10px; }
.labor-desc { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.labor-amt { font-weight: 600; white-space: nowrap; }
.labor .icon-btn { width: 24px; height: 24px; }
.labor .icon-btn svg { width: 14px; height: 14px; }

/* --- podsumowanie ------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: grid; gap: 6px; }
.panel h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel p { margin: 0; }
.table-wrap { overflow-x: auto; }
table.sum { width: 100%; border-collapse: collapse; font-size: 13px; }
table.sum th, table.sum td { padding: 4px 4px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.sum th:first-child, table.sum td:first-child { text-align: left; white-space: normal; padding-left: 0; }
table.sum th:last-child, table.sum td:last-child { padding-right: 0; }
table.sum thead th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 500; }
table.sum td.zero { color: var(--muted); }
table.sum tfoot td { font-weight: 600; border-bottom: 0; border-top: 1.5px solid var(--ink); }
.big-total { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.big-total .value { font-size: 22px; font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar span { display: block; height: 100%; }
.bar .m { background: var(--accent); }
.bar .l { background: var(--tape); }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.todo-list { margin: 0; padding-left: 16px; display: grid; gap: 2px; font-size: 13px; }

/* --- logowanie ---------------------------------------------------------- */
.login { max-width: 400px; margin: 0 auto; padding-block: 40px; display: grid; gap: 14px; }
.login h1 { font-size: 26px; margin: 0; font-weight: 600; letter-spacing: -.02em; }
.login .panel { gap: 10px; }

/* --- formularze / dialog ------------------------------------------------ */
dialog {
  border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(500px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); box-shadow: 0 16px 48px rgb(0 0 0 / .22);
}
dialog::backdrop { background: rgb(15 20 18 / .45); }
#dlg-form { display: grid; gap: 10px; padding: 14px; }
#dlg-form h3 { margin: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
#dlg-form h3 .muted { font-weight: 400; }
.field { display: grid; gap: 2px; min-width: 0; }
.field label { font-size: 12px; font-weight: 500; color: var(--muted); }
.field .hint { font-size: 11px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm);
  padding: 6px 8px; font-size: 16px; min-height: 36px;
}
.field textarea { resize: vertical; min-height: 56px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; }
.row-url { display: flex; gap: 6px; }
.row-url input { flex: 1; }
.row-url .btn { min-height: 36px; }
.fetch-status { font-size: 12px; border-radius: var(--r-sm); padding: 6px 8px; overflow-wrap: anywhere; }
.fetch-status.ok { background: var(--accent-soft); color: var(--accent); }
.fetch-status.err { background: var(--danger-soft); color: var(--danger); }
.fetch-status.busy { background: var(--surface-2); color: var(--muted); }
.img-preview { display: flex; gap: 8px; align-items: center; }
.img-preview .thumb { width: 36px; height: 36px; }

.fold { border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); }
.fold > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 4px; padding: 6px 8px;
  font-size: 13px; user-select: none; min-height: 34px;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold-chev { display: inline-grid; color: var(--muted); transition: transform .12s ease; }
.fold-chev svg { width: 14px; height: 14px; }
.fold[open] .fold-chev { transform: rotate(90deg); }
.fold-label { font-weight: 500; flex: none; }
.fold-sum { color: var(--muted); font-size: 12px; margin-left: auto; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fold-body { display: grid; gap: 8px; padding: 2px 8px 8px; }

.dlg-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.dlg-actions .btn { min-height: 34px; padding-inline: 14px; }
.form-error { color: var(--danger); font-size: 12px; margin: 0; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13px; text-align: center;
  z-index: 50; max-width: calc(100vw - 24px);
}

.foot { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: center; padding-block: 4px 20px; }

@media (max-width: 480px) {
  .grand .split { display: none; }
  .row-3 { grid-template-columns: 1.3fr 1fr 1fr; gap: 6px; }
  .item-detail { padding-left: 10px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.field label.radio { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); font-weight: 400; min-height: 32px; cursor: pointer; }
.field input[type="radio"] { width: 18px; height: 18px; min-height: 0; padding: 0; margin: 0; flex: none; accent-color: var(--accent); }

/* --- załączniki --------------------------------------------------------- */
.atts { display: grid; }
.att { display: flex; align-items: center; gap: 6px; min-height: 30px; padding-left: 2px; }
.att-ico { display: inline-grid; color: var(--muted); flex: none; }
.att-ico svg { width: 15px; height: 15px; }
.att-name {
  border: 0; background: none; padding: 2px 0; cursor: pointer; color: var(--accent); text-align: left;
  font-size: 13px; text-decoration: underline; text-underline-offset: 2px; min-width: 0; overflow-wrap: anywhere;
}
.att-meta { font-size: 11px; color: var(--muted); white-space: nowrap; margin-left: auto; }
.att .icon-btn { width: 24px; height: 24px; }
.att .icon-btn svg { width: 14px; height: 14px; }
.item-detail .atts { border-top: 1px dashed var(--line); padding-top: 4px; }
.labor-wrap .atts { padding: 0 6px 4px 10px; }
.clip { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); }
.clip svg { width: 13px; height: 13px; }
.btn-row { display: flex; gap: 4px; flex-wrap: wrap; }
.drop-hover { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }
