:root {
  --navy: #0B2545;
  --navy-deep: #071A33;
  --teal: #1B4B5A;
  --mist: #EDF1EE;
  --paper: #F7F5EF;
  --brass: #C08A4E;
  --rust: #B5482A;
  --ink: #1B2430;
  --line: #D8DCD3;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Source Sans 3', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
}
.hidden { display: none !important; }

/* ---- Brand ---- */
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 44px; height: 44px; color: var(--brass); flex-shrink: 0; }
.brand-mark.small { width: 32px; height: 32px; }
.brand h1 { font-family: var(--font-display); font-size: 1.6rem; margin: 0; color: var(--navy); letter-spacing: 0.01em; }
.topbar .brand h1 { font-size: 1.25rem; }
.eyebrow { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--teal); margin: 2px 0 0; }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, var(--teal), var(--navy-deep) 70%);
  padding: 24px;
}
.login-card {
  background: var(--paper);
  border-radius: 4px;
  padding: 40px 36px;
  width: 100%; max-width: 380px;
  box-shadow: 0 30px 60px rgba(0,0,0,0.35);
  border-top: 4px solid var(--brass);
  overflow: hidden;
}
.boat-photo {
  display: block;
  width: calc(100% + 72px);
  margin: -40px -36px 20px;
  height: 160px;
  object-fit: cover;
}
.login-copy { color: var(--teal); margin: 18px 0 14px; font-size: 0.95rem; }
.login-users { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 4px;
  cursor: pointer; background: #fff; font-family: var(--font-body); font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
}
.user-chip:hover { border-color: var(--brass); }
.user-chip.selected { border-color: var(--brass); background: #FBF3E8; font-weight: 600; }
.user-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.pin-input {
  width: 100%; padding: 12px; font-size: 1.1rem; letter-spacing: 0.3em; text-align: center;
  border: 1px solid var(--line); border-radius: 4px; margin-bottom: 14px; font-family: var(--font-mono);
}
.login-error { color: var(--rust); font-size: 0.85rem; min-height: 1.2em; }

/* ---- App shell ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: #fff; padding: 14px 28px;
}
.topbar .brand-mark { color: var(--brass); }
.topbar .brand h1 { color: #fff; }
.topbar .eyebrow { color: #9FC6C9; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.who-am-i { font-family: var(--font-mono); font-size: 0.85rem; color: #CFE0DF; }

.tabs {
  display: flex; gap: 2px; background: var(--teal); padding: 0 24px;
  overflow-x: auto;
}
.tab {
  background: transparent; border: none; color: #D6E4E3; padding: 12px 18px;
  font-family: var(--font-body); font-weight: 600; font-size: 0.88rem; cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: var(--brass); }

.content { max-width: 980px; margin: 0 auto; padding: 28px 24px 80px; }
.panel { display: none; }
.panel.active { display: block; }
.panel-head { margin-bottom: 18px; }
.panel-head h2 { font-family: var(--font-display); font-size: 1.5rem; color: var(--navy); margin: 0 0 4px; }
.panel-sub { color: #5A6B72; margin: 0; font-size: 0.92rem; }

/* ---- Legend ---- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 18px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--teal); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ---- Forms ---- */
.inline-form {
  display: flex; flex-wrap: wrap; align-items: end; gap: 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 4px;
  padding: 16px; margin-bottom: 20px;
}
.inline-form label {
  display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem;
  color: var(--teal); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
}
.inline-form .grow { flex: 1; min-width: 180px; }
.inline-form input {
  border: 1px solid var(--line); border-radius: 3px; padding: 8px 10px;
  font-family: var(--font-body); font-size: 0.92rem; color: var(--ink);
}
.inline-form input:focus { outline: 2px solid var(--brass); outline-offset: 1px; }

.btn {
  border: none; border-radius: 3px; padding: 9px 18px; font-weight: 700;
  font-size: 0.85rem; cursor: pointer; font-family: var(--font-body);
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-deep); }
.btn-ghost { background: transparent; color: #D6E4E3; border: 1px solid rgba(255,255,255,0.3); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-del {
  background: transparent; color: var(--rust); border: 1px solid var(--rust);
  padding: 4px 10px; font-size: 0.75rem; border-radius: 3px; cursor: pointer;
}

