:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f6fde;
  --primary-ink: #ffffff;
  --primary-soft: #e8f1fd;
  --sidebar: #0b1a2e;
  --sidebar-ink: #c7d2e1;
  --sidebar-active: #18304f;
  --good: #15803d; --good-soft: #dcfce7;
  --bad: #b91c1c;  --bad-soft: #fee2e2;
  --warn: #b45309; --warn-soft: #fef3c7;
  --info: #1d4ed8; --info-soft: #dbeafe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not(.report-root) {
    --bg: #0b1220; --surface: #111a2b; --surface-2: #0f1727; --border: #22314a; --text: #e5edf7; --muted: #8fa1ba;
    --primary: #3b8cf0; --primary-soft: #14263f; --sidebar: #070e1a; --sidebar-active: #13243d;
    --good: #4ade80; --good-soft: #0f2d1b; --bad: #f87171; --bad-soft: #3a1414; --warn: #fbbf24; --warn-soft: #3a2a0c;
    --info: #93c5fd; --info-soft: #132a4a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 13px; margin: 0 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
code.secret { font-size: 16px; padding: 4px 8px; background: var(--warn-soft); border-radius: 6px; user-select: all; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pre { white-space: pre-wrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.bad-text { color: var(--bad); }
.good-text { color: var(--good); }
.inline { display: inline; }
.icon { flex: none; vertical-align: middle; }

/* ---- App shell ---- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 236px; background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex: none; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; }
.brand.center { justify-content: center; padding: 0 0 12px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #f59e0b, #ef4444); color: #fff; display: grid; place-items: center; flex: none; }
.brand-name { font-weight: 700; color: #fff; line-height: 1.2; }
.bare .brand-name { color: var(--text); font-size: 18px; }
.brand-sub { font-size: 11px; color: #8aa0bd; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
.sidebar nav a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-ink); font-weight: 500; }
.sidebar nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #f59e0b; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6b819e; padding: 14px 10px 4px; }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-top: 1px solid #1b2c45; }
.sidebar-foot .me { color: var(--sidebar-ink); display: flex; gap: 8px; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sidebar-foot button.link { color: var(--sidebar-ink); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.topbar { display: none; }
.nav-toggle { display: none; }
.viewing-as { background: var(--warn-soft); color: var(--warn); padding: 8px 28px; font-size: 13px; }
.viewing-as button.link { color: var(--warn); font-weight: 600; margin-left: 8px; }

/* ---- Page parts ---- */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-header .subtitle { margin: 4px 0 0; color: var(--muted); }
.page-header .back { font-size: 12px; color: var(--muted); display: inline-block; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px 18px; }
.stack { display: flex; flex-direction: column; gap: 0; }
.stack.narrow { max-width: 420px; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-sidebar { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 18px; align-items: start; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-good { background: var(--good-soft); color: var(--good); }
.flash-bad { background: var(--bad-soft); color: var(--bad); }
.flash-info { background: var(--info-soft); color: var(--info); }
.alert-box { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; }
.alert-box ul { margin: 4px 0 0; padding-left: 18px; }
.alert-box a { color: inherit; text-decoration: underline; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.danger-zone { margin-top: 24px; text-align: right; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs a.active { color: var(--text); border-color: var(--primary); }

/* ---- KPIs ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--text); display: block; border-top: 3px solid var(--border); }
a.kpi:hover { text-decoration: none; border-color: var(--primary); }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.kpi-hint { font-size: 12px; color: var(--muted); }
.kpi-good { border-top-color: var(--good); } .kpi-good .kpi-value { color: var(--good); }
.kpi-bad { border-top-color: var(--bad); } .kpi-bad .kpi-value { color: var(--bad); }
.kpi-warn { border-top-color: var(--warn); } .kpi-warn .kpi-value { color: var(--warn); }
.small-kpis { grid-template-columns: repeat(4, 1fr); }
.small-kpis .kpi { padding: 10px 12px; box-shadow: none; }
.small-kpis .kpi-value { font-size: 20px; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.tag-dot { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.tag-dot::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: currentColor; }
.tag-red { color: #dc2626; } .tag-green { color: #16a34a; } .tag-blue { color: #2563eb; } .tag-yellow { color: #ca8a04; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table.compact td { padding: 6px 8px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.inactive { opacity: .55; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border: 0; }
.list .badge { margin-left: 6px; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }

/* ---- Forms ---- */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; min-height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 12.5px; }
.field-check { justify-content: flex-end; }
.field-check label { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.req { color: var(--bad); margin-left: 2px; }
.help { color: var(--muted); font-size: 11.5px; }
.error { color: var(--bad); font-size: 12px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); }
.form-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 12.5px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters select, .filters input[type=date] { width: auto; }
.search-input { position: relative; flex: 1; min-width: 200px; }
.search-input .icon { position: absolute; left: 10px; top: 11px; color: var(--muted); }
.search-input input { padding-left: 32px; }
.btn { display: inline-flex; align-items: center; gap: 6px; justify-content: center; padding: 8px 14px; min-height: 38px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: 12.5px; }
.btn-lg { padding: 12px 22px; font-size: 16px; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
.industry-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.industry-option { display: flex; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; }
.industry-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.industry-option p { margin: 4px 0 0; }
.activity-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.activity-form .row { display: flex; gap: 8px; }
.activity-form .row > select { width: auto; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-top: 1px solid var(--border); }
.timeline li.done { opacity: .55; }
.timeline .tl-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.entry-card { border-color: var(--primary); }

/* ---- Photos / capture ---- */
.photo-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.photo-form input[name=caption] { flex: 1; min-width: 160px; width: auto; }
.camera-btn { cursor: pointer; }
.camera-btn.has-file { border-color: var(--good); color: var(--good); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photo-grid figure { margin: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.photo-grid img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.photo-grid figcaption { padding: 6px 8px; font-size: 12.5px; }
.camera-drop { display: grid; place-items: center; border: 2px dashed var(--border); border-radius: 12px; min-height: 180px; margin-bottom: 16px; cursor: pointer; overflow: hidden; background: var(--surface-2); position: relative; }
.camera-drop img { width: 100%; max-height: 360px; object-fit: contain; }
.camera-cta { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; }
.camera-drop img:not([hidden]) + .camera-cta { display: none; }

/* ---- Auth pages ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-title { font-size: 20px; margin: 4px 0 12px; text-align: center; }
.auth-card .stack { gap: 12px; }

/* ---- Report (print) ---- */
body.report { background: #e5e7eb; color: #111; color-scheme: light; --text: #111; --muted: #555; --border: #d1d5db; --surface: #fff; --surface-2: #f3f4f6; --bad: #b91c1c; --good: #15803d; }
.report-toolbar { display: flex; gap: 8px; justify-content: center; padding: 12px; }
.report-page { background: #fff; max-width: 1100px; margin: 0 auto 40px; padding: 32px 36px; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.report-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid #111; padding-bottom: 14px; margin-bottom: 18px; }
.report-head h1 { font-size: 22px; }
.report-head h2 { font-size: 18px; margin-bottom: 6px; }
.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.report-page section { margin-bottom: 18px; }
.report-page .table th, .report-page .table td { font-size: 11px; padding: 4px 6px; }
.report-foot { border-top: 1px solid #ccc; padding-top: 12px; font-size: 12px; }
.report-foot .sign { display: flex; gap: 40px; margin: 24px 0 12px; }
@media print {
  body.report { background: #fff; }
  .no-print { display: none !important; }
  .report-page { box-shadow: none; padding: 0; margin: 0; max-width: none; }
  .report-page tr { break-inside: avoid; }
  @page { size: A4 landscape; margin: 12mm; }
}

/* ---- Responsive ---- */
@media (max-width: 960px) {
  .grid-2, .grid-sidebar { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .nav-toggle:checked ~ .sidebar { transform: none; }
  .topbar { display: flex; align-items: center; gap: 12px; background: var(--sidebar); color: #fff; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 40; }
  .menu-btn { cursor: pointer; display: grid; place-items: center; }
  .topbar-title { font-weight: 700; }
  .content { padding: 16px 14px 80px; }
  .viewing-as { padding: 8px 14px; }
  .page-header { align-items: flex-start; }
  h1 { font-size: 19px; }
  .card-body { padding: 14px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .small-kpis { grid-template-columns: repeat(2, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom */
  .sticky-actions { position: sticky; bottom: 0; background: var(--surface); padding: 12px 0 max(12px, env(safe-area-inset-bottom)); margin-bottom: -16px; border-top: 1px solid var(--border); }
  .sticky-actions .btn { flex: 1; }
  .report-grid { grid-template-columns: 1fr; }
  .activity-form .row { flex-wrap: wrap; }
}

/* ---- Bar chart (single series) ---- */
.chart { margin: 0; }
.chart-plot { display: flex; gap: 8px; height: 180px; }
.chart-axis { display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--muted); text-align: right; padding-bottom: 20px; min-width: 24px; font-variant-numeric: tabular-nums; }
.chart-bars { flex: 1; display: flex; gap: 2px; align-items: stretch; border-bottom: 1px solid var(--border); background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(50% - 1px), var(--border) calc(50% - 1px), var(--border) 50%) 0 0 / 100% calc(100% - 20px) no-repeat; padding-bottom: 20px; position: relative; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; min-width: 0; outline: none; }
.chart-bar { width: min(70%, 28px); background: var(--primary); border-radius: 4px 4px 0 0; min-height: 0; transition: filter .15s; }
.chart-x { position: absolute; bottom: -20px; font-size: 11px; color: var(--muted); }
.chart-col:hover .chart-bar, .chart-col:focus .chart-bar { filter: brightness(1.2); }
.chart-col:hover::after, .chart-col:focus::after { content: attr(data-tip); position: absolute; bottom: calc(100% - 10px); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 2; pointer-events: none; }
.chart-empty { margin: 8px 0 0; }
.chart-table { margin-top: 10px; }
.chart-table summary { cursor: pointer; }
