:root {
  --navy: #0b2545;
  --accent: #e8702a;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #16202c;
  --muted: #6b7684;
  --line: #dde2e8;
  --ok: #1f9d55;
  --warn: #d98b00;
  --bad: #d64545;
  --primary: #13427a;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b; --card: #18212c; --text: #e8edf2; --muted: #93a0ae; --line: #2a3644;
    --primary: #3b82d6; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.two .input { min-width: 0; }
.block { display: block; width: 100%; }

/* Inputs — 16px+ so iOS doesn't zoom on focus */
.input, .field input, .search {
  width: 100%; font-size: 17px; padding: 12px 12px; min-height: 48px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat; padding-right: 32px;
}
textarea.input { min-height: 64px; resize: vertical; font-family: inherit; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.input:focus, .search:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px; min-height: 48px;
  cursor: pointer; color: var(--text); background: var(--line);
}
.btn-lg { font-size: 18px; min-height: 56px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { filter: brightness(0.9); }
.btn-outline { background: transparent; border: 2px dashed var(--line); color: var(--primary); margin-top: 12px; }
.btn-danger { background: transparent; color: var(--bad); border: 2px solid var(--bad); }
.btn-danger.armed { background: var(--bad); color: #fff; }
.btn:disabled { opacity: 0.55; }
.linkish { background: none; border: 0; color: var(--primary); font: inherit; padding: 8px 0; text-align: left; cursor: pointer; }
.icon-btn {
  background: none; border: 0; color: inherit; font-size: 24px; min-width: 44px; min-height: 44px;
  cursor: pointer; padding: 0;
}
.icon-btn.small { font-size: 20px; min-width: 32px; min-height: 32px; }

/* Login */
.login-wrap { max-width: 380px; margin: 0 auto; padding: calc(48px + env(safe-area-inset-top)) 20px 24px; text-align: center; }
.login-wrap h1 { margin: 12px 0 2px; }
.login-wrap form { margin-top: 24px; text-align: left; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; }
.msg { padding: 10px 12px; border-radius: 10px; background: #fdecec; color: #8a1f1f; font-size: 0.95rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 6px;
  background: var(--navy); color: #fff;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px 12px;
}
.topbar .muted { color: #b6c3d4; }
.topbar-title { flex: 1; min-width: 0; }
#title-main { font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#title-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  font: inherit; font-size: 0.78rem; font-weight: 600; border: 0; border-radius: 999px; padding: 6px 10px;
  background: rgba(255,255,255,0.14); color: #fff; white-space: nowrap; cursor: pointer;
}
.pill::before { content: "●"; margin-right: 5px; }
.pill.ok::before { color: #4ade80; }
.pill.warn::before { color: #fbbf24; }
.pill.bad::before { color: #f87171; }
.pill.busy::before { content: "↻"; display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  display: flex; align-items: center; gap: 8px; margin: 10px 12px 0; padding: 10px 12px;
  border-radius: 10px; background: #fff6e0; color: #6a4a00; font-size: 0.9rem;
}

.view { padding: 12px; max-width: 640px; margin: 0 auto; }
.search { margin-bottom: 12px; }

/* Area tabs */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--line); padding: 4px; border-radius: 12px; margin-bottom: 12px; }
.seg button {
  font: inherit; font-weight: 600; border: 0; border-radius: 9px; padding: 10px 4px; min-height: 44px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.seg .cnt { font-weight: 400; font-size: 0.8rem; opacity: 0.8; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); color: var(--text); border: 0; border-radius: var(--radius);
  padding: 12px 14px; min-height: 60px; font: inherit; cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.row:active { filter: brightness(0.96); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-count { font-weight: 700; color: var(--muted); min-width: 28px; text-align: right; }
.row.sub { margin-left: 18px; min-height: 52px; }
.chev { color: var(--muted); font-size: 1.2rem; }
.thumb {
  width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; background: var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--muted);
}
.tag { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; margin-left: 4px; vertical-align: middle; }
.tag.pending { background: #fff1d6; color: #8a5a00; }
.tag.error { background: #fde2e2; color: #9b1c1c; }
.tag.pub { background: #fff1d6; color: #8a5a00; }
.dot-pending { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); flex: none; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.section-h { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 4px 8px; }
.group-h { font-size: 0.8rem; font-weight: 700; color: var(--muted); margin: 10px 4px 0; }

/* Quick-add card */
.card { background: var(--card); border-radius: var(--radius); padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.add-card { display: flex; flex-direction: column; gap: 10px; }
.add-row { display: flex; gap: 10px; }
.add-fields { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.photo-tile {
  width: 104px; flex: none; border: 2px dashed var(--line); border-radius: 12px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; text-align: center; cursor: pointer;
  font-size: 30px; line-height: 1.1; color: var(--muted); position: relative; min-height: 104px;
}
.photo-tile small { font-size: 0.8rem; }
.photo-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-tile.has-photo { border-style: solid; border-color: var(--primary); }
.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* Sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; -webkit-overflow-scrolling: touch;
}
.sheet-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 0 14px; }
.sheet .attrib { margin: -8px 0 14px; }
.docs { margin-top: 18px; border-top: 1px solid var(--line); }
.docs .section-h { margin-top: 14px; }
.doc-list { margin-bottom: 12px; }
.doc-row { gap: 8px; }
.doc-row .doc-open { color: inherit; text-decoration: none; min-width: 0; }
.doc-row .row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-row .doc-del { padding: 6px 10px; min-height: 36px; font-size: 0.85rem; flex-shrink: 0; }
.doc-form { margin-top: 8px; }
.sheet-photo { width: 100%; max-height: 260px; object-fit: contain; border-radius: 12px; background: var(--line); }
.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }
.menu-item { display: block; width: 100%; text-align: left; margin-bottom: 8px; color: inherit; text-decoration: none; box-sizing: border-box; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom));
  background: #1c2733; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60;
  font-weight: 600; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

/* Boat map (bow up, port on the left) */
.seg.seg-sm { grid-template-columns: repeat(2, 1fr); width: 60%; margin: -4px auto 12px; }
.seg.seg-sm button { padding: 6px 8px; font-size: 0.85rem; min-height: 34px; }
.boat-map { position: relative; background: #fff; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; margin-bottom: 12px; user-select: none; -webkit-user-select: none; }
.plan-img { display: block; width: 100%; height: auto; pointer-events: none; }
.pin {
  position: absolute; width: 15px; height: 15px; margin: -7.5px 0 0 -7.5px; padding: 0; border-radius: 50%; cursor: pointer;
  background: #13427a; border: 2.5px solid #fff; box-shadow: 0 0 0 1px rgba(11, 37, 69, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);
}
.pin::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; }  /* bigger tap target */
.pin.has { background: var(--accent); }
.plbl {
  position: absolute; transform: translateY(-50%); white-space: nowrap; border: 0; cursor: pointer; margin: 0;
  font: 600 10.5px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: #0b2545;
  background: rgba(255, 255, 255, 0.94); border-radius: 999px; padding: 5px 7px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.plbl.has { background: #fde8db; }
.plbl .n { display: inline-block; margin-left: 4px; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 5px; font-size: 9.5px; }
.plbl:active, .pin:active { filter: brightness(0.9); }
.map-tag { position: absolute; font: 700 10px/1 -apple-system, sans-serif; letter-spacing: 0.08em; color: #6b7684; background: rgba(255,255,255,0.85); padding: 2px 5px; border-radius: 4px; }
.map-tag.bow { top: 6px; left: 50%; transform: translateX(-50%); }
.map-tag.port { top: 6px; left: 6px; }
.map-tag.stbd { top: 6px; right: 6px; }
#map-extra .list { margin-bottom: 12px; }
#loc-spots .btn { margin-bottom: 14px; }
#loc-spots .list { margin-bottom: 10px; }
