/* ZIMFIC Insights dashboard. Tokens and shared components come from base.css.
   Desktop: light rail + content. Phones: app bar, bottom tab bar, one column. */

body.admin { font-size: 14px; }

.app { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }

/* ---------- Rail (desktop) ---------- */

.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--sp-6); padding: var(--sp-5) var(--sp-3); background: var(--surface); border-right: 1px solid var(--line); }
.rail > .brand { padding: 0 var(--sp-2); }
.rail-nav { display: grid; gap: 2px; }
.rail-nav a { display: flex; align-items: center; gap: var(--sp-3); height: 40px; padding: 0 var(--sp-3); border-radius: var(--r); color: var(--text-2); font-weight: 500; text-decoration: none; }
.rail-nav a:hover { background: var(--surface-2); color: var(--text); }
.rail-nav a.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.rail-foot { margin-top: auto; display: grid; gap: 6px; padding: 0 var(--sp-2); font-size: 13px; }
.who { display: grid; min-width: 0; margin-bottom: 2px; }
.who b, .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who b { font-weight: 600; color: var(--text); }
.who span { font-size: 12px; color: var(--text-3); }
.rail-foot .link { justify-self: start; }

/* ---------- Staff sign-in ---------- */

.gate { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-6) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom)); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Content ---------- */

.content { min-width: 0; padding: var(--sp-5) var(--sp-6) var(--sp-8); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.head-title { display: flex; align-items: center; gap: var(--sp-3); }
.head-mark { display: none; }
.head h1 { font-size: 26px; margin-top: 2px; }

.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.seg button { height: 30px; min-width: 44px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm); background: none; color: var(--text-2); font-family: var(--mono); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }

.status { margin-bottom: var(--sp-3); padding: 10px var(--sp-3); border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); color: var(--text-2); }
.status.err { color: var(--danger); background: var(--danger-soft); border-color: transparent; }

.tab { display: grid; gap: var(--sp-3); animation: fade .25s both; }
.grid { display: grid; gap: var(--sp-3); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.card-h { margin-bottom: var(--sp-3); }
.card-h h3 { font-size: 15px; letter-spacing: -.01em; }
.card-h span { display: block; font-size: 12.5px; color: var(--text-3); }
.card-h.split { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; }
.controls { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.input-sm { height: 36px; font-size: 14px; width: auto; min-width: 180px; }
select.input-sm { min-width: 150px; }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-3); min-height: 94px; }
.tile { padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; }
.tile-k { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.tile-v { font-family: var(--display); font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-v.text { font-size: 17px; line-height: 1.35; white-space: normal; }
.tile-d { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

/* ---------- Charts ---------- */

.chart-host { min-height: 240px; }
.chart-host.short { min-height: 180px; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .baseline { stroke: var(--line-2); stroke-width: 1; }
.chart .tick { fill: var(--text-3); font-family: var(--mono); font-size: 10.5px; }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-4); margin-bottom: var(--sp-2); font-size: 12.5px; color: var(--text-2); }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; vertical-align: -1px; }

.bars { display: grid; gap: var(--sp-2); }
.bar-row { display: grid; grid-template-columns: minmax(84px, 34%) 1fr; gap: var(--sp-3); align-items: center; }
.bar-label { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; align-items: center; gap: var(--sp-2); height: 18px; min-width: 0; }
.bar-fill { height: 12px; min-width: 2px; border-radius: 0 4px 4px 0; }
.bar-val { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); white-space: nowrap; }
.bar-val b { color: var(--text); font-weight: 600; }
.chart-note { margin-top: var(--sp-2); font-size: 12.5px; color: var(--text-3); }

.funnel { display: grid; gap: var(--sp-2); }
.f-row { display: grid; grid-template-columns: 140px 1fr; gap: var(--sp-3); align-items: center; }
.f-label { font-size: 13px; }
.f-track { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.f-fill { height: 18px; min-width: 2px; border-radius: 0 4px 4px 0; background: var(--s1); }
.f-val { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); white-space: nowrap; }
.f-drop { margin-left: 4px; color: var(--danger); }

