/* Field-first styling: dark by default (tunnels, night shifts), big targets,
   nothing smaller than 16px so iOS never zooms on focus. */

:root {
  --bg: #12161c;
  --bg-2: #1a2028;
  --bg-3: #232b35;
  --line: #313b47;
  --fg: #e8edf3;
  --fg-dim: #98a5b3;
  --accent: #f0a33c;
  --accent-2: #5b9bd5;
  --danger: #e06c5a;
  --ok: #5fbf7f;
  --bar-h: 62px;
  --cap-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8; --bg-2: #ffffff; --bg-3: #eaeef2;
    --line: #d3dae1; --fg: #182029; --fg-dim: #5d6b7a;
    --accent: #c97a12; --accent-2: #2d6fa8;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; min-width: 0; text-align: center; }
.topbar-title > div:first-child {
  font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sub { font-size: 12px; color: var(--fg-dim); }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  background: transparent; border: 0; color: var(--fg);
  font-size: 22px; border-radius: 10px;
}
.icon-btn:active { background: var(--bg-3); }

/* ------------------------------------------------------------------- pages */
#main {
  padding: 14px 12px calc(var(--bar-h) + var(--cap-h) + var(--safe-b) + 24px);
}
.page[hidden] { display: none; }
h3 { margin: 22px 0 8px; font-size: 15px; text-transform: uppercase;
     letter-spacing: .06em; color: var(--fg-dim); }
.hint { color: var(--fg-dim); font-size: 14px; margin: 6px 0 14px; }
.hint.legal { margin-top: 26px; font-size: 12px; line-height: 1.5; }

/* ------------------------------------------------------------------ fields */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--fg-dim); margin-bottom: 5px; }
input[type=text], input[type=url], input[type=date], select, textarea {
  width: 100%; font: inherit; font-size: 16px;
  color: var(--fg); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; appearance: none;
}
textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240,163,60,.18);
}
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.permission-box {
  margin-top: 26px; padding: 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line);
}
.permission-box h3 { margin-top: 0; }

/* ---------------------------------------------------------------- buttons */
button { font: inherit; }
.primary, .secondary, .danger {
  display: block; width: 100%; margin: 10px 0;
  padding: 15px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--fg); font-weight: 600;
}
.primary { background: var(--accent); border-color: var(--accent); color: #1a1206; }
.primary.big { padding: 18px; font-size: 17px; }
.danger { color: var(--danger); }
button:active { opacity: .75; }
button:disabled { opacity: .45; }

/* ------------------------------------------------------------- timeline */
.timeline { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden;
}
.card.heading { border-left: 4px solid var(--accent-2); }
.card.photo   { border-left: 4px solid var(--ok); }
.card.note    { border-left: 4px solid var(--accent); }
.card.bullets { border-left: 4px solid #9b7fd4; }

.card-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--bg-3); font-size: 13px; color: var(--fg-dim);
}
.card-head .kind { font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.card-head .spacer { flex: 1; }
.card-head button {
  width: 38px; height: 38px; border: 0; background: transparent;
  color: var(--fg-dim); font-size: 17px; border-radius: 8px;
}
.card-head button:active { background: var(--line); }
.card-body { padding: 10px; }
.card-body textarea { min-height: 90px; }

.lvl-row { display: flex; gap: 6px; margin-bottom: 8px; }
.lvl-row button {
  flex: 1; padding: 9px 0; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--fg-dim);
  font-size: 13px; font-weight: 600;
}
.lvl-row button.on { background: var(--accent-2); border-color: var(--accent-2); color: #08111a; }

.card-body img {
  display: block; width: 100%; height: auto; border-radius: 8px;
  background: var(--bg-3); margin-bottom: 8px;
}

.dictate-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.mic {
  flex: none; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--fg); font-weight: 600;
}
.mic.rec { background: var(--danger); border-color: var(--danger); color: #fff; }
.dictate-row .tip { font-size: 12px; color: var(--fg-dim); line-height: 1.35; }

.empty { text-align: center; padding: 50px 20px; color: var(--fg-dim); }

/* -------------------------------------------------------------- capture bar */
.capture-bar {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--bar-h) + var(--safe-b));
  z-index: 25; display: flex; gap: 6px; padding: 7px 8px;
  background: var(--bg-2); border-top: 1px solid var(--line);
}
.capture-bar[hidden] { display: none; }
.cap {
  flex: 1; min-width: 0; height: 54px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg-3); color: var(--fg); font-size: 11px; font-weight: 600;
}
.cap .ico { font-size: 20px; line-height: 1; }
.cap:active { background: var(--accent); color: #1a1206; }

/* ------------------------------------------------------------------ tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 26;
  display: flex; height: calc(var(--bar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--bg-2); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; border: 0; background: transparent; color: var(--fg-dim);
  font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tab .ico { font-size: 21px; line-height: 1; }
.tab.is-active { color: var(--accent); }

/* ------------------------------------------------------------------ export */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 8px; text-align: center;
}
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 11px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: .05em; }

.outline {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; font-size: 14px;
}
.outline .o { padding: 3px 0; color: var(--fg-dim); }
.outline .o.h1 { color: var(--fg); font-weight: 700; padding-left: 0; }
.outline .o.h2 { padding-left: 14px; color: var(--fg); }
.outline .o.h3 { padding-left: 28px; }
.outline .o.h4 { padding-left: 42px; }
.outline .o.body { padding-left: 56px; font-size: 13px; }

.build-status { font-size: 14px; color: var(--fg-dim); min-height: 22px; }
.build-status.err { color: var(--danger); }
.build-status.ok { color: var(--ok); }
.hint.ok-text { color: var(--ok); }
.hint.err-text { color: var(--danger); }

/* ------------------------------------------------------------------ modals */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.55); display: flex; align-items: flex-end;
}
.modal[hidden] { display: none; }
.sheet {
  width: 100%; max-height: 88vh; overflow: auto;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 18px 14px calc(18px + var(--safe-b));
  border-top: 1px solid var(--line);
}
.sheet h2 { margin: 0 0 14px; font-size: 19px; }
.report-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.report-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px;
}
.report-row.on { border-color: var(--accent); }
.report-row .meta { flex: 1; min-width: 0; }
.report-row .meta b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.report-row .meta span { font-size: 12px; color: var(--fg-dim); }
.report-row button { width: 40px; height: 40px; border: 0; background: transparent;
  color: var(--fg-dim); font-size: 18px; border-radius: 8px; }

/* ------------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bar-h) + var(--cap-h) + var(--safe-b) + 16px);
  z-index: 80; max-width: 90vw;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 22px;
  padding: 11px 18px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.toast[hidden] { display: none; }
