/* ==========================================================================
   Mekhfon — responsive + print
   wall display (≥1900) · laptop (≤1500) · small laptop (≤1280) · tablet (≤1100)
   · tablet portrait (≤900) · phone (≤720)
   ========================================================================== */

/* ---- masthead on wide screens (the illustration bleeds to the screen edge) ------------ */
@media (min-width: 1600px) {
  /* masthead: the illustration bleeds to the screen edge while the content sits in the centred column, so
     spread the content over the room the art leaves instead of leaving a blank band between them. */
  .rb-header-top {
    --rb-art-w: min(33vw, 780px);
    --rb-edge: max(0px, calc((100vw - var(--rb-maxw)) / 2));
    padding-right: max(var(--rb-gutter), calc(var(--rb-art-w) - var(--rb-edge) - 120px));
    justify-content: space-between;
  }
  .rb-header-top .rb-clock { margin-left: 0; }
}

/* ---- wall display / large monitor ------------------------------------------ */
@media (min-width: 1900px) {
  :root { --rb-maxw: 2200px; }
  .rb-brand-mark { width: 10rem; }
  .rb-mission { font-size: 1.22rem; }
  .rb-clock-text { font-size: 1.18rem; }
  .rb-nav-btn { padding: .66rem 1.7rem; font-size: 1.12rem; }
  .rb-nav-track { padding-right: 6rem; }
  .rb-ov-map .rb-map-stage { min-height: 30rem; }
  .rb-fctable td { padding: .5rem .8rem; }
  .rb-wx { width: 2.3rem; height: 2.3rem; }
}

/* ---- laptop ------------------------------------------------------------------ */
@media (max-width: 1500px) {
  .rb-header-top { gap: .85rem; }
  .rb-brand-mark { width: 7.4rem; }
  .rb-brand-name { font-size: 1.9rem; }
  .rb-mission { font-size: 1.04rem; }
  .rb-nav-btn { padding: .6rem .85rem; font-size: 1rem; }
  .rb-hero--ov { grid-template-columns: minmax(0, 34fr) minmax(0, 20fr) minmax(0, 46fr); }
  .rb-h1-sep { display: none; }
  .rb-h1-route { display: block; margin-top: .25rem; color: var(--rb-gold-600); }
  .rb-ov-grid { grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr); }
  .rb-fctable td:nth-child(2) { min-width: 8.4rem; font-size: .84rem; }
  .rb-detail-cell { min-width: 8rem; font-size: .78rem; }
  .rb-wx3 > div { min-width: 2.5rem; }
  .rb-windows { grid-template-columns: repeat(5, minmax(10rem, 1fr)); overflow-x: auto; }
}

/* ---- overview bottom row on laptops: the radar film gets its own full-width row (its thumbnails were 40px wide in a third of
        the screen); the river card and the data-source card share the row beneath it ------------------------------------- */
