/* AVA — dark maritime theme.
   Deep navy ground, brass rules and accents, muted teal for secondary signals.
   Condensed display face for headers, monospace for every number and date. */

@font-face {
  font-family: 'Oswald';
  src: url('../fonts/oswald-latin.woff2') format('woff2');
  font-weight: 200 700;          /* variable axis — one file covers every weight */
  font-style: normal;
  font-display: swap;
}

:root {
  --navy-900: #05101b;
  --navy-800: #071523;
  --navy-700: #0c1f31;
  --navy-600: #12293e;
  --navy-500: #1b354f;
  --brass: #c9a227;
  --brass-bright: #e3bd4a;
  --brass-dim: rgba(201, 162, 39, .22);
  --teal: #4d9e9a;
  --teal-dim: rgba(77, 158, 154, .18);
  --text: #e7eef6;
  --text-dim: #8ea6bb;
  --text-faint: #5f7a92;
  --danger: #e2565b;
  --amber: #e0a02e;
  --ok: #4d9e9a;
  --line: rgba(201, 162, 39, .16);
  --line-soft: rgba(255, 255, 255, .07);
  --radius: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --nav-h: 58px;

  --display: 'Oswald', 'Avenir Next Condensed', 'Roboto Condensed', 'Helvetica Neue', system-ui, sans-serif;
  --body: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy-900);
  color: var(--text);
  font: 16px/1.45 var(--body);
  overscroll-behavior-y: none;
}
body { display: flex; flex-direction: column; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── controls ────────────────────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 18px;
  background: var(--navy-700); color: var(--text);
  font-family: var(--display); font-weight: 500; font-size: 15px;
  letter-spacing: .06em; text-transform: uppercase;
  cursor: pointer; min-height: 46px;
}
.btn-primary { background: var(--brass); border-color: var(--brass); color: #1a1305; font-weight: 600; }
.btn-teal    { background: var(--teal); border-color: var(--teal); color: #04201f; font-weight: 600; }
.btn-danger  { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost   { background: transparent; border-color: transparent; color: var(--brass-bright); padding: 8px 10px; min-height: 38px; }
.btn-sm      { padding: 8px 13px; min-height: 38px; font-size: 13px; }
.btn-block   { width: 100%; }
.btn:active  { opacity: .72; }
.btn:disabled { opacity: .45; }

.field {
  width: 100%; padding: 12px 13px; border-radius: 9px;
  border: 1px solid var(--line-soft); background: var(--navy-800); color: var(--text);
  font-size: 16px; /* 16px stops iOS zooming the page on focus */
  min-width: 0;    /* flex items default to min-width:auto and refuse to shrink */
}
.field:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 2px var(--brass-dim); }
.field::placeholder { color: #55708a; }
textarea.field { min-height: 110px; resize: vertical; line-height: 1.55; }
input[type="date"].field, input[type="month"].field, input[type="number"].field { font-family: var(--mono); }
/* WebKit sizes date and month controls from their shadow content, which
   overflows a narrow flex column unless the intrinsic width is overridden. */
input[type="date"].field, input[type="month"].field {
  -webkit-appearance: none; appearance: none;
  min-width: 0; width: 100%; padding-right: 10px;
}
select.field { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--brass) 50%), linear-gradient(135deg, var(--brass) 50%, transparent 50%); background-position: right 16px center, right 11px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

.icon-btn {
  border: 0; background: transparent; font-size: 17px; line-height: 1;
  width: 38px; height: 38px; border-radius: 8px; cursor: pointer; color: var(--brass-bright);
}
.icon-btn:active { background: var(--navy-700); }

/* ── lock screen ─────────────────────────────────────────────────────────── */
.lock {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 24px);
  background:
    radial-gradient(120% 80% at 50% 0%, #0d2136 0%, transparent 60%),
    var(--navy-900);
}
.lock-inner { width: 100%; max-width: 400px; text-align: center; }
.lock-mark {
  font-family: var(--display); font-size: 62px; font-weight: 600;
  letter-spacing: .16em; color: var(--brass); margin: 0; line-height: 1;
}
.lock-rule { height: 1px; background: linear-gradient(90deg, transparent, var(--brass), transparent); margin: 14px 0 12px; }
.lock-sub { color: var(--text-dim); margin: 0 0 28px; font-size: 14px; letter-spacing: .04em; }
.lock-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.lock-error { color: var(--danger); font-size: 14px; margin: 2px 0 0; text-align: center; }
.lock-note { color: var(--text-dim); font-size: 12.5px; line-height: 1.55; margin: 6px 0 0; }
.lock-note strong { color: var(--amber); }

.strength { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-dim); font-family: var(--display); letter-spacing: .06em; text-transform: uppercase; }
.strength-bar { flex: 1; height: 4px; border-radius: 2px; background: var(--navy-700); overflow: hidden; }
.strength-bar i { display: block; height: 100%; width: 0; background: var(--danger); transition: width .2s, background .2s; }

/* ── app chrome ──────────────────────────────────────────────────────────── */
.app { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 14px) 0 calc(var(--safe-l) + 14px);
  /* Solid rather than blurred: backdrop-filter under a fixed overlay misrenders
     on some iOS builds, and the blur adds nothing on a flat dark ground. */
  background: var(--navy-900);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { font-family: var(--display); font-size: 25px; font-weight: 600; letter-spacing: .22em; color: var(--brass); margin: 0; }
.topbar-actions { display: flex; gap: 2px; }
.screen-title {
  font-family: var(--display); font-size: 13px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--text-dim); margin: 2px 0 0;
}
.searchwrap { padding: 10px 0 12px; }
.search {
  width: 100%; padding: 10px 13px; font-size: 16px;
  border-radius: 9px; border: 1px solid var(--line-soft); background: var(--navy-800); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
.search:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 2px var(--brass-dim); }

