/* CGB Field Safety — styles. System fonts only, so nothing loads from the internet. */
:root{
  --bg:#F6F4EE;
  --surface:#FFFFFF;
  --surface-sunken:#EFEBE1;
  --text:#1B211D;
  --text-muted:#5C665F;
  --border:#DEDACD;
  --primary:#1F4E3D;
  --primary-strong:#163829;
  --primary-tint:#E4EEE8;
  --accent:#B8621F;
  --accent-tint:#F7E9DB;
  --danger:#A32B21;
  --danger-tint:#F7E0DC;
  --warning:#8A5C00;
  --warning-tint:#F5E9CE;
  --success:#256B3F;
  --success-tint:#DFEEE3;
  --extreme:#7A1414;
  --extreme-tint:#F1D6D3;
  --info:#1E6A73;
  --info-tint:#DDF0F0;
  --focus:#1F4E3D;
  --shadow:0 1px 2px rgba(20,24,20,.06), 0 4px 14px rgba(20,24,20,.05);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#12160F; --surface:#1B221C; --surface-sunken:#232A24; --text:#EDEBE1; --text-muted:#9BA69C;
    --border:#313A30; --primary:#5EA37E; --primary-strong:#7CBB98; --primary-tint:#1C2C22;
    --accent:#E0954D; --accent-tint:#2E2417; --danger:#E2685A; --danger-tint:#332019;
    --warning:#E0B84C; --warning-tint:#332B14; --success:#6FC290; --success-tint:#1C2C20;
    --extreme:#EF7A6E; --extreme-tint:#3A1815; --info:#6CC6CC; --info-tint:#16292B; --focus:#7CBB98;
    --shadow:0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"]{
  --bg:#12160F; --surface:#1B221C; --surface-sunken:#232A24; --text:#EDEBE1; --text-muted:#9BA69C;
  --border:#313A30; --primary:#5EA37E; --primary-strong:#7CBB98; --primary-tint:#1C2C22;
  --accent:#E0954D; --accent-tint:#2E2417; --danger:#E2685A; --danger-tint:#332019;
  --warning:#E0B84C; --warning-tint:#332B14; --success:#6FC290; --success-tint:#1C2C20;
  --extreme:#EF7A6E; --extreme-tint:#3A1815; --info:#6CC6CC; --info-tint:#16292B; --focus:#7CBB98;
  --shadow:0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.35);
}

*{ box-sizing:border-box; }
html{ -webkit-text-size-adjust:100%; }
html,body{ min-height:100%; }
body{
  margin:0; background:var(--bg); color:var(--text);
  font:15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding:0 16px calc(96px + env(safe-area-inset-bottom, 0px));
}
[hidden]{ display:none !important; }
img{ max-width:100%; }
h1,h2,h3{ margin:0; line-height:1.15; font-weight:800; letter-spacing:-.01em; }
p{ margin:0; }

.wrap{ max-width:680px; margin:0 auto; }
.wrap > * + *{ margin-top:14px; }
main > * + *{ margin-top:14px; }
.stack > * + *{ margin-top:10px; }
.mt8{ margin-top:8px; } .mt12{ margin-top:12px; }
.center{ text-align:center; }
.muted{ color:var(--text-muted); font-size:14px; }
.small{ font-size:13px; }
.mono{ font-family:ui-monospace, Menlo, Consolas, monospace; }

