:root {
  --bg: #eef2f5; --surface: #ffffff; --text: #14212c; --muted: #5a6b7b; --line: #d5dde4;
  --head: #123a5a; --head-text: #ffffff; --accent: #1f6fb2; --accent-text: #ffffff;
  --ok: #1e8449; --warn: #a86400; --bad: #c0392b; --ok-bg: #e5f5ec; --warn-bg: #fdf1dc; --bad-bg: #fbe7e5;
  --me: #dcebf8; --vts: #ffffff; --pb: #1e8449; --pd: #8e44ad; --eta: #a86400; --msg: #1f6fb2;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c141b; --surface: #16222d; --text: #e6edf2; --muted: #93a6b6; --line: #273746;
    --head: #0a2437; --head-text: #e6edf2; --accent: #4aa3df; --accent-text: #06121b;
    --ok: #58d68d; --warn: #f5b041; --bad: #ec7063; --ok-bg: #12301f; --warn-bg: #3a2a0c; --bad-bg: #3b1714;
    --me: #16344d; --vts: #16222d; --pb: #3fbf73; --pd: #b27fd0; --eta: #f0a93a; --msg: #4aa3df;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 10px 16px; cursor: pointer; min-height: 44px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.small { min-height: 34px; padding: 5px 12px; font-size: 14px; }
button.wide { width: 100%; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, textarea { font: inherit; width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; color: var(--muted); font-size: 14px; }
.muted { color: var(--muted); } .small { font-size: 13.5px; }
.error { color: var(--bad); min-height: 1.3em; }

/* setup */
.setup-box { max-width: 420px; margin: 0 auto; padding: 48px 20px; text-align: center; }
.setup-logo { width: 84px; height: 84px; }
.setup-box h1 { margin: 12px 0 4px; }
#setup-code { text-align: center; font-size: 22px; letter-spacing: 2px; margin: 18px 0 12px; font-family: ui-monospace, monospace; }
button.big { width: 100%; min-height: 52px; font-size: 18px; }
.lang-switch { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.lang-switch button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* main */
#main { display: flex; flex-direction: column; height: 100%; }
.top { background: var(--head); color: var(--head-text); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
.top-row { display: flex; justify-content: space-between; align-items: center; }
.vts-name { font-weight: 700; font-size: 18px; }
.pilot-name { opacity: .85; font-size: 14px; }
.icon-btn { background: transparent; border: 0; color: var(--head-text); padding: 8px; min-height: 44px; }
.conn { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; padding: 4px 10px; border-radius: 99px;
  font-size: 13.5px; background: rgba(255,255,255,.12); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #9aa; flex: none; }
.conn.ok .dot { background: #4be08a; } .conn.warn .dot { background: #ffc04d; } .conn.bad .dot { background: #ff6b5e; }

.banner button { white-space: nowrap; flex: none; }
.banner { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 16px;
  background: var(--warn-bg); color: var(--text); border-bottom: 1px solid var(--line); font-size: 14px; }

.onboard { padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.onboard-label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.onboard-vessel { font-size: 19px; font-weight: 700; }
.onboard.none .onboard-vessel { color: var(--muted); font-weight: 500; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 10px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.act { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; min-height: 68px;
  border-width: 2px; font-size: 13px; font-weight: 600; }
.act-code { font-size: 19px; font-weight: 800; letter-spacing: .5px; }
.act.pb { border-color: var(--pb); color: var(--pb); } .act.pd { border-color: var(--pd); color: var(--pd); }
.act.eta { border-color: var(--eta); color: var(--eta); } .act.msg { border-color: var(--msg); color: var(--msg); }
.act:active { transform: scale(.97); }

.timeline { flex: 1; overflow-y: auto; padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; }
.day { align-self: center; font-size: 12.5px; color: var(--muted); margin: 6px 0; }
.bubble { max-width: 86%; padding: 9px 12px; border-radius: var(--radius); box-shadow: 0 1px 1px rgba(0,0,0,.06);
  word-wrap: break-word; }
.bubble.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 4px; }
.bubble.vts { align-self: flex-start; background: var(--vts); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.vts.unread { border-color: var(--accent); border-width: 2px; }
.bubble .who { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.bubble .meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.bubble .result { margin-top: 5px; font-size: 14px; padding: 5px 8px; border-radius: 8px; }
.result.ok { background: var(--ok-bg); color: var(--ok); } .result.bad { background: var(--bad-bg); color: var(--bad); }
.result.wait { background: var(--warn-bg); color: var(--warn); }
.bubble .sms-btn { margin-top: 6px; }
.empty { color: var(--muted); text-align: center; margin-top: 30px; font-size: 14.5px; }

/* sheets */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--surface);
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto; box-shadow: 0 -6px 24px rgba(0,0,0,.2); }
@media (min-width: 640px) { .sheet { max-width: 560px; margin: 0 auto; } }
.sheet h2 { margin: 0 0 10px; font-size: 18px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.sheet-actions button { flex: 1; }
.big-text { font-size: 19px; font-weight: 600; }
.vessel-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.vessel-list li button { width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line);
  border-radius: 0; background: transparent; padding: 10px 4px; display: flex; flex-direction: column; }
.vessel-list .vn { font-weight: 700; }
.vessel-list .vd { font-size: 13px; color: var(--muted); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.quick button { min-height: 36px; padding: 5px 12px; font-size: 14px; border-radius: 99px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1c2833; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: 90vw;
  font-size: 14.5px; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.banner.info { background: var(--me); }
#alerts-extra { color: var(--warn); }
#alerts-extra:empty { display: none; }
