/* Allied Rooftop Explorer - mobile first (360-430 px is the main screen). */
:root {
  --bg: #f4f5f1; --fg: #17201b; --muted: #55615a; --line: #d6dbd4; --card: #ffffff;
  --sun: #e8a21c; --sun-ink: #7a4d00; --sun-bg: #fff3d6;
  --green: #1e9c90; --green-ink: #136e65; --green-bg: #e1f3f1;                /* Kirloskar teal: fills; ink for text */
  --sky: #27488d; --sky-bg: #e4eaf5; --brand: #27488d;                          /* Allied blue: buttons, headings, links */
  --red: #ce2528; --red-bg: #fdf0f0;                                            /* Allied red: errors and the contact card */
  --wa: #0b6e4f; --shadow: 0 1px 2px rgba(23, 32, 27, .06), 0 4px 16px rgba(23, 32, 27, .05);
  --field: #8a958d;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --fg: #e9ece8; --muted: #a3ada5; --line: #2c3430; --card: #1b2120;
    --sun: #f2b84a; --sun-ink: #f2c66e; --sun-bg: #3b2d10;
    --green: #22ad9f; --green-ink: #63d1c4; --green-bg: #10302c;
    --sky: #9db8ee; --sky-bg: #17243c; --brand: #4069c0; --red: #f28b8c; --red-bg: #3d1b1c;
    --wa: #0b6e4f; --shadow: none; color-scheme: dark; --field: #6b766f;
  }
}
:root[data-theme="dark"] {
  --bg: #121614; --fg: #e9ece8; --muted: #a3ada5; --line: #2c3430; --card: #1b2120;
  --sun: #f2b84a; --sun-ink: #f2c66e; --sun-bg: #3b2d10;
  --green: #22ad9f; --green-ink: #63d1c4; --green-bg: #10302c;
  --sky: #9db8ee; --sky-bg: #17243c; --brand: #4069c0; --red: #f28b8c; --red-bg: #3d1b1c;
  --wa: #0b6e4f; --shadow: none; color-scheme: dark; --field: #6b766f;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: "IBM Plex Sans", "Noto Sans Malayalam", "Nirmala UI", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.55; padding-bottom: 72px;
}
.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding-inline: 16px; }
h1 { font-size: clamp(1.55rem, 6vw, 2.2rem); line-height: 1.15; margin: 10px 0 6px; font-weight: 700; letter-spacing: -.01em; color: var(--sky); }
h2 { font-size: 1.08rem; margin: 0 0 12px; font-weight: 700; display: flex; align-items: center; gap: 10px; overflow-wrap: anywhere; color: var(--sky); }
h2 .n {
  flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--sun); color: #1d1500; font-size: .85rem; font-weight: 700;
}
p { margin: 0; }
a { color: var(--sky); }
code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .85em; color: var(--fg); }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* header */
.top { background: linear-gradient(180deg, var(--card), var(--bg)); border-bottom: 1px solid var(--line); padding: 14px 0 12px; }
.brand { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.logos { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.logo-ph {
  display: grid; place-items: center; min-width: 104px; min-height: 44px; padding: 4px 10px; border: 1.5px dashed var(--line);
  border-radius: 8px; color: var(--muted); font-size: .72rem; font-weight: 600; text-align: center; line-height: 1.15;
}
.logo-img { display: block; height: 44px; width: auto; max-width: 170px; object-fit: contain; padding: 4px 8px; border-radius: 8px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo-img { background: #fff; } }
:root[data-theme="dark"] .logo-img { background: #fff; }
.cred { font-size: .78rem; color: var(--muted); flex: 1 1 220px; }
.lede { color: var(--muted); max-width: 62ch; }
.lede-sm { color: var(--muted); font-size: .92rem; margin-bottom: 4px; }
.stepper { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.stepper::-webkit-scrollbar { display: none; }
.stepper a {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px 4px 5px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--fg); text-decoration: none; font-size: .85rem;
}
.stepper b { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--sun-bg); color: var(--sun-ink); font-size: .75rem; }

/* cards */
main.wrap { display: grid; gap: 14px; padding-top: 14px; padding-bottom: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; box-shadow: var(--shadow); scroll-margin-top: 10px; }

/* form controls */
.field { display: block; font-size: .85rem; color: var(--muted); margin: 14px 0 6px; }
input[type=number], input[type=text], input[type=tel], input[type=search] {
  width: 100%; font: inherit; font-size: 1rem; min-height: 46px; padding: 10px 12px; border: 1px solid var(--field); border-radius: 10px;
  background: var(--bg); color: var(--fg); font-variant-numeric: tabular-nums;
}
input::placeholder { color: var(--muted); opacity: 1; }
input:focus-visible, .btn:focus-visible, .stepper a:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
input[type=range] { width: 100%; margin: 12px 0 2px; accent-color: var(--green); height: 28px; }
.seg { border: 0; padding: 0; margin: 14px 0 0; min-width: 0; }
.seg legend { font-size: .85rem; color: var(--muted); padding: 0; margin-bottom: 6px; }
.seg .opts { display: flex; flex-wrap: wrap; gap: 8px; }
.seg .opt { position: relative; display: inline-flex; }
.seg input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; scroll-margin-bottom: 8px; }
.seg label {
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; border: 1px solid var(--field); border-radius: 999px;
  background: var(--card); color: var(--fg); cursor: pointer; font-size: .92rem; user-select: none;
}
.seg input:checked + label { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.seg input:focus-visible + label { outline: 3px solid var(--sky); outline-offset: 2px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .95rem;
  min-height: 46px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  cursor: pointer; text-decoration: none; text-align: center; min-width: 0; overflow-wrap: break-word;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.sm { min-height: 38px; padding: 6px 14px; font-size: .9rem; }
.msg { font-size: .85rem; color: var(--muted); min-height: 0; margin-top: 6px; }
.msg:empty { display: none; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 8px; }
.fine { font-size: .78rem; color: var(--muted); margin-top: 10px; }

/* step 1: search + map */
.search { display: flex; flex-wrap: wrap; gap: 8px; }
.search input { flex: 1 1 10rem; min-width: 0; }
.search .btn { flex: none; }
.search input, .search .btn { min-height: 48px; }   /* one height for the box, തിരയൂ and എന്റെ location, also when wrapped */
.search .btn.locate { flex: 1 1 100%; }   /* phones: its own full-width row under the search */
.btn .ico { flex: none; }
.locate-note { margin-top: 6px; }
@media (min-width: 640px) { .search .btn.locate { flex: none; } }
.mapbox { position: relative; margin-top: 10px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
#map { height: min(58vh, 460px); min-height: 300px; background: #3d4740; }
.map-ph {
  height: 100%; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 16px; text-align: center; color: #fff;
  background-color: #4d443b;
  background-image: linear-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .07) 1px, transparent 1px);
  background-size: 28px 28px;
}
.map-note {
  position: absolute; top: 10px; right: 10px; z-index: 800; background: rgba(10, 14, 12, .78); color: #fff; font-size: .85rem; font-weight: 600;
  padding: 6px 10px; border-radius: 8px; pointer-events: none; font-variant-numeric: tabular-nums;
}
.maptools { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.maptools .btn.pri { flex: 1 1 200px; }
.rh { background: transparent; border: 0; }
.rh::after { content: ""; position: absolute; inset: 10px; background: #fff; border: 2px solid #17201b; border-radius: 3px; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.rh.rot::after { inset: 8px; border-radius: 50%; background: #ffd23f; border-color: #17201b; }
.rh.move::after { inset: 11px; border-radius: 50%; background: #fff; border: 3px solid #ffd23f; }
.esri-tile { overflow: hidden; }
.esri-tile img { position: absolute; left: 0; top: 0; width: 256px; height: 256px; max-width: none; }
.esri-tile img.half { width: 512px; height: 512px; }
.leaflet-container { font: inherit; }
.leaflet-container .leaflet-control-attribution { font-size: 10px; }

/* results */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 8.5rem), 1fr)); grid-auto-flow: row dense; gap: 10px; }
.kpi { border: 1px solid var(--line); border-left: 4px solid var(--kc, var(--green)); border-radius: 10px; padding: 10px 12px; background: var(--card); min-width: 0; }
.kpi.wide, .kpis > .ok { grid-column: 1 / -1; }
.kpi small { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; min-width: 0; overflow-wrap: anywhere; }
.kpi b { display: block; font-size: 1.22rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; margin: 2px 0; overflow-wrap: break-word; }
.kpi span { display: block; font-size: .78rem; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.k-sun { --kc: var(--sun); } .k-green { --kc: var(--green); } .k-sky { --kc: var(--sky); } .k-red { --kc: var(--red); }
.tbl { overflow-x: auto; margin-top: 12px; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .86rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td.n { white-space: nowrap; }
#detail td.n { white-space: normal; }
tr.hl td { background: var(--sun-bg); }
.pos { color: var(--green-ink); } .neg { color: var(--fg); }   /* red is kept for errors */
.chartbox { margin: 14px 0 0; }
.chartbox figcaption { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }
.chart { display: block; width: 100%; height: auto; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.legend .k::before { content: ""; display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; background: currentColor; }
.legend .without::before { background: var(--sky); } .legend .green::before { background: var(--green); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--green-bg); color: var(--green-ink); white-space: nowrap; }
.assume { font-size: .82rem; color: var(--muted); display: grid; gap: 6px; margin-top: 12px; }
.report .tbl { overflow-x: visible; }
.report td.n { white-space: normal; overflow-wrap: normal; }   /* wrap only at spaces: never split an amount */
.report th { overflow-wrap: anywhere; }
@media (max-width: 429px) {
  table { font-size: .8rem; }
  th, td { padding: 6px 4px; }
}
@media (max-width: 374px) {
  #betable { font-size: .74rem; }
  #betable th, #betable td { padding: 5px 3px; }
  #betable th { overflow-wrap: anywhere; letter-spacing: 0; }
  #betable th:first-child { overflow-wrap: normal; }
}
/* Packages on phones: one card per size (label above value), no sideways scrolling. */
@media (max-width: 639px) {
  #pktable, #pktable tbody, #pktable tr, #pktable td { display: block; }
  #pktable tr.hd { display: none; }
  #pktable tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  #pktable td { border: 0; padding: 0; text-align: left; white-space: normal; }
  #pktable td::before { content: attr(data-label); display: block; color: var(--muted); font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
}

/* step 5 */
.lead { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 12px; }
.lead .btn.wa { width: 100%; margin-top: 14px; }
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: .82rem; color: var(--muted); margin-top: 14px; cursor: pointer; }
.consent input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; accent-color: var(--green); }
.consent span { min-width: 0; overflow-wrap: anywhere; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.ok { border-radius: 10px; padding: 12px; font-size: .9rem; margin-top: 12px; background: var(--green-bg); color: var(--green-ink); }
.ok:empty { padding: 0; margin: 0; }
.ferr { margin: 4px 0 0; font-size: .82rem; font-weight: 600; color: var(--red); }
input[aria-invalid="true"] { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.print-note { display: none; }
.ok.err { background: var(--red-bg); color: var(--red); }
.ok a { color: inherit; font-weight: 600; }
.cta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.cta .btn { flex: 1 1 160px; }

/* report */
.report { border: 2px solid var(--green); }
/* The report gets focus after submit (for screen readers); a ring around the whole card is not needed and would print. */
#report:focus { outline: none; }
.rep-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.rep-head .cred { flex: 1 1 100%; }
.report h2 { margin-top: 14px; }
.rep-meta { font-size: .82rem; color: var(--muted); }
.rep-grid { display: grid; gap: 10px; margin-top: 12px; }
.report th { text-transform: none; letter-spacing: 0; font-size: .82rem; }
.rep-total th, .rep-total td { font-weight: 700; font-size: 1rem; color: var(--fg); border-top: 2px solid var(--fg); }
.rep-note { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--sun-bg); color: var(--sun-ink); font-size: .85rem; }
.rep-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.rep-actions .btn { flex: 1 1 160px; }

/* sticky summary (phones) */
.sticky { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0, 0, 0, .08); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
.sticky-in { max-width: 1040px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sticky .btn { flex: none; white-space: nowrap; overflow-wrap: normal; }
#stickyText { font-size: .86rem; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

.foot { font-size: .75rem; color: var(--muted); padding-top: 6px; padding-bottom: 16px; display: grid; gap: 4px; }

@media (max-width: 899px) { html { scroll-padding-bottom: calc(var(--sticky-h, 72px) + 16px); } }

/* wider screens */
@media (min-width: 640px) {
  .kpis { grid-template-columns: repeat(auto-fit, minmax(min(100%, 10.5rem), 1fr)); }
  .kpi.wide { grid-column: auto; }
  .lead { grid-template-columns: 1fr 1fr 1fr; }
  .lead .consent, .lead .btn.wa { grid-column: 1 / -1; }
  .rep-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 900px) {
  main.wrap { grid-template-columns: 1fr 1fr; }
  #s1 { grid-column: 1 / -1; }
  #s3, #s4, #s5, #report, #packages { grid-column: 1 / -1; }
  body { padding-bottom: 0; }
  .sticky { display: none; }
}

/* print: the report only */
@media print {
  :root, :root:not([data-theme="light"]), :root[data-theme="dark"] { --bg: #fff; --fg: #111; --muted: #444; --line: #ccc; --card: #fff; --green: #1e9c90; --green-ink: #136e65; --green-bg: #e1f3f1; --sky: #27488d; --brand: #27488d; --red: #ce2528; --sun-bg: #fff3d6; --sun-ink: #6b4400; --shadow: none; color-scheme: light; }
  @page { size: A4; margin: 14mm; }
  body { padding: 0; background: #fff; font-size: 12pt; }
  .top, .foot, .sticky, main > :not(#report):not(.print-note), .no-print { display: none !important; }
  .print-note { display: block; font-size: 14pt; }
  #report:not([hidden]) ~ .print-note { display: none !important; }
  main.wrap { display: block; padding: 0; max-width: none; }
  .report:not([hidden]) { display: block !important; border: 0; box-shadow: none; padding: 0; }
  .rep-grid { grid-template-columns: 1fr; }
  .tbl { overflow: visible !important; }
  td.n { white-space: normal; }
  table { font-size: 10.5pt; }
  th, td { padding: 4px 8px; }
  .rep-head .logo-img { height: 36px; background: #fff; border: 1px solid #e3e3e3; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rep-head .logo-ph { height: auto; min-height: 36px; }
  .logo-ph { border-color: #999; color: #555; }
}