/* ── list ────────────────────────────────────────────────────────────────── */
.list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px calc(var(--safe-r) + 14px) calc(var(--safe-b) + var(--nav-h) + 84px) calc(var(--safe-l) + 14px);
  display: flex; flex-direction: column; gap: 9px;
}
.card {
  background: var(--navy-700); border: 1px solid var(--line-soft);
  border-left: 3px solid var(--brass); border-radius: var(--radius);
  padding: 12px 13px; cursor: pointer;
}
.card:active { background: var(--navy-600); }
.card.expired  { border-left-color: var(--danger); }
.card.soon     { border-left-color: var(--amber); }
.card.onboard  { border-left-color: var(--teal); }
.card.pinned   { background: linear-gradient(180deg, rgba(201,162,39,.09), transparent 60%), var(--navy-700); }

.card-head { display: flex; align-items: flex-start; gap: 9px; }
.card-title {
  font-family: var(--display); font-size: 17px; font-weight: 500; letter-spacing: .02em;
  margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--text);
}
.card-sub { color: var(--text-dim); font-size: 13px; margin: 3px 0 0; overflow-wrap: anywhere; }
.card-body { margin-top: 9px; }

/* compact data grid used by sea time rows */
.dgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px 10px; margin-top: 9px; }
.dgrid.two { grid-template-columns: repeat(2, 1fr); }
.dcell { min-width: 0; }
.dkey {
  font-family: var(--display); font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-dim); display: block; margin-bottom: 1px;
}
.dval { font-family: var(--mono); font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.dval.dim { color: var(--text-dim); }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 3px;
  font-family: var(--display); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; font-weight: 500;
  border: 1px solid currentColor; white-space: nowrap;
}
.pill-brass { color: var(--brass-bright); }
.pill-teal  { color: var(--teal); }
.pill-amber { color: var(--amber); }
.pill-danger{ color: var(--danger); }
.pill-dim   { color: var(--text-dim); }

