:root {
  --teal: #00DDBB; --teal-dark: #00A88E; --teal-soft: #E3FBF6;
  --grey: #4A4A4A; --grey-2: #6B6B6B; --line: #E4E7EA; --bg: #F5F7F8; --card: #FFFFFF;
  --green: #12A150; --green-bg: #E6F6EC; --yellow: #B7791F; --yellow-bg: #FFF6DB; --red: #D93A3A; --red-bg: #FDECEC;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--grey);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.45rem; line-height: 1.2; margin: 0 0 .35rem; color: var(--grey); }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; color: var(--grey); }
a { color: var(--teal-dark); }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: .55rem 1rem; padding-top: calc(.55rem + env(safe-area-inset-top));
  background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-bottom: 3px solid var(--teal);
}
.brand img { display: block; height: 36px; width: auto; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

/* Layout (mobile first) */
.layout { max-width: 1120px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; grid-template-columns: minmax(0,1fr); }
.intro .tagline { margin: 0; color: var(--grey-2); }
.col-inputs { display: grid; gap: 1rem; min-width: 0; }
.col-results { min-width: 0; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; padding: 1.5rem; gap: 1.25rem; }
  .intro, .col-full { grid-column: 1 / -1; }
  .col-results { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; border-radius: var(--radius); }
  .topbar { padding-left: max(1.5rem, calc((100% - 1120px) / 2 + 1.5rem)); padding-right: max(1.5rem, calc((100% - 1120px) / 2 + 1.5rem)); }
  h1 { font-size: 1.8rem; }
  body { padding-bottom: 0; }
}

/* Cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; border: 1px solid var(--line); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.label { font-weight: 600; margin-bottom: .5rem; }
.hint { display: block; color: var(--grey-2); font-size: .8rem; margin-top: .35rem; }
.empty { color: var(--grey-2); margin: .25rem 0; }

/* Fields */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .75rem; }
.field { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 600; margin-bottom: .75rem; min-width: 0; }
.grid2 .field { margin-bottom: 0; }
.grid2 + .field, .field + .grid2, .grid2 + .grid2 { margin-top: .75rem; }
input[type=number], input[type=text] {
  width: 100%; min-width: 0; font: inherit; font-size: 1.05rem; font-weight: 500; color: var(--grey);
  padding: .65rem .75rem; border: 1.5px solid var(--line); border-radius: 10px; background: #FBFCFC;
  -moz-appearance: textfield; appearance: textfield;
}
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,221,187,.2); background: #fff; }
input.example { background: var(--yellow-bg); }
.input-with-toggle { display: flex; flex-wrap: wrap; gap: .5rem; align-items: stretch; }
.input-with-toggle input { flex: 1 1 130px; }

