/* ==========================================================================
   Kalkulator page — wall-area table calculator
   Loaded only by kalkulator.html (on top of styles.css)
   ========================================================================== */
.calc-section{
  background: var(--c-offwhite);
  padding-block: clamp(2.5rem, 6vw, 4.5rem);
}

.calc-table-wrap{
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 2px;
}
.calc-table{
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.calc-table th,
.calc-table td{
  padding: 0.75rem 0.9rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--c-border);
}
.calc-table thead th{
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--c-text-soft);
  background: var(--c-offwhite-2);
  white-space: nowrap;
}
.calc-table tfoot th,
.calc-table tfoot td{
  border-bottom: 0;
  background: var(--c-charcoal);
  color: var(--c-text-inverse);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  padding-block: 1rem;
}
.calc-table tfoot .calc-total{ color: #6fcf7a; font-size: 1.25rem; }
.calc-table tfoot .calc-total.is-negative{ color: #ff7a66; }

.calc-num{ text-align: right !important; white-space: nowrap; }

/* columns */
.calc-table td:nth-child(1){ width: 22%; }
.calc-table td:nth-child(3){ width: 110px; }
.calc-table td:nth-child(4){ width: 140px; }
.calc-table td:nth-child(5),
.calc-table th:nth-child(5){ width: 48px; padding-inline: 0.4rem; }

/* inputs */
.calc-input{
  width: 100%;
  background: #fff;
  border: 1.5px solid var(--c-border);
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  border-radius: 2px;
  transition: border-color var(--dur-fast) var(--ease);
}
.calc-input:hover{ border-color: var(--c-gray); }
.calc-input:focus{ border-color: var(--c-orange); outline: none; }
.calc-input.is-invalid{ border-color: #b42814; background: rgba(180,40,20,0.04); }
.calc-input--num{ text-align: right; font-variant-numeric: tabular-nums; }

/* dynamic length cells */
.calc-lengths{
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.4rem;
  align-items: flex-start;
}
.calc-lengths .calc-input{ width: 5.25rem; }
.calc-plus{
  width: 2.3rem; height: 2.3rem;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px dashed var(--c-gray);
  color: var(--c-text-soft);
  font-size: 1.2rem; line-height: 1;
  border-radius: 2px;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.calc-plus:hover{ border-color: var(--c-orange); color: var(--c-orange); }
.calc-sum{
  font-size: 0.8rem;
  color: var(--c-text-mute);
  margin-top: 0.35rem;
  font-variant-numeric: tabular-nums;
}

.calc-area{
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  padding-top: 1.15rem !important;
  font-variant-numeric: tabular-nums;
}

.calc-remove{
  width: 2.3rem; height: 2.3rem;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--c-text-mute);
  border-radius: 2px;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.calc-remove:hover{ color: #b42814; background: rgba(180,40,20,0.06); }
.calc-remove svg{ width: 16px; height: 16px; }

.calc-actions{
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: center;
}
.calc-hint{
  font-size: 0.85rem;
  color: var(--c-text-soft);
  max-width: 60ch;
}
.calc-hint kbd{
  font-family: var(--font-body);
  font-size: 0.75rem;
  padding: 0.1em 0.45em;
  border: 1px solid var(--c-concrete);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: #fff;
}

/* group header rows (plafon / razvojna širina / odbici) */
.calc-group-head th{
  background: var(--c-offwhite-2);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--c-text-soft);
  border-top: 2px solid var(--c-concrete);
}
.calc-group-head th span{ text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--c-text-mute); }
.calc-pair-label{
  padding-top: 1.15rem !important;
  font-weight: 600;
  color: var(--c-text-soft);
}
.calc-pair-a, .calc-pair-b{ max-width: 5.25rem; }
.calc-minus-body .calc-area{ color: #b42814; }
/* additions green, reductions red */
.calc-rooms-body .calc-area,
.calc-plafon-body .calc-area{ color: #2f6b2a; }
.calc-btn-minus{
  border-color: var(--c-charcoal);
  color: var(--c-charcoal);
}
.calc-btn-minus:hover{ background: var(--c-charcoal); color: var(--c-text-inverse); }

/* fixed RŠ row: one m² value, added to the total */
.calc-rs-label{
  padding-top: 1.15rem !important;
  font-weight: 600;
  color: var(--c-text-soft);
}
.calc-rs-label span{ font-weight: 400; color: var(--c-text-mute); }
.calc-rs-input{ max-width: 5.25rem; }
.calc-rs-body .calc-area{ color: #2f6b2a; }

/* meta fields above the table: vrsta rada + datum */
.calc-meta{
  display: grid;
  gap: 1rem 1.5rem;
  margin-bottom: 1.5rem;
}
@media (min-width: 640px){
  .calc-meta{ grid-template-columns: minmax(0, 22rem) 12rem; }
}
.calc-meta__field label{
  display: block;
  font-size: 0.85rem; font-weight: 600;
  margin-bottom: 0.45rem;
}
.calc-meta__field label span{ font-weight: 400; color: var(--c-text-mute); }
.calc-meta .calc-input{ padding: 0.7rem 0.85rem; }

.calc-date{ position: relative; display: flex; }
.calc-date .calc-input{ padding-right: 2.9rem; font-variant-numeric: tabular-nums; }
.calc-date__btn{
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 2.7rem;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--c-text-soft);
  transition: color var(--dur-fast) var(--ease);
}
.calc-date__btn:hover{ color: var(--c-orange); }
.calc-date__btn svg{ width: 18px; height: 18px; }
/* native picker stays in the DOM (showPicker needs it rendered) but invisible, anchored under the field */
.calc-date__native{
  position: absolute; left: 0; bottom: 0;
  width: 100%; height: 1px;
  opacity: 0; pointer-events: none; border: 0; padding: 0;
}

/* plafon label: "Plafon [ naziv ]" */
.calc-pair-label--named{ padding-top: 0.75rem !important; }
.calc-pair-named{ display: flex; align-items: center; gap: 0.5rem; }
.calc-pair-named .calc-pair-name{ flex: 1; min-width: 0; width: auto; font-weight: 400; }

/* per-section subtotal rows */
.calc-subtotal th,
.calc-subtotal td{
  background: var(--c-offwhite);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--c-text-soft);
  padding-block: 0.6rem;
}
.calc-subtotal th{ text-align: right; }
.calc-subtotal td.calc-num{
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
  color: #2f6b2a;
  font-variant-numeric: tabular-nums;
}
.calc-subtotal--minus td.calc-num{ color: #b42814; }

/* column labels under each section header — identical to the main thead (Prostorija row) */
.calc-group-head .calc-colhead th{
  background: var(--c-offwhite-2);
  border-top: 2px solid var(--c-concrete);
  border-bottom: 1px solid var(--c-border);
  padding: 0.75rem 0.9rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--c-text-soft);
  white-space: nowrap;
}
.calc-colhead__note{ text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--c-text-mute); }

/* export buttons (Excel / PDF), pushed to the right of the add buttons */
.calc-export{ display: flex; gap: 0.75rem; margin-left: auto; }
.calc-export .btn svg{ width: 16px; height: 16px; }

/* ==========================================================================
   PDF export = print layout (browser "Save as PDF")
   On print, only #calc-print is shown: one combined obračunski list,
   grouped by section (prostorije → plafon → RŠ → odbici), each section listing every flat.
   ========================================================================== */
.calc-print{ display: none; }

@media print{
  @page{ size: A4 portrait; margin: 12mm; }
  html, body{ background: #fff !important; }
  .skip-link, .header, .nav-mobile, .footer, .page-header{ display: none !important; }
  .calc-section{ padding: 0 !important; background: #fff !important; }
  .calc-section .container{ max-width: none; padding: 0; }
  .calc-section .container > :not(.calc-print){ display: none !important; }
  .calc-print{ display: block !important; }
  .calc-print, .calc-print *{ -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* ---- header ---- */
  .ol-head{ margin-bottom: 5mm; }
  .ol-head__top{
    display: flex; justify-content: space-between; align-items: flex-end; gap: 6mm;
    padding-bottom: 3mm; margin-bottom: 3mm;
    border-bottom: 2.5px solid var(--c-charcoal);
  }
  .ol-head__brand .logo__mark{ font-size: 20pt; }
  .ol-head__brand small{ display: block; margin-top: 1mm; font-size: 8pt; color: var(--c-text-soft); }
  .ol-head__title{
    font-family: var(--font-display); font-weight: 800; font-size: 13pt; line-height: 1.15;
    text-transform: uppercase; letter-spacing: 0.04em; text-align: right;
  }
  .ol-info{ width: 100%; border-collapse: collapse; font-size: 9pt; }
  .ol-info th, .ol-info td{ border: 1px solid #bbb; padding: 1.4mm 2mm; text-align: left; }
  .ol-info th{
    width: 22%; background: var(--c-offwhite-2);
    font-size: 7.5pt; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--c-text-soft);
  }
  .ol-info td{ font-weight: 600; }

  /* ---- the list ---- */
  .ol-table{ width: 100%; border-collapse: collapse; font-size: 8.5pt; border: 1px solid #bbb; }
  .ol-table th, .ol-table td{ padding: 1.4mm 2mm; text-align: left; vertical-align: top; border-bottom: 1px solid #ddd; }
  .ol-table tr{ break-inside: avoid; }
  .ol-table .num{ text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .ol-sec th{
    background: var(--c-offwhite-2);
    border-top: 2px solid var(--c-concrete);
    font-size: 7.5pt; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--c-text-soft);
  }
  .ol-sec th.ol-sec__name{ color: var(--c-text); font-size: 8.5pt; }
  .ol-stan td{ font-weight: 800; font-family: var(--font-display); background: #faf9f6; padding-top: 2mm; }
  .ol-stan-sub td{ font-size: 8pt; color: var(--c-text-soft); font-weight: 600; }
  .ol-sec-total td{ background: var(--c-offwhite); font-weight: 700; border-bottom: 1px solid #bbb; }
  .ol-table .is-plus{ color: #2f6b2a; font-weight: 700; }
  .ol-table .is-minus{ color: #b42814; font-weight: 700; }
  .ol-table .muted{ color: var(--c-text-mute); }
  .ol-grand td{
    background: var(--c-charcoal); color: #fff;
    font-family: var(--font-display); font-weight: 800; font-size: 11pt; padding-block: 2.5mm;
  }
  .ol-grand .num{ color: #6fcf7a; }
  .ol-recap{ margin-top: 6mm; }
  .ol-legend{ margin-top: 3mm; font-size: 7.5pt; color: var(--c-text-mute); }

  /* ---- signatures ---- */
  .ol-sign{
    display: grid; grid-template-columns: 1fr auto 1fr; gap: 10mm; align-items: end;
    margin-top: 14mm; break-inside: avoid;
  }
  .ol-sign > div > span{
    display: block; border-top: 1px solid var(--c-text); padding-top: 1.5mm;
    font-size: 8.5pt; text-align: center; color: var(--c-text-soft);
  }
  .ol-sign__mp{ font-size: 9pt; color: var(--c-text-mute); padding-bottom: 1.5mm; }
}

/* ==========================================================================
   Flats (stanovi): one block per flat + grand total
   ========================================================================== */
.calc-stanovi{ display: grid; gap: 2.5rem; }
.calc-stan{
  border-top: 3px solid var(--c-charcoal);
  padding-top: 1.25rem;
}
.calc-stan__head{
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: 1rem;
}
.calc-stan__title{ display: flex; align-items: center; gap: 0.6rem; }
.calc-stan__title span{
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
}
.calc-stan-name{
  width: 12rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  padding: 0.45rem 0.7rem;
}
.calc-stan__remove{
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.85rem; font-weight: 600;
  color: var(--c-text-mute);
  padding: 0.5rem 0.7rem;
  border-radius: 2px;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.calc-stan__remove[hidden]{ display: none; }
.calc-stan__remove svg{ width: 14px; height: 14px; }
.calc-stan__remove:hover{ color: #b42814; background: rgba(180,40,20,0.06); }
.calc-actions--stan{ margin-top: 1rem; }

.calc-grand{
  margin-top: 2.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--c-black);
  color: var(--c-text-inverse);
  padding: 1.1rem 1.25rem;
  border-radius: 2px;
}
.calc-grand[hidden]{ display: none; }
.calc-grand__label{ font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.04em; }
.calc-grand__value{ font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; color: #6fcf7a; font-variant-numeric: tabular-nums; }
.calc-grand__value.is-negative{ color: #ff7a66; }
.calc-actions--global{ margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--c-border); }

/* both action rows share one 3-column grid so the buttons line up:
   [+ prostoriju] [+ plafon] [− odbitak]
   [+ stan]       [Excel]    [PDF]        */
.calc-actions--stan,
.calc-actions--global{
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 15rem));
  gap: 1rem;
  align-items: center;
}
.calc-actions--stan .btn,
.calc-actions--global .btn{ width: 100%; }
.calc-actions--global .calc-export{ display: contents; }
.calc-actions--global .calc-hint{ grid-column: 1 / -1; }
@media (max-width: 640px){
  .calc-actions--stan,
  .calc-actions--global{ grid-template-columns: 1fr; }
}

/* one wall: length input + ×2 / 50% toggles underneath */
.calc-wall{ display: flex; flex-direction: column; gap: 0.25rem; width: 5.25rem; }
.calc-wall__opts{ display: flex; gap: 0.25rem; }
.calc-wall__opt{ flex: 1; position: relative; cursor: pointer; }
.calc-wall__opt input{ position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.calc-wall__opt span{
  display: block;
  text-align: center;
  font-size: 0.7rem; font-weight: 600; line-height: 1.6;
  border: 1px solid var(--c-border);
  border-radius: 2px;
  background: #fff;
  color: var(--c-text-mute);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.calc-wall__opt:hover span{ border-color: var(--c-gray); color: var(--c-text-soft); }
.calc-wall__opt input:checked + span{ background: var(--c-charcoal); border-color: var(--c-charcoal); color: #fff; }
.calc-wall__opt input:focus-visible + span{ outline: 2px solid var(--c-orange); outline-offset: 1px; }
.calc-wall.is-x2 .calc-length,
.calc-wall.is-half .calc-length{ border-color: var(--c-charcoal); }

/* D / P prefix inside a marked wall's input */
.calc-wall{ position: relative; }
.calc-wall.is-x2::before,
.calc-wall.is-half::before{
  position: absolute; left: 0.55rem; top: 0; height: calc(1.1rem + 1.425rem + 3px); /* = wall input height */
  display: flex; align-items: center;
  font-weight: 800; font-size: 0.85rem;
  color: var(--c-orange);
  pointer-events: none;
}
.calc-wall.is-x2::before{ content: "D"; }
.calc-wall.is-half::before{ content: "P"; }

/* ==========================================================================
   Phones (≤640px): the table becomes stacked cards — no sideways scrolling.
   Every row is a white card; each field gets its label from td[data-label].
   ========================================================================== */
@media (max-width: 640px){
  /* 16px inputs: stops iOS Safari zooming in on focus */
  .calc-input{ font-size: 1rem; }
  .calc-wall.is-x2::before,
  .calc-wall.is-half::before{ height: calc(1.1rem + 1.5rem + 3px); }

  .calc-stan__head{ gap: 0.5rem; }
  .calc-stan-name{ width: 6.5rem; }
  .calc-stan__remove{ padding-inline: 0.5rem; white-space: nowrap; }

  .calc-table-wrap{ overflow: visible; background: none; border: 0; }
  .calc-table{ min-width: 0; display: block; font-size: 1rem; }
  .calc-table thead,
  .calc-table tbody,
  .calc-table tfoot,
  .calc-table tr{ display: block; }
  .calc-table th,
  .calc-table td{ display: block; width: auto !important; padding: 0; border: 0; }
  .calc-table td:empty{ display: none; }

  /* section headings: keep only the first column label */
  .calc-table thead th:not(:first-child),
  .calc-colhead th:not(:first-child){ display: none; }
  .calc-table thead th:first-child,
  .calc-group-head .calc-colhead th:first-child{
    padding: 0.7rem 0.9rem;
    background: var(--c-offwhite-2);
    border: 1px solid var(--c-border);
    border-top: 2px solid var(--c-concrete);
    white-space: normal;
  }
  .calc-group-head{ margin-top: 1rem; }

  /* one card per row */
  .calc-rooms-body tr,
  .calc-plafon-body tr,
  .calc-minus-body tr,
  .calc-rs-body tr{
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    align-items: end;
    padding: 0.9rem;
    background: #fff;
    border: 1px solid var(--c-border);
    border-top: 0;
  }
  /* row 1: name + remove */
  .calc-table tr > :first-child{ grid-column: 1 / 3; }
  .calc-table td.calc-del{ grid-column: 3; grid-row: 1; justify-self: end; align-self: start; }
  .calc-remove{ width: 2.75rem; height: 2.75rem; margin: -0.35rem -0.35rem 0 0; }
  /* rooms: walls full width, then visina | površina */
  .calc-rooms-body td:nth-child(2){ grid-column: 1 / -1; }
  .calc-rooms-body td:nth-child(3){ grid-column: 1; }
  .calc-rooms-body td:nth-child(4){ grid-column: 2 / -1; }
  /* plafon / odbici: dužina | širina/visina | m² */
  .calc-pair-label,
  .calc-pair-label--named{ padding-top: 0 !important; align-self: center; }
  .calc-rs-label{ display: none !important; }
  .calc-rs-body td:nth-child(2){ grid-column: 1 / 3; }

  .calc-table td[data-label]::before{
    content: attr(data-label);
    display: block;
    margin-bottom: 0.4rem;
    font-family: var(--font-body);
    font-size: 0.7rem; font-weight: 600;
    letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--c-text-soft);
    text-align: left;
  }
  .calc-table .calc-area{
    padding: 0 0 0.6rem !important;
    font-size: 1.15rem;
  }
  .calc-table .calc-area::before{ text-align: right !important; }
  .calc-pair-a, .calc-pair-b, .calc-rs-input{ max-width: none; }

  /* walls: bigger touch targets */
  .calc-lengths{ gap: 0.6rem 0.5rem; }
  .calc-wall{ width: calc((100% - 1rem) / 3 - 0.95rem); min-width: 4.6rem; }
  .calc-wall__opt span{ font-size: 0.8rem; line-height: 2; }
  .calc-plus{ width: 2.75rem; height: 2.75rem; }

  /* subtotal + total rows: label left, value right */
  .calc-subtotal tr,
  .calc-table tfoot tr{
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: 0.65rem 0.9rem;
    background: var(--c-offwhite);
    border: 1px solid var(--c-border);
    border-top: 0;
  }
  .calc-subtotal th{ text-align: left; }
  .calc-table tfoot{ margin-top: 1rem; }
  .calc-table tfoot tr{ background: var(--c-charcoal); border: 0; padding: 1rem 0.9rem; }

  .calc-grand{ padding: 1rem; }
  .calc-grand__label{ font-size: 0.9rem; }
  .calc-grand__value{ font-size: 1.3rem; white-space: nowrap; }

  /* action buttons: primary full width, secondary pairs side by side */
  .calc-actions--stan,
  .calc-actions--global{ grid-template-columns: 1fr 1fr; gap: 0.75rem; }
  .calc-actions--stan .btn--primary,
  .calc-actions--global .btn--primary{ grid-column: 1 / -1; }
  .calc-actions--stan .btn,
  .calc-actions--global .btn{ padding-inline: 0.75rem; }
  .calc-hint kbd{ white-space: nowrap; }
}