/* Top bar */
.topbar{
  position:sticky; top:0; z-index:20; margin:0 -16px; display:flex; align-items:center; gap:12px;
  padding:12px 16px; padding-top:calc(12px + env(safe-area-inset-top, 0px));
  background:var(--primary); color:#fff; box-shadow:var(--shadow);
}
:root[data-theme="dark"] .topbar, .topbar{ background:#1F4E3D; }
.topbar .mark{ width:46px; height:38px; object-fit:contain; background:#fff; border-radius:9px; padding:3px 4px; flex:none; }
.topbar-text{ flex:1; min-width:0; }
.topbar .sub{ font-size:11px; opacity:.85; letter-spacing:.05em; text-transform:uppercase; }
.topbar .title{ font-size:20px; font-weight:800; line-height:1.1; }
.net{ width:10px; height:10px; border-radius:50%; background:#8FD19E; flex:none; box-shadow:0 0 0 3px rgba(255,255,255,.15); }
.net.off{ background:#F2C14E; }

/* Cards and fields */
.card{ background:var(--surface); border:1px solid var(--border); border-radius:14px; padding:16px; box-shadow:var(--shadow); }
.card > * + *{ margin-top:12px; }
.section-title{ font-size:21px; color:var(--primary); }
.field{ display:block; }
.field-label{ display:block; font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--text-muted); margin-bottom:6px; }
input[type=text], input[type=tel], input[type=date], input[type=search], textarea, select{
  width:100%; font:inherit; font-size:16px; color:var(--text); background:var(--surface-sunken);
  border:1px solid var(--border); border-radius:10px; padding:12px; min-height:48px;
  -webkit-appearance:none; appearance:none;
}
select{
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235C665F' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position:right 14px center; padding-right:36px;
}
textarea{ min-height:72px; resize:vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible{ outline:3px solid var(--focus); outline-offset:1px; }
.grid2{ display:grid; grid-template-columns:1fr 1fr; gap:12px; }
@media (max-width:480px){ .grid2{ grid-template-columns:1fr; } }

/* Buttons */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px; text-decoration:none;
  font:inherit; font-weight:700; font-size:16px; border-radius:12px; padding:13px 18px; min-height:50px;
  border:1px solid transparent; cursor:pointer; color:var(--text); background:none;
}
.btn svg{ width:20px; height:20px; flex:none; }
.btn-primary{ background:var(--primary); color:#fff; }
.btn-primary:disabled{ opacity:.45; cursor:not-allowed; }
.btn-outline{ border-color:var(--primary); color:var(--primary); background:var(--surface); }
.btn-ghost{ border-color:var(--border); background:var(--surface); }
.btn-danger{ background:var(--danger); color:#fff; }
.btn-small{ min-height:40px; padding:8px 12px; font-size:14px; border-radius:10px; }
.btn-block{ width:100%; }
.btn-row{ display:flex; gap:8px; }
.btn-row .btn{ flex:1; }
.icon-btn{
  display:inline-flex; align-items:center; justify-content:center; width:44px; height:44px; flex:none;
  border-radius:10px; border:1px solid var(--border); background:var(--surface-sunken); color:var(--primary);
  font:inherit; font-size:20px; cursor:pointer;
}
.icon-btn svg{ width:19px; height:19px; }
.icon-btn-lg{ width:50px; height:50px; }
.icon-btn.danger{ color:var(--danger); }

/* Segmented (Yes / No / N/A) — big targets for gloves */
.seg{ display:flex; gap:8px; flex-wrap:wrap; }
.seg button{
  flex:1; min-width:64px; min-height:48px; font:inherit; font-size:15px; font-weight:700;
  border-radius:12px; border:1.5px solid var(--border); background:var(--surface-sunken); color:var(--text); cursor:pointer;
}
.seg button[aria-pressed="true"]{ background:var(--primary); border-color:var(--primary); color:#fff; }
.seg button.danger-opt[aria-pressed="true"]{ background:var(--danger); border-color:var(--danger); }

.chip-row{ display:flex; gap:8px; flex-wrap:wrap; }
.chip{
  font:inherit; font-size:14px; font-weight:600; padding:10px 14px; min-height:44px; border-radius:999px;
  border:1.5px solid var(--border); background:var(--surface-sunken); color:var(--text); cursor:pointer;
}
.chip[aria-pressed="true"]{ background:var(--primary); border-color:var(--primary); color:#fff; }

/* Activities */
.group-label{ font-size:12px; font-weight:800; text-transform:uppercase; letter-spacing:.06em; color:var(--accent); margin:16px 0 8px; }
.group-label:first-child{ margin-top:4px; }
.activity{ margin-top:8px; }
.activity-row{
  width:100%; display:flex; align-items:center; justify-content:space-between; gap:10px; min-height:56px;
  padding:12px 14px; border:1.5px solid var(--border); border-radius:12px; background:var(--surface-sunken);
  font:inherit; color:var(--text); text-align:left; cursor:pointer;
}
.activity-row .name{ font-weight:700; font-size:16px; }
.activity-row .right{ display:flex; align-items:center; gap:8px; flex:none; }
.activity.open .activity-row{ border-color:var(--primary); background:var(--primary-tint); border-radius:12px 12px 0 0; }
.chev{ transition:transform .15s ease; color:var(--text-muted); }
.activity.open .chev{ transform:rotate(90deg); color:var(--primary); }
.activity-panel{ border:1.5px solid var(--primary); border-top:none; border-radius:0 0 12px 12px; padding:4px 14px 14px; background:var(--surface); }
.hazard{ padding:14px 0; border-top:1px dashed var(--border); }
.hazard:first-child{ border-top:none; }
.hazard-name{ font-weight:700; font-size:15.5px; margin-bottom:10px; }
.hazard > * + *{ margin-top:10px; }
.subrow{ padding-top:10px; border-top:1px solid var(--border); }
.subrow > * + *{ margin-top:8px; }
.risk-line{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; font-size:14px; }

/* Badges */
.badge{ display:inline-flex; align-items:center; gap:5px; font-size:12.5px; font-weight:800; padding:4px 10px; border-radius:999px; letter-spacing:.02em; white-space:nowrap; }
.badge.low{ background:var(--success-tint); color:var(--success); }
.badge.moderate{ background:var(--warning-tint); color:var(--warning); }
.badge.high{ background:var(--accent-tint); color:var(--accent); }
.badge.extreme{ background:var(--extreme-tint); color:var(--extreme); }
.badge.flag{ background:var(--danger-tint); color:var(--danger); }
.badge.ok{ background:var(--success-tint); color:var(--success); }
.badge.wait{ background:var(--warning-tint); color:var(--warning); }
.badge.count{ background:var(--primary); color:#fff; }

/* Status */
.status-banner{ display:flex; align-items:center; gap:12px; border-radius:14px; padding:14px 16px; font-weight:800; font-size:16px; }
.status-banner.safe{ background:var(--success-tint); color:var(--success); }
.status-banner.stop{ background:var(--danger-tint); color:var(--danger); }
.status-banner.pending{ background:var(--surface-sunken); color:var(--text-muted); }
.status-banner .dot{ width:14px; height:14px; border-radius:50%; background:currentColor; flex:none; }

/* Banners */
.banner{ display:flex; align-items:center; justify-content:space-between; gap:10px; border-radius:12px; padding:10px 12px; font-size:14px; font-weight:600; }
.banner button{ font:inherit; font-size:14px; font-weight:800; border:none; color:#fff; padding:9px 14px; border-radius:9px; cursor:pointer; flex:none; }
.banner-warn{ background:var(--warning-tint); color:var(--warning); border:1px solid var(--warning); }
.banner-warn button{ background:var(--warning); }
.banner-info{ background:var(--info-tint); color:var(--info); border:1px solid var(--info); }
.banner-info button{ background:var(--info); }

/* Photos */
.photo-grid{ display:grid; grid-template-columns:repeat(3, 1fr); gap:8px; }
.photo-tile{ position:relative; padding-top:100%; border-radius:10px; overflow:hidden; background:var(--surface-sunken); border:1px solid var(--border); }
.photo-tile img{ position:absolute; inset:0; top:0; left:0; width:100%; height:100%; object-fit:cover; display:block; }
.photo-tile button{
  position:absolute; top:5px; right:5px; width:32px; height:32px; border-radius:50%; border:none;
  background:rgba(0,0,0,.6); color:#fff; font-size:18px; line-height:1; cursor:pointer;
}
.add-photo{
  position:relative; padding-top:100%; border-radius:10px; border:2px dashed var(--border); background:var(--surface-sunken);
  color:var(--text-muted); font:inherit; font-size:13px; font-weight:700; cursor:pointer;
}
.add-photo span{ position:absolute; inset:0; top:0; left:0; right:0; bottom:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px; }
.add-photo svg{ width:24px; height:24px; }

/* GPS */
.gps-row{ display:flex; gap:8px; align-items:center; }
.gps-row .btn{ flex:1; }
.gps-readout{ margin-top:8px; padding:10px 12px; border-radius:10px; background:var(--primary-tint); font-size:14px; line-height:1.5; }
.gps-readout b{ font-family:ui-monospace, Menlo, Consolas, monospace; }
.gps-readout .poor{ color:var(--warning); font-weight:700; }

/* History */
.hist-item{
  width:100%; display:flex; align-items:center; justify-content:space-between; gap:10px; padding:14px;
  border:1px solid var(--border); border-radius:12px; background:var(--surface); cursor:pointer; text-align:left; font:inherit; color:var(--text);
}
.hist-item .who{ font-weight:800; font-size:15.5px; }
.hist-item .meta{ font-size:13px; color:var(--text-muted); }
.hist-item .right{ display:flex; flex-direction:column; align-items:flex-end; gap:6px; flex:none; }
.empty{ text-align:center; padding:30px 10px; color:var(--text-muted); }
.kv{ display:grid; grid-template-columns:auto 1fr; gap:4px 12px; font-size:14.5px; }
.kv dt{ font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--text-muted); padding-top:2px; }
.kv dd{ margin:0; }
.detail-hazard{ padding:10px 0; border-top:1px dashed var(--border); font-size:14px; }
.detail-hazard:first-of-type{ border-top:none; }
.detail-hazard .hazard-name{ margin-bottom:4px; }

/* Emergency */
.sos{
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px; min-height:110px;
  background:#B3261E; color:#fff; border-radius:18px; text-decoration:none; box-shadow:var(--shadow);
}
.sos-big{ font-size:34px; font-weight:900; letter-spacing:.01em; }
.sos-small{ font-size:14px; opacity:.9; font-weight:600; }
.call-row{ display:flex; align-items:center; justify-content:space-between; gap:12px; padding:10px 0; border-top:1px solid var(--border); }
.call-row:first-of-type{ border-top:none; }
.call-row .who{ font-weight:700; }
.call-row .num{ font-size:14px; color:var(--text-muted); }
.em-coords{ padding:14px; border-radius:12px; background:var(--primary-tint); text-align:center; }
.em-coords .big{ font-size:24px; font-weight:800; font-family:ui-monospace, Menlo, Consolas, monospace; line-height:1.3; }

/* Settings / admin */
.admin-note{ font-size:12px; font-weight:800; text-transform:uppercase; letter-spacing:.06em; color:var(--accent); }
.edit-row{ display:flex; gap:8px; align-items:center; }
.edit-row input{ flex:1; min-width:0; }
.edit-row select{ width:auto; flex:none; }
.lib-activity{ border:1px solid var(--border); border-radius:12px; padding:12px; background:var(--surface-sunken); }
.lib-activity > * + *{ margin-top:8px; }
.lib-activity input[type=text]{ background:var(--surface); }
details.lib summary{ cursor:pointer; font-weight:700; padding:6px 0; list-style:none; }
details.lib summary::-webkit-details-marker{ display:none; }
details.lib summary:before{ content:"▸ "; color:var(--text-muted); }
details.lib[open] summary:before{ content:"▾ "; }

/* Tab bar */
.tabbar{
  position:fixed; left:0; right:0; bottom:0; z-index:30; display:flex; justify-content:center;
  padding:6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); background:var(--surface); border-top:1px solid var(--border);
}
.tabbar-inner{ max-width:680px; width:100%; display:flex; gap:4px; }
.tab-btn{
  flex:1; display:flex; flex-direction:column; align-items:center; gap:3px; min-height:56px; justify-content:center;
  font:inherit; font-size:12px; font-weight:700; background:none; border:none; color:var(--text-muted); border-radius:12px; cursor:pointer;
}
.tab-btn svg{ width:22px; height:22px; }
.tab-btn[aria-current="true"]{ color:var(--primary); background:var(--primary-tint); }
.tab-sos{ color:#B3261E; }
.tab-sos[aria-current="true"]{ color:#B3261E; background:var(--danger-tint); }

/* Toast */
.toast{
  position:fixed; left:50%; bottom:calc(92px + env(safe-area-inset-bottom, 0px)); z-index:50; max-width:90%;
  -webkit-transform:translateX(-50%); transform:translateX(-50%);
  background:var(--text); color:var(--bg); font-size:14px; font-weight:700; padding:11px 18px; border-radius:14px; text-align:center;
  box-shadow:var(--shadow); opacity:0; pointer-events:none; transition:opacity .2s ease;
}
.toast.show{ opacity:1; }

/* Sign-in */
.login{ position:fixed; top:0; left:0; right:0; bottom:0; z-index:90; background:var(--bg); overflow:auto; padding:24px 16px calc(24px + env(safe-area-inset-bottom, 0px)); padding-top:calc(24px + env(safe-area-inset-top, 0px)); }
.login-box{ max-width:420px; margin:0 auto; background:var(--surface); border:1px solid var(--border); border-radius:16px; padding:20px; box-shadow:var(--shadow); }
.login-box > * + *{ margin-top:14px; }
.login-logo{ display:block; width:220px; max-width:70%; margin:0 auto; background:#fff; border-radius:10px; padding:6px; }
.login-box h2{ color:var(--primary); font-size:24px; }
.login-error{ background:var(--danger-tint); color:var(--danger); border-radius:10px; padding:10px 12px; font-weight:700; font-size:14px; }
input[type=email], input[type=password]{
  width:100%; font:inherit; font-size:16px; color:var(--text); background:var(--surface-sunken);
  border:1px solid var(--border); border-radius:10px; padding:12px; min-height:48px; -webkit-appearance:none; appearance:none;
}

/* Fatal error screen */
.fatal{ position:fixed; inset:0; top:0; left:0; right:0; bottom:0; z-index:100; background:rgba(0,0,0,.6); display:flex; align-items:center; justify-content:center; padding:16px; }
.fatal-box{ background:var(--surface); border-radius:16px; padding:20px; max-width:520px; width:100%; }
.fatal-box > * + *{ margin-top:12px; }
.fatal-box h2{ color:var(--danger); }
.fatal-box pre{ white-space:pre-wrap; word-break:break-word; background:var(--surface-sunken); padding:10px; border-radius:8px; font-size:13px; max-height:40vh; overflow:auto; }