/* Segmented controls */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: #EEF1F2; padding: 4px; border-radius: 12px; }
.seg {
  font: inherit; font-weight: 600; font-size: .92rem; color: var(--grey); background: transparent; border: 0; border-radius: 9px;
  padding: .55rem .4rem; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15;
}
.seg small { font-weight: 500; font-size: .7rem; color: var(--grey-2); margin-top: 2px; }
.seg.active { background: #fff; color: #111; box-shadow: 0 1px 3px rgba(0,0,0,.12); outline: 2px solid var(--teal); }
.segmented.small { flex: 0 0 auto; grid-auto-columns: auto; }
.segmented.small .seg { font-size: .78rem; padding: .35rem .55rem; white-space: nowrap; }

/* Buttons */
.btn { font: inherit; font-weight: 700; border-radius: 10px; border: 1.5px solid transparent; padding: .7rem 1rem; cursor: pointer; }
.btn-sm { font-size: .82rem; padding: .4rem .7rem; }
.btn-primary { background: var(--teal); color: #08352E; }
.btn-primary:active { background: var(--teal-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--grey); }
.btn-ghost.danger { color: var(--red); }
.btn-lang { background: var(--grey); color: #fff; font-size: .85rem; padding: .4rem .75rem; min-width: 48px; }
.row-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.banner { margin-top: .75rem; background: var(--yellow-bg); border: 1px solid #F0D68A; color: #6B4E00; border-radius: 10px; padding: .6rem .75rem; font-size: .85rem; }

/* Fixed costs */
details.card > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
details.card > summary::-webkit-details-marker { display: none; }
.sum-title { font-weight: 700; font-size: 1.05rem; }
.sum-title .hint { font-weight: 500; }
.sum-value { font-weight: 700; color: var(--teal-dark); white-space: nowrap; }
.sum-value::after { content: " ▾"; color: var(--grey-2); }
details[open] .sum-value::after { content: " ▴"; }
.fixed-grid { margin-top: 1rem; margin-bottom: .75rem; }
.fixed-totals { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; background: var(--teal-soft); border-radius: 10px; padding: .65rem .75rem; font-size: .85rem; }
.fixed-totals div { display: flex; flex-direction: column; }
.fixed-totals strong { font-size: 1.1rem; color: #0B5F52; }

/* Results */
.results-card { border-top: 4px solid var(--teal); }
.verdict { border-radius: 12px; padding: .9rem 1rem; margin-bottom: .75rem; border: 2px solid; }
.verdict-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -.01em; }
.verdict-title::before { content: ""; display: inline-block; width: .7em; height: .7em; border-radius: 50%; margin-right: .45em; background: currentColor; vertical-align: .05em; }
.verdict-sub { font-size: .9rem; margin-top: .15rem; }
.verdict.take { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.verdict.negotiate { background: var(--yellow-bg); border-color: #E3B341; color: var(--yellow); }
.verdict.pass { background: var(--red-bg); border-color: var(--red); color: var(--red); }
.verdict-sub { color: var(--grey); }
.counter { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .6rem; background: var(--grey); color: #fff; border-radius: 12px; padding: .75rem 1rem; margin-bottom: .75rem; }
.counter span { flex-basis: 100%; font-size: .85rem; opacity: .85; }
.counter strong { font-size: 1.5rem; color: var(--teal); }
.counter small { opacity: .9; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .75rem; }
.kpi { background: #F7F9FA; border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; display: flex; flex-direction: column; min-width: 0; }
.kpi span { font-size: .75rem; color: var(--grey-2); font-weight: 600; }
.kpi strong { font-size: 1.25rem; color: #222; overflow-wrap: anywhere; }
.kpi strong.neg { color: var(--red); }
table.rates { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.rates th { text-align: left; font-weight: 500; color: var(--grey-2); padding: .4rem 0; }
table.rates td { text-align: right; font-weight: 700; padding: .4rem 0; color: #222; font-variant-numeric: tabular-nums; }
table.rates td small { display: block; font-weight: 500; color: var(--grey-2); font-size: .78rem; }
table.rates tr + tr th, table.rates tr + tr td { border-top: 1px solid var(--line); }
table.rates tr.sep th, table.rates tr.sep td { border-top: 2px solid var(--teal); }
.breakdown { margin-top: .5rem; }
.breakdown summary { cursor: pointer; font-weight: 600; color: var(--teal-dark); padding: .3rem 0; }
.warnings { list-style: none; padding: 0; margin: .5rem 0 0; }
.warnings li { background: var(--yellow-bg); color: #6B4E00; border-radius: 8px; padding: .5rem .65rem; font-size: .83rem; margin-top: .4rem; }
.save-row { margin-top: 1rem; display: grid; gap: .5rem; }
.save-row .field { margin: 0; }

/* History */
.history { list-style: none; margin: 0; padding: 0; }
.history li { display: grid; grid-template-columns: auto 1fr auto; gap: .25rem .75rem; align-items: center; padding: .65rem 0; border-top: 1px solid var(--line); }
.history .dot { width: 12px; height: 12px; border-radius: 50%; }
.dot.take { background: var(--green); } .dot.negotiate { background: #E3B341; } .dot.pass { background: var(--red); }
.history .h-main { min-width: 0; }
.history .h-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .h-meta { font-size: .8rem; color: var(--grey-2); }
.history .h-right { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.history .h-right small { display: block; font-weight: 500; color: var(--grey-2); }
.history .h-del { grid-column: 3; justify-self: end; }
.linkbtn { background: none; border: 0; color: var(--red); font: inherit; font-size: .78rem; cursor: pointer; padding: 0; }

/* Pro */
.pro { background: linear-gradient(135deg, #fff 0%, var(--teal-soft) 100%); }
.badge { background: var(--grey); color: #fff; font-size: .72rem; font-weight: 700; border-radius: 999px; padding: .2rem .6rem; text-transform: uppercase; letter-spacing: .04em; }
.pro-list { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.pro-list li { margin: .2rem 0; }
.pro-list li::marker { color: var(--teal-dark); }

/* Footer */
.footer { max-width: 1120px; margin: 0 auto; padding: 1rem 1rem 2rem; text-align: center; }
.footer .cta { font-weight: 700; font-size: 1rem; background: var(--grey); color: #fff; border-radius: 12px; padding: .85rem 1rem; margin: 0 0 .75rem; }
.footer .cta a { color: var(--teal); text-decoration: none; }
.footer .fine { font-size: .78rem; color: var(--grey-2); margin: .25rem 0; }

/* Sticky verdict bar (mobile only) */
.sticky-bar {
  position: fixed; left: .75rem; right: .75rem; bottom: calc(.75rem + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-radius: 14px;
  text-decoration: none; font-weight: 800; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.sticky-bar.take { background: var(--green); } .sticky-bar.negotiate { background: #C98A0B; } .sticky-bar.pass { background: var(--red); }
@media (min-width: 900px) { .sticky-bar { display: none !important; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); background: #222; color: #fff; padding: .55rem 1rem; border-radius: 999px; font-size: .9rem; z-index: 40; }

@media (max-width: 360px) {
  .grid2 { grid-template-columns: minmax(0,1fr); }
  .input-with-toggle { flex-direction: column; }
}
#results, #historyCard, #proCard { scroll-margin-top: 84px; }

/* Align inputs across a row even when one label wraps to two lines */
@supports (grid-template-rows: subgrid) {
  .grid2 > .field { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: .3rem; align-content: start; }
  .grid2 > .field > span:first-child { align-self: end; }
  .grid2 > .field > .hint { margin-top: 0; }
}