@media (min-width: 901px) and (max-width: 1500px) {
  .rb-ov-bottom { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .rb-ov-bottom .rb-film { grid-column: 1 / -1; }
  .rb-film-body .rb-thumbs { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  /* one row of thumbnails is shorter than the big picture: tabs on top, slider at the bottom, thumbnails between them */
  .rb-film-body { align-items: stretch; }
  .rb-film-main { display: flex; flex-direction: column; justify-content: space-between; gap: .6rem; }
}

/* stations: give the source table more of the row on laptops (its frequency / age columns were wrapping to two lines) */
@media (min-width: 1101px) and (max-width: 1500px) {
  .rb-stations-grid { grid-template-columns: minmax(0, 2.15fr) minmax(0, 1fr); }
  #stSources td:nth-child(2), #stSources td:nth-child(4) { white-space: nowrap; }
}

/* ---- small laptop -------------------------------------------------------------- */
@media (max-width: 1280px) {
  .rb-header-art { width: min(36vw, 560px); opacity: .9; }
  .rb-mission span:last-child { display: none; }
  .rb-mission { font-size: 1rem; max-width: 12rem; }
  .rb-hero--ov { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  .rb-hero--ov .rb-kpis { grid-column: 1 / -1; }
  .rb-hero--water, .rb-hero--alerts { grid-template-columns: 1fr; }
  .rb-radar-grid { grid-template-columns: minmax(13.5rem, .8fr) minmax(0, 2fr); }
  .rb-radar-grid .rb-analysis { grid-column: 1 / -1; }
  .rb-fc-grid { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  .rb-fc-bottom { grid-template-columns: 1fr 1fr; }
  .rb-fc-bottom .rb-legend-card { grid-column: 1 / -1; }
}

/* ---- tablet --------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .rb-ov-grid, .rb-split, .rb-split--wide, .rb-water-grid, .rb-alerts-grid, .rb-reports-grid, .rb-stations-grid, .rb-radar-bottom, .rb-safehero { grid-template-columns: 1fr; }
  .rb-ov-map .rb-map-stage { min-height: 26rem; margin-bottom: 0; }
  /* water page: one column; cards are re-ordered so the station map follows the main chart (not the CCTV list) */
  .rb-water-grid > .rb-stack { display: contents; }
  .rb-w-chart { order: 1; } .rb-w-map { order: 2; } .rb-w-live { order: 3; } .rb-w-twin { order: 4; } .rb-w-cctv { order: 5; } .rb-w-src { order: 6; }
  .rb-water-mapcard .rb-map-stage--water { flex: none; height: clamp(22rem, 62vw, 30rem); }
  /* zone cards leave the map and sit beneath it */
  .rb-zone-stack { position: static; width: auto; flex-direction: row; flex-wrap: wrap; padding: .6rem .8rem .8rem; background: transparent; pointer-events: auto; }
  .rb-ov-map .rb-map-stage { overflow: visible; display: flex; flex-direction: column; border: 0; background: transparent; margin: 0; }
  .rb-ov-map .rb-map-stage .rb-map { position: relative; inset: auto; height: 26rem; border-radius: 12px; border: 1px solid var(--rb-line); margin: 0 .8rem; }
  .rb-ov-map .rb-zone-stack { order: 2; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .rb-ov-map .rb-compass, .rb-ov-map .rb-legend, .rb-ov-map .rb-dbz, .rb-ov-map .rb-map-tag { z-index: 520; }
  .rb-ov-map .rb-compass { left: 1.6rem; top: .8rem; }
  .rb-ov-map .rb-legend { display: none; }
  .rb-ov-map .rb-dbz { right: 1.6rem; }
  .rb-ov-map .rb-map-tag { left: 1.6rem; bottom: auto; top: 25rem; }
  /* zone cards are below the map now, so bottom-right map controls need no offset */
  .rb-ov-map .rb-map-stage .leaflet-bottom.leaflet-right { margin-right: 0; }
  .rb-zcard { min-height: 5.2rem; }
  .rb-radar-grid { grid-template-columns: 1fr; }
  .rb-radar-map { order: 1; min-height: 30rem; }
  .rb-layers { order: 2; }
  .rb-analysis { order: 3; }
  .rb-layers .rb-radios { display: grid; grid-template-columns: repeat(3, 1fr); }
  .rb-map-stage--radar { min-height: 30rem; }
  .rb-fc-grid { grid-template-columns: 1fr; }
  .rb-fc-inspector { position: static; }
  /* keep the selected source detail visible before the long station list */
  .rb-stations-grid > .rb-st-side { position: static; display: contents; }
  .rb-st-side > #stDetail { order: -1; }
  .rb-stations-grid > .rb-card { order: 0; }
  .rb-st-side > .rb-principles { order: 1; }
  .rb-settings { grid-template-columns: 1fr; }
  .rb-settings-nav { position: static; flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .rb-settings-nav a { white-space: nowrap; }
  .rb-windows { grid-template-columns: repeat(5, minmax(12rem, 1fr)); }
  .rb-ad-foot { grid-template-columns: 1fr; }
  .rb-principles { grid-template-columns: 1fr; }
  .rb-strip { grid-template-columns: 1fr; }
  /* keep the water station table inside its card on tablets */
  .rb-st-table th, .rb-st-table td { padding: .55rem .5rem; }
  .rb-st-table th { white-space: normal; }
}

/* ---- tablet portrait ---------------------------------------------------------------- */
/* ---- footer on tablets: partner + credit share the first row, caution + sources get the full second row ---- */
@media (min-width: 721px) and (max-width: 1100px) {
  .rb-footer-inner { grid-template-columns: 1fr auto; row-gap: .8rem; }
  .rb-footer-mid { grid-column: 1 / -1; order: 3; padding: .7rem 0 0; border: 0; border-top: 1px solid var(--rb-line-2); }
}

@media (max-width: 900px) {
  .rb-header-art { opacity: .5; width: 60vw; }
  .rb-mission, .rb-hdiv { display: none; }
  .rb-mode-note { display: none; }
  .rb-clock { margin-left: auto; }
  .rb-nav-btn span { font-size: .95rem; }
  .rb-hero--ov { grid-template-columns: 1fr; }
  .rb-ov-bottom { grid-template-columns: 1fr; }
  .rb-ov-bottom .rb-src-list { grid-template-columns: 1fr; }
  .rb-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rb-alert-panels { grid-template-columns: 1fr; grid-template-rows: none; }
  .rb-alert-panels > .rb-panel:first-child { grid-row: auto; }
  .rb-alert-panels > .rb-panel:nth-child(3) { align-self: start; }
  .rb-form--grid { grid-template-columns: 1fr; }
  .rb-fc-bottom { grid-template-columns: 1fr; }
  .rb-legend-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---- phone ------------------------------------------------------------------------------ */
@media (max-width: 720px) {
  :root { --rb-gutter: .8rem; }
  html { font-size: calc(14.5px * var(--rb-scale)); scroll-padding-top: 5rem; }
  body.rb { background-attachment: scroll; }

  /* compact masthead: mark + wordmark + date + status */
  .rb-header-art { width: 70vw; opacity: .38; }
  .rb-header-top { min-height: 4.1rem; gap: .5rem; padding: .35rem var(--rb-gutter); }
  .rb-brand { gap: .4rem; }
  .rb-brand-mark { width: 4.9rem; }
  .rb-brand-name { font-size: 1.5rem; line-height: 1.08; }
  .rb-brand-sub { margin-top: .28rem; font-size: .52rem; letter-spacing: 0; white-space: nowrap; }
  .rb-clock { display: none; }
  .rb-mode { margin-left: auto; align-items: flex-end; }
  .rb-mode-pill { padding: .15rem .6rem; font-size: .8rem; }
  .rb-mode-note, .rb-hdiv--mode { display: none; }
  .rb-header-tools { display: none; }
  .rb-nav { display: none; }

  .rb-main { padding-top: .6rem; padding-bottom: 1.2rem; } /* the footer below carries the clearance for the tab bar (it used to be added twice: ~84px of dead space) */
  .rb-h1 { font-size: 1.85rem; }
  .rb-h1-sep { display: none; }
  .rb-h1-route { display: block; font-size: 1.15rem; margin-top: .3rem; color: var(--rb-gold-600); }
  .rb-lede { font-size: .9rem; }
  .rb-card { padding: .8rem .85rem .9rem; border-radius: 14px; }
  .rb-card-title { font-size: 1.02rem; }
  .rb-pagehead { margin-bottom: .6rem; }
  .rb-pagehead-tools { width: 100%; justify-content: flex-start; }

  /* KPI + callout */
  .rb-hero--ov { gap: .65rem; }
  .rb-callout { padding: .7rem .8rem; }
  .rb-callout-ico { width: 2.6rem; height: 2.6rem; }
  .rb-callout-title { font-size: 1.2rem; }
  .rb-kpis { gap: .55rem; }
  .rb-kpi { padding: .65rem .65rem .6rem; }
  .rb-kpi-ico { width: 2.3rem; height: 2.3rem; }
  .rb-kpi-head { min-height: 2.3rem; font-size: .78rem; }
  .rb-kpi-val { font-size: 1.55rem; }

  /* overview map + zones */
  .rb-ov-map .rb-map-stage .rb-map { height: 21rem; margin: 0 .5rem; }
  .rb-ov-map .rb-map-stage { min-height: 0; }
  .rb-ov-map .rb-zone-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: .55rem .5rem .6rem; }
  .rb-ov-map .rb-map-tag { top: 18.4rem; left: 1rem; font-size: .56rem; }
  .rb-ov-map .rb-compass { left: 1rem; width: 2.5rem; height: 2.5rem; }
  .rb-ov-map .rb-dbz { right: 1rem; padding: .2rem .55rem; }
  .rb-ov-map .rb-dbz-ramp { width: 4rem; }
  .rb-ov-map > .rb-card-head { padding: .75rem .8rem 0; }
  .rb-card-tools .rb-btn span { display: none; }

  /* forecast table → cards */
  .rb-ov-forecast .rb-table-wrap { border: 0; background: transparent; overflow: visible; }
  .rb-fctable { display: none; }
  .rb-zone-cards { display: flex; flex-direction: column; gap: .5rem; }
  .rb-zcard-m { display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .7rem; align-items: center; padding: .6rem .7rem; border-radius: 13px; border: 1px solid var(--z-chip); background: linear-gradient(180deg, #fff, var(--z-soft)); }
  .rb-zcard-m .rb-wx3 { grid-column: 1 / -1; justify-content: space-around; padding-top: .2rem; }
  .rb-zcard-m p { grid-column: 1 / -1; font-size: .8rem; line-height: 1.45; color: var(--rb-ink-2); }
  .rb-zcard-m b { font: 700 .88rem/1.3 var(--rb-font-text); }
  .rb-note { flex-direction: column; align-items: stretch; }
  .rb-note .rb-btn { width: 100%; }

  /* bottom strip */
  .rb-thumbs { grid-template-columns: repeat(4, minmax(0, 1fr)); row-gap: .6rem; }
  .rb-thumb { padding-inline: .05rem; }
  .rb-thumb small { min-height: 1.2em; font-size: .64rem; }
  .rb-film-row { flex-direction: column; align-items: stretch; }
  .rb-film-row .rb-play { align-self: flex-start; }
  .rb-river-body { grid-template-columns: 1fr; }
  .rb-src { grid-template-columns: auto minmax(0, 1fr) auto; }
  .rb-src-note { grid-column: 2 / -1; }

  /* other pages */
  .rb-evidence, .rb-doc-zones, .rb-zone-mini { grid-template-columns: 1fr 1fr; }
  .rb-fc-bottom, .rb-twin { grid-template-columns: 1fr; }
  .rb-chart-box { height: 12rem; }
  .rb-windows { grid-template-columns: repeat(5, minmax(11rem, 1fr)); margin-inline: calc(var(--rb-gutter) * -1); padding-inline: var(--rb-gutter); }
  .rb-chart-box--skew { height: 26rem; }
  .rb-chart-box--tall { height: 16rem; }
  .rb-ana-tiles { grid-template-columns: 1fr 1fr; }
  .rb-mini-sources { grid-template-columns: repeat(2, 1fr); }
  .rb-radar-map, .rb-map-stage--radar { min-height: 26rem; }
  .rb-sat-inset { width: 46%; bottom: 3.2rem; }
  .rb-layers .rb-radios { grid-template-columns: 1fr; }
  .rb-map-stage--tall { min-height: 24rem; }
  .rb-alert-item { grid-template-columns: auto minmax(0, 1fr); }
  .rb-alert-item > :last-child { grid-column: 2; }
  .rb-ad-meta { gap: .8rem 1.2rem; }
  .rb-doc { padding: 1.1rem 1.1rem 1rem; }
  .rb-safehero-h { font-size: 1.3rem; }

  /* sounding: the current profile badge carries a long filename + stale note */
  #sndCurrent { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }

  /* reports: the document table becomes cards, and the preview header can wrap */
  #rpList { overflow: visible; border: 0; background: transparent; }
  .rb-report-table { display: block; width: 100%; border-collapse: separate; background: transparent; }
  .rb-report-table thead { display: none; }
  .rb-report-table tbody { display: grid; gap: .5rem; }
  .rb-report-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .25rem .6rem; padding: .65rem .7rem; border: 1px solid var(--rb-line); border-radius: 12px; background: #fff; }
  .rb-report-table td { display: block; border: 0; padding: 0; }
  .rb-report-table td:first-child { grid-column: 1 / -1; }
  .rb-report-table td:nth-child(2) { font-size: .78rem; color: var(--rb-muted); }
  .rb-report-table td:nth-child(2)::before { content: "ออกเมื่อ "; }
  .rb-report-table td:nth-child(3) { justify-self: end; }
  .rb-report-table .rb-doc-title { width: 100%; }
  .rb-report-table .rb-doc-title > div { min-width: 0; }
  .rb-doc-head { flex-wrap: wrap; gap: .6rem; }
  .rb-doc-head > div { min-width: 0; }
  .rb-doc-head img { width: 3.2rem; }
  .rb-doc-head h2 { font-size: 1.02rem; }
  .rb-doc-stamp { margin-left: auto; }

  /* settings permission matrix: keep the Admin column inside the card */
  #setPerm th, #setPerm td { padding: .45rem .4rem; }
  #setPerm th { font-size: .72rem; }

  /* footer */
  .rb-footer { padding-bottom: calc(5.8rem + env(safe-area-inset-bottom, 0px)); }
  .rb-footer-inner { grid-template-columns: 1fr; row-gap: .7rem; padding-top: .85rem; }
  .rb-footer-partner img { width: 2.7rem; height: 2.7rem; }
  .rb-footer-mid { order: 3; padding: .65rem 0 0; border: 0; border-top: 1px solid var(--rb-line-2); gap: .4rem; }
  .rb-footer-powered { position: absolute; top: .85rem; right: var(--rb-gutter); }
  .rb-footer-note { font-size: .7rem; }
  .rb-footer-src li { font-size: .62rem; }

  /* bottom tab bar */
  .rb-tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1150; display: grid; grid-template-columns: repeat(5, 1fr); gap: .15rem; padding: .35rem .5rem calc(.4rem + env(safe-area-inset-bottom, 0px)); background: rgba(255, 253, 247, .96); backdrop-filter: blur(14px); border-top: 1px solid var(--rb-line); box-shadow: 0 -14px 30px -18px rgba(111, 78, 20, .55); }
  .rb-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; min-height: 3.2rem; padding: .3rem .1rem; border: 0; border-radius: 14px; background: transparent; font: 600 .68rem/1.2 var(--rb-font-text); color: var(--rb-ink-2); }
  .rb-tab .rb-i { width: 1.45rem; height: 1.45rem; }
  .rb-tab.is-active { background: var(--rb-gold-grad); color: var(--rb-ink); font-weight: 700; box-shadow: 0 1px 0 #FFF6D8 inset; }
  .rb-map-toast { bottom: calc(5.2rem + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 400px) {
  .rb-footer-powered > span { display: none; }
}

@media (max-width: 380px) {
  .rb-kpi-val { font-size: 1.35rem; }
  .rb-brand-sub { display: none; }
  .rb-thumbs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- print: briefing only (A4) -------------------------------------------------------------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body.rb { background: #fff !important; }
  .rb-header, .rb-tabbar, .rb-sheet, .rb-backdrop, .rb-skip, .rb-map-toast { display: none !important; }
  .rb-main { max-width: none; padding: 0; }
  .rb-screen { display: none !important; animation: none; }
  #screen-reports { display: block !important; }
  #screen-reports > :not(.rb-reports-grid) { display: none !important; }
  .rb-reports-grid { display: block; }
  .rb-reports-grid > .rb-card:first-child { display: none; }
  .rb-doc-card { background: #fff; padding: 0; border: 0; box-shadow: none; }
  .rb-doc { box-shadow: none; padding: 0; }
  .rb-doc::before { display: none; }
}

/* ---- phone: keep small maps legible ---------------------------------------------------- */
@media (max-width: 720px) {
  .rb-zlabel small { display: none; }
  .rb-zlabel { padding: .15rem .55rem .15rem .25rem; }
  .rb-sat-inset { width: 36%; bottom: 2.6rem; right: .5rem; padding: .18rem; }
  .rb-sat-inset-head { display: none; }
  .rb-pin-badge { display: none; }
  .rb-map-stage--radar .leaflet-top.leaflet-left { margin-top: 3.4rem; }
  .rb-compass { width: 2.5rem; height: 2.5rem; left: .5rem; top: .5rem; }
  .rb-map-tag { font-size: .55rem; left: .5rem; }
  .rb-approach { font-size: .62rem; }
  .rb-lm { font-size: .68rem; padding: .12rem .45rem .12rem .3rem; }
  .rb-lm svg { width: 1.3rem; height: 1rem; }
  .rb-matrix td { min-width: 3.9rem; }
  .rb-matrix th:first-child, .rb-matrix td:first-child { min-width: 9rem; }
  .rb-mx-zone b { font-size: .78rem; }
}