/* ---- Ledger rows ---- */
.ledger { display: flex; flex-direction: column; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.ledger-row {
  background: #fff; padding: 12px 16px; display: flex; align-items: center; gap: 12px;
}
.ledger-row.low-stock { background: #FBEDE7; }
.row-color { width: 4px; align-self: stretch; border-radius: 2px; flex-shrink: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 0.94rem; color: var(--ink); }
.row-meta { font-family: var(--font-mono); font-size: 0.76rem; color: #7A8890; margin-top: 2px; }
.row-note { font-size: 0.85rem; color: #4A5A61; margin-top: 3px; font-style: italic; }
.empty-state { padding: 24px; text-align: center; color: #8A98A0; font-size: 0.9rem; background: #fff; }

.totals { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 16px; }
.total-card { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 12px 16px; min-width: 140px; }
.total-card .num { font-family: var(--font-mono); font-size: 1.3rem; font-weight: 600; color: var(--navy); }
.total-card .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: #7A8890; }

.saved-msg { color: var(--teal); font-size: 0.85rem; min-height: 1.2em; }
.hint { font-size: 0.8rem; color: #7A8890; margin: -10px 0 18px; }

/* ---- Entitlements ---- */
.usage-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 24px; }
.usage-card { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 16px; border-top: 3px solid var(--brass); }
.usage-card-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 2px; display: flex; align-items: center; gap: 8px; }
.usage-card-shares { font-size: 0.75rem; color: #7A8890; margin-bottom: 12px; }
.usage-row { margin-bottom: 10px; }
.usage-row-label { display: flex; justify-content: space-between; font-size: 0.76rem; color: var(--teal); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; margin-bottom: 4px; }
.usage-bar-track { height: 8px; background: var(--mist); border-radius: 4px; overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: 4px; }
.usage-period-title { font-family: var(--font-mono); font-size: 0.72rem; color: #8A98A0; margin: 12px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; }

.rules-box { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 20px 22px; margin-top: 8px; }
.rules-box h3 { font-family: var(--font-display); color: var(--navy); font-size: 1.1rem; margin: 0 0 10px; }
.rules-box h3:not(:first-child) { margin-top: 22px; }
.rules-box ul { margin: 0; padding-left: 20px; }
.rules-box li { margin-bottom: 8px; font-size: 0.9rem; line-height: 1.5; color: var(--ink); }
.rules-box p { font-size: 0.9rem; line-height: 1.55; color: var(--ink); margin: 0; }

/* ---- Ballots ---- */
.ballot-row { flex-wrap: wrap; }
.ballot-status { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 3px 8px; border-radius: 10px; }
.ballot-status.open { background: #E4F0EC; color: var(--teal); }
.ballot-status.closed { background: #F0E6D8; color: var(--brass); }
.ballot-entrants { font-size: 0.8rem; color: #5A6B72; margin-top: 4px; }
.ballot-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-small { border: 1px solid var(--navy); color: var(--navy); background: #fff; padding: 5px 12px; font-size: 0.76rem; font-weight: 700; border-radius: 3px; cursor: pointer; }
.btn-small:hover { background: var(--mist); }
.btn-small:disabled { opacity: 0.4; cursor: not-allowed; }
.ics-link { font-size: 0.76rem; color: var(--teal); text-decoration: none; font-weight: 600; border: 1px solid var(--teal); padding: 5px 10px; border-radius: 3px; }
.ics-link:hover { background: var(--mist); }
.transfer-select { font-size: 0.78rem; padding: 5px; border: 1px solid var(--line); border-radius: 3px; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .content { padding: 20px 14px 60px; }
  .inline-form { flex-direction: column; align-items: stretch; }
}
