:root {
  --bg: #f5f2ee;
  --card: #ffffff;
  --text: #221d18;
  --muted: #7a7168;
  --border: #e8e2da;
  --field: #faf8f5;
  --accent: #b5532f;
  --accent-soft: #f6e6de;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 8px 24px rgba(60, 40, 20, .06);
  --radius: 16px;
  color-scheme: light;
}

/* tamna tema je zadana; svijetla se bira prekidačem */
:root[data-theme="dark"] {
  --bg: #171412;
  --card: #211d1a;
  --text: #f1ebe4;
  --muted: #a39a90;
  --border: #36302b;
  --field: #1a1715;
  --accent: #e0774f;
  --accent-soft: #3a261d;
  --accent-text: #1a1310;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 20px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-weight: 400; }
small { font-size: 12px; }

.screen { max-width: 1120px; margin: 0 auto; padding: 24px 16px 48px; }

/* ---------- header ---------- */
.top {
  display: flex; flex-wrap: wrap; gap: 16px;
  align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 0; font-size: 13px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--accent); display: grid; place-items: center; flex: none;
}
.logo svg { width: 26px; height: 26px; fill: none; stroke: var(--accent-text); stroke-width: 2.4; stroke-linejoin: round; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.project {
  min-width: 0; width: 240px; max-width: 100%;
}

/* ---------- controls ---------- */
input, select, button { font: inherit; color: inherit; }

input[type="text"], input[type="number"], select {
  width: 100%; height: 40px; padding: 0 12px;
  background: var(--field); border: 1px solid var(--border); border-radius: 10px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a7168' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
}
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }

.btn-ghost {
  border: 1px dashed var(--border); background: transparent; color: var(--accent);
  border-radius: 10px; height: 36px; padding: 0 12px; cursor: pointer; font-weight: 500; font-size: 14px;
}
.btn-ghost:hover { border-color: var(--accent); background: var(--accent-soft); }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 500; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 40px; height: 24px; border-radius: 99px; background: var(--border); position: relative; transition: background .2s; }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; }
.check.big { color: var(--text); font-weight: 500; font-size: 15px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }

.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .sun { display: none; }
:root[data-theme="dark"] .icon-btn .sun { display: block; }
:root[data-theme="dark"] .icon-btn .moon { display: none; }

.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--field); border: 1px solid var(--border); border-radius: 12px;
}
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 7px 10px; border-radius: 9px;
  font-size: 14px; font-weight: 500; color: var(--muted); transition: all .15s;
}
.seg input:checked + span { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px;
}
.card-head { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.num-badge {
  width: 26px; height: 26px; border-radius: 8px; display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 700;
}

.cols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 28px; align-items: start; }

.form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 500; }
.hint { margin: -8px 0 0; font-size: 13px; color: var(--muted); }

.iu { position: relative; }
.iu input { padding-right: 58px; }
.iu em {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-style: normal; font-size: 13px; color: var(--muted); pointer-events: none;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.group[hidden], .field[hidden] { display: none; }

.list-block { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.list-block > * { width: 100%; }
.list-block > .btn-ghost { width: auto; }
.list-title { font-size: 13px; font-weight: 600; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-head, .list-row { display: grid; gap: 8px; align-items: center; }
.list-cols-3 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) 32px; }
.list-cols-4 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, .7fr) 32px; }
.list-head { font-size: 12px; color: var(--muted); }
.list-row .iu input { padding-right: 28px; }
.list-row .iu em { right: 10px; }
.x {
  width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}
.x:hover { background: var(--accent-soft); color: var(--accent); }

.adv { border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; }
.adv summary { cursor: pointer; padding: 11px 0; font-size: 14px; font-weight: 500; color: var(--muted); list-style: none; }
.adv summary::-webkit-details-marker { display: none; }
.adv summary::before { content: "›"; display: inline-block; margin-right: 8px; transition: transform .2s; }
.adv[open] summary::before { transform: rotate(90deg); }
.adv[open] { padding-bottom: 14px; }