.empty { text-align: center; color: var(--text-dim); padding: 56px 20px; }
.empty-mark { display: block; margin-bottom: 10px; opacity: .4; color: var(--brass); }
.empty h3 { font-family: var(--display); letter-spacing: .12em; text-transform: uppercase; font-size: 15px; margin: 0 0 6px; color: var(--text-dim); }
.empty p { font-size: 13.5px; margin: 0; }

/* ── sea time summary banner ─────────────────────────────────────────────── */
.summary {
  background: linear-gradient(180deg, var(--navy-600), var(--navy-700));
  border: 1px solid var(--brass-dim); border-radius: var(--radius);
  padding: 14px; margin-bottom: 4px;
}
.summary-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.summary-total { font-family: var(--mono); font-size: 27px; color: var(--brass-bright); font-variant-numeric: tabular-nums; line-height: 1.1; }
.summary-label { font-family: var(--display); font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--text-dim); }
.summary-days { font-family: var(--mono); font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.rank-row {
  display: flex; align-items: center; gap: 9px; padding: 6px 0;
  border-top: 1px solid var(--line-soft); font-size: 13px;
}
.rank-row:first-of-type { margin-top: 10px; }
.rank-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rank-days { font-family: var(--mono); color: var(--brass-bright); font-variant-numeric: tabular-nums; }
.rank-bar { height: 3px; background: var(--brass); border-radius: 2px; opacity: .55; }

/* ── grouped global search ───────────────────────────────────────────────── */
.group-head {
  display: flex; align-items: center; gap: 9px; margin: 14px 0 2px;
  font-family: var(--display); font-size: 11.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--brass);
}
.group-head:first-child { margin-top: 0; }
.group-head::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.group-count { font-family: var(--mono); color: var(--text-dim); letter-spacing: 0; }

/* ── bottom nav ──────────────────────────────────────────────────────────── */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: stretch;
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  background: var(--navy-800);
  border-top: 1px solid var(--line);
}
.nav-btn {
  flex: 1 1 0; min-width: 0; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); padding: 4px 2px; color: var(--text-faint); position: relative;
}
.nav-ico { display: flex; align-items: center; justify-content: center; height: 22px; opacity: .78; }
.nav-lab {
  font-family: var(--display); font-size: 9px; letter-spacing: .07em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.nav-btn[aria-current="page"] { color: var(--brass); }
.nav-btn[aria-current="page"] .nav-ico { opacity: 1; }
.nav-btn[aria-current="page"]::before {
  content: ''; position: absolute; top: 0; left: 22%; right: 22%; height: 2px; background: var(--brass);
}
.nav-badge {
  position: absolute; top: 5px; right: 50%; transform: translateX(19px);
  min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px;
  background: var(--danger); color: #fff;
  font-family: var(--mono); font-size: 9.5px; line-height: 15px; text-align: center;
}

/* ── FAB ─────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed; right: calc(var(--safe-r) + 16px);
  bottom: calc(var(--safe-b) + var(--nav-h) + 16px); z-index: 31;
  width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brass); color: #1a1305; font-size: 27px; line-height: 1; font-weight: 300;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .5), 0 0 0 1px rgba(227, 189, 74, .3);
}
.fab:active { transform: scale(.93); }

/* ── sheets ──────────────────────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(2, 8, 14, .72); display: flex; align-items: flex-end; }
.sheet-panel {
  background: var(--navy-800); width: 100%;
  /* Never reach under the status bar: leave the top inset clear. dvh keeps this
     honest while Safari's toolbars slide in and out. */
  max-height: calc(100vh - var(--safe-t) - 12px);
  max-height: calc(100dvh - var(--safe-t) - 12px);
  border-radius: 16px 16px 0 0; border-top: 1px solid var(--brass-dim);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .6);
  isolation: isolate;
  display: flex; flex-direction: column; animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .5; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet-panel { animation: none; } }