.heat { display: grid; gap: var(--sp-4); }
.heat-step h4 { margin-bottom: var(--sp-2); font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.heat-cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 4px; }
.cell { display: flex; flex-direction: column; justify-content: space-between; gap: 2px; min-height: 52px; padding: var(--sp-2) 10px; border-radius: var(--r-sm); color: var(--text); }
.cell.dark { color: #fff; }
.cell-n { font-size: 12.5px; font-weight: 500; }
.cell-c { font-family: var(--mono); font-size: 11px; }
.heat-scale { display: flex; align-items: center; gap: var(--sp-2); font-size: 11.5px; color: var(--text-3); }
.heat-scale .swatch { width: 20px; margin: 0; border-radius: 0; }
.heat-scale .ramp { display: inline-flex; }

.tip { position: fixed; z-index: 1000; max-width: 240px; padding: 6px 10px; border-radius: var(--r-sm); background: var(--navy); color: #fff; font-size: 12px; line-height: 1.5; pointer-events: none; box-shadow: var(--shadow-pop); }
.tip .swatch { width: 8px; height: 8px; }

/* ---------- Lists & tables ---------- */

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: var(--sp-2) var(--sp-3); text-align: left; white-space: nowrap; font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--line); }
td { padding: 10px var(--sp-3); white-space: nowrap; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 12.5px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.rowcard { display: none; }

.feed { display: grid; gap: var(--sp-2); max-height: 720px; overflow-y: auto; }
.post { display: grid; gap: 6px; padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r); }
.post-h { display: flex; justify-content: space-between; gap: var(--sp-2); flex-wrap: wrap; font-size: 12.5px; color: var(--text-3); }
.post-h b { color: var(--text); font-weight: 600; }
.post-q { font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.post p { font-size: 13.5px; white-space: pre-wrap; }
audio { width: 100%; height: 36px; margin-top: 4px; }

.bigmap { height: min(620px, 70vh); border-radius: var(--r); overflow: hidden; z-index: 0; }

/* ---------- WiFi tab forms ---------- */

.row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.saved-note { font-size: 13px; color: var(--ok); font-weight: 600; }
.codes { display: grid; gap: 6px; margin-top: var(--sp-2); }
.code-row { display: flex; align-items: center; gap: var(--sp-2); padding: 6px 6px 6px var(--sp-3); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); }
.code-row code { flex: 1; font-family: var(--mono); font-size: 14px; font-weight: 600; letter-spacing: .04em; }
.chip.muted { background: var(--surface-2); color: var(--text-3); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 10px var(--sp-3); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; }
.switch b { display: block; font-size: 14px; font-weight: 600; }
.switch small { display: block; font-size: 12.5px; color: var(--text-3); }
.switch input { width: 40px; height: 22px; flex: none; accent-color: var(--accent); }
.wifi-form { display: grid; gap: var(--sp-2); }

/* ---------- Member detail (inside a .sheet from base.css) ---------- */

.detail-sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }
.dl { display: grid; grid-template-columns: 128px 1fr; gap: 6px var(--sp-3); margin: var(--sp-3) 0 0; font-size: 13.5px; }
.dl dt { color: var(--text-3); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.sec { margin: var(--sp-5) 0 var(--sp-2); font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); }
.idphoto { width: 100%; aspect-ratio: 1.5; object-fit: contain; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); }
.temp-pw { margin-top: var(--sp-2); font-size: 13.5px; }
.temp-pw b { font-family: var(--mono); font-size: 15px; }

/* ---------- Bottom tab bar (phones) ---------- */

.tabbar { display: none; }
.more-list { display: grid; gap: 2px; }
.more-list a, .more-list button { display: flex; align-items: center; gap: var(--sp-3); height: 48px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r); background: none; color: var(--text); font-weight: 500; text-decoration: none; text-align: left; cursor: pointer; }
.more-list a.active { background: var(--accent-soft); color: var(--accent-hover); }

@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); min-height: 196px; }
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-2-1 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }
  .content { padding: 0 var(--sp-3) calc(80px + env(safe-area-inset-bottom)); }
  .head {
    position: sticky; top: 0; z-index: 30; flex-direction: column; align-items: stretch; gap: var(--sp-2);
    margin: 0 calc(-1 * var(--sp-3)) var(--sp-3); padding: calc(var(--sp-2) + env(safe-area-inset-top)) var(--sp-3) var(--sp-2);
    background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .head-mark { display: grid; }
  .head h1 { font-size: 19px; margin: 0; }
  .head .eyebrow { font-size: 10px; }
  .seg { display: grid; grid-template-columns: repeat(4, 1fr); }
  .tiles { gap: var(--sp-2); min-height: 172px; }
  .tile { padding: 10px var(--sp-3); }
  .tile-v { font-size: 21px; }
  .tile-v.text { font-size: 15px; }
  .g-2, .g-3 { grid-template-columns: minmax(0, 1fr); }
  .grid, .tab { gap: var(--sp-2); }
  .card { padding: var(--sp-3); border-radius: var(--r); }
  .chart-host { min-height: 200px; }
  .f-row { grid-template-columns: 1fr; gap: 2px; }
  .card-h.split > * { flex: 1 1 100%; }
  .controls .input-sm { flex: 1; min-width: 0; }
  .card-h.split > .input-sm { width: 100%; min-width: 0; }
  .heat-cells { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bigmap { height: 64vh; }
  .row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-2); }
  .dl { grid-template-columns: 1fr; gap: 0; }
  .dl dd { margin-bottom: var(--sp-2); }

  /* tables become cards */
  .scroll-x table { display: none; }
  .rowcard { display: grid; gap: 1px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
  .rowcard.clickable { cursor: pointer; }
  .rowcard b { font-size: 14px; font-weight: 600; }
  .rowcard span { font-family: var(--mono); font-size: 12px; color: var(--text-3); }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 52px;
    border: 0; border-radius: var(--r); background: none; color: var(--text-3); font-size: 11px; font-weight: 600; text-decoration: none; cursor: pointer;
  }
  .tabbar .active { color: var(--accent); }
  .tabbar .active .i { stroke-width: 2.3; }
}