.shapes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.shape {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px 10px; border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; font-size: 13px; font-weight: 500; background: var(--field); transition: all .15s;
}
.shape input { position: absolute; opacity: 0; pointer-events: none; }
.shape svg { width: 44px; height: 34px; fill: var(--accent-soft); stroke: var(--muted); stroke-width: 1.8; stroke-linejoin: round; }
.shape:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.shape:has(input:checked) svg { stroke: var(--accent); fill: var(--card); }
.shape:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--accent-soft); }

.prices { display: flex; flex-direction: column; gap: 10px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------- results ---------- */
.result {
  position: sticky; top: 16px;
  background: var(--field); border: 1px solid var(--border); border-radius: 14px; padding: 20px;
}
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat.main { grid-column: 1 / -1; background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.stat .label { font-size: 12px; opacity: .8; }
.stat .value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat.main .value { font-size: 32px; }
.stat .unit { font-size: 14px; font-weight: 500; opacity: .85; margin-left: 4px; }

.facts { margin: 0 0 16px; display: grid; grid-template-columns: auto auto; gap: 4px 12px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--border); }
.tbl td { padding: 9px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th + th, .tbl td + td { padding-left: 10px; }
.tbl .n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .sub { display: block; font-size: 12px; color: var(--muted); }
.tbl tfoot td { border-bottom: 0; font-weight: 700; padding-top: 12px; }
.empty { color: var(--muted); font-size: 14px; margin: 0; }

.total-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 24px; margin-bottom: 20px; border-top: 0;
}
.total-bar .value { font-size: 26px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

.disclaimer { font-size: 13px; color: var(--muted); text-align: center; max-width: 640px; margin: 8px auto 0; }

body.no-prices .prices,
body.no-prices .price { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .cols { grid-template-columns: 1fr; }
  .result { position: static; }
}
@media (max-width: 560px) {
  .card { padding: 18px 16px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { width: 100%; }
  .project { flex: 1 1 100%; width: auto; }
  .list-head { display: none; }
  .list-cols-3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 32px; }
  .list-cols-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, .8fr) 32px; }
  .list-row > input[type="text"] { grid-column: 1 / -1; }
  .list-row .iu input { height: 48px; padding-top: 16px; }
  .list-row .iu::before { content: attr(data-l); position: absolute; left: 12px; top: 6px; font-size: 11px; color: var(--muted); pointer-events: none; }
  .list-row + .list-row { padding-top: 10px; border-top: 1px solid var(--border); }
}

/* ---------- print ---------- */
#print-view { display: none; }

@media print {
  :root, :root[data-theme] {
    --bg: #fff; --card: #fff; --text: #000; --muted: #666; --border: #ddd; --field: #fff;
    --accent: #b5532f; --accent-soft: #f6e6de; --accent-text: #fff;
    color-scheme: light;
  }
  @page { size: A4; margin: 16mm 14mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .screen { display: none; }
  #print-view { display: block; }
}

.pv-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #b5532f; padding-bottom: 8px; margin-bottom: 18px; }
.pv-head h1 { font-size: 18pt; }
.pv-head .meta { text-align: right; font-size: 10pt; color: #555; }
.pv-sec { margin-bottom: 20px; break-inside: avoid; }
.pv-sec h2 { font-size: 13pt; margin-bottom: 8px; }
.pv-inputs { font-size: 9.5pt; color: #444; margin: 0 0 10px; line-height: 1.6; }
.pv-sec .tbl { font-size: 10pt; }
.pv-sec .tbl th, .pv-sec .tbl td { border-bottom-color: #ddd; }
.pv-sec .tbl .sub { color: #666; }
.pv-total { display: flex; justify-content: space-between; font-size: 13pt; font-weight: 700; border-top: 2px solid #000; padding-top: 8px; }
.pv-note { margin-top: 24px; font-size: 8.5pt; color: #666; }