.sheet-bar {
  display: flex; align-items: center; justify-content: center;
  padding: 13px 14px; border-bottom: 1px solid var(--line);
  background: var(--navy-800); flex: 0 0 auto;
}
.sheet-bar strong {
  font-family: var(--display); font-size: 13px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text); text-align: center; min-width: 0;
}

/* Actions sit at the bottom: clear of the status bar, and within thumb reach.
   The bottom inset keeps them above the home indicator. */
.sheet-actions {
  display: flex; gap: 10px; flex: 0 0 auto;
  border-top: 1px solid var(--line); background: var(--navy-800);
  padding: 10px calc(var(--safe-r) + 14px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 14px);
}
.sheet-actions > .btn { flex: 1 1 0; min-width: 0; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 15px calc(var(--safe-r) + 15px) 20px calc(var(--safe-l) + 15px);
  display: flex; flex-direction: column; gap: 13px; flex: 1 1 auto; min-height: 0;
}

.label {
  font-family: var(--display); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-dim); display: block; margin-bottom: 5px;
}
.hint { color: var(--text-faint); font-size: 12px; margin: 5px 0 0; line-height: 1.5; }
.fieldrow { display: flex; gap: 9px; }
.fieldrow > div { flex: 1; min-width: 0; }

.panel { background: var(--navy-700); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 13px; }
.panel h3 { font-family: var(--display); font-size: 12.5px; letter-spacing: .14em; text-transform: uppercase; margin: 0 0 5px; color: var(--brass); }
.panel p { margin: 0 0 11px; color: var(--text-dim); font-size: 13px; line-height: 1.5; }

.contract {
  border: 1px solid var(--teal-dim); border-left: 2px solid var(--teal);
  border-radius: 9px; padding: 12px; margin-bottom: 9px; background: var(--navy-800);
}
.contract-head { display: flex; align-items: center; justify-content: between; gap: 8px; margin-bottom: 9px; }
.contract-num { font-family: var(--display); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--teal); flex: 1; }
.del-btn { border: 0; background: transparent; color: var(--danger); font-size: 19px; cursor: pointer; width: 32px; height: 32px; }

.detail-sec { border-top: 1px solid var(--line-soft); padding-top: 12px; margin-top: 2px; }
.detail-sec:first-child { border-top: 0; padding-top: 0; }
.detail-sec h4 { font-family: var(--display); font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--brass); margin: 0 0 9px; }
.link-btn { display: block; text-align: center; text-decoration: none; }

.stat { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.stat:last-child { border-bottom: 0; }
.stat > span:last-child { color: var(--text-dim); font-family: var(--mono); text-align: right; }

/* ── toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + var(--nav-h) + 78px); z-index: 60;
  background: var(--navy-600); color: var(--text); border: 1px solid var(--brass-dim);
  padding: 10px 17px; border-radius: 7px; font-size: 14px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .55); max-width: 86vw; text-align: center;
}

/* Passcode type switch on the setup screen. */
.segment {
  display: flex; gap: 4px; padding: 4px;
  background: var(--navy-800); border: 1px solid var(--line-soft); border-radius: 11px;
}
.seg {
  flex: 1; border: 0; cursor: pointer; border-radius: 8px; padding: 10px 8px; min-height: 42px;
  background: transparent; color: var(--text-dim);
  font-family: var(--display); font-size: 13px; letter-spacing: .1em; text-transform: uppercase;
}
.seg[aria-checked="true"] { background: var(--brass); color: #1a1305; font-weight: 600; }

/* ── document viewer ─────────────────────────────────────────────────────── */
.viewer-panel { height: calc(100dvh - var(--safe-t) - 12px); }
.viewer-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--navy-900);
  padding: 10px calc(var(--safe-r) + 8px) 10px calc(var(--safe-l) + 8px);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.viewer-page {
  width: 100%; height: auto; display: block; border-radius: 4px;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .5);
}
.viewer-image { max-width: 100%; height: auto; border-radius: 6px; }
