/* ── Design Tokens ──────────────────────────────────────────────── */
:root {
  color-scheme: light dark;
  --bg: #f4f8ff;
  --surface: #ffffff;
  --border: #dbe7f8;
  --border-light: #edf4ff;

  --text: #0d1b2f;
  --text-2: #1c3557;
  --muted: #60728d;
  --faint: #95a6bd;

  --brand: #0055c7;
  --brand-dark: #003f94;
  --brand-rgb: 0,85,199;
  --brand-gold: #f6c445;
  --brand-cream: #ffffff;
  --brand-ink: #062348;
  --hero-gradient-end: #0b3c78;

  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --ok-border: #bbf7d0;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --bad-border: #fecaca;
  --info: #0055c7;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;
  --neutral-bg: #f0f6ff;
  --neutral-border: #dbe7f8;

  --sidebar-w: 220px;
  --topbar-h: 64px;
  --m-topbar-h: 52px;
  --bottomnav-h: 64px;

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  --shadow-sm: 0 1px 2px 0 rgba(12,42,78,.06);
  --shadow: 0 1px 3px 0 rgba(12,42,78,.08), 0 1px 2px -1px rgba(12,42,78,.06);
  --shadow-md: 0 4px 6px -1px rgba(12,42,78,.08), 0 2px 4px -2px rgba(12,42,78,.05);
  --shadow-lg: 0 10px 15px -3px rgba(12,42,78,.08), 0 4px 6px -4px rgba(12,42,78,.05);

  --font: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  --font-mono: 'Courier New', Courier, monospace;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; appearance: none; -webkit-appearance: none; }
input, textarea, select { font-family: inherit; font-size: inherit; }
img, svg { display: block; max-width: 100%; }
table { border-collapse: collapse; width: 100%; }
ul, ol { list-style: none; }

/* ── Utility ────────────────────────────────────────────────────── */
.mono { font-family: var(--font-mono); font-size: .875em; letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* ── Avatar ─────────────────────────────────────────────────────── */
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; letter-spacing: .04em;
  flex-shrink: 0; user-select: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: 11px; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

/* ── Brand mark ─────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-glyph { flex-shrink: 0; color: var(--brand); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-size: 15px; font-weight: 800; color: var(--text); letter-spacing: -.01em; }
.brand-sub { font-size: 10.5px; color: var(--muted); font-weight: 500; }

/* ── Card ───────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.card-interactive {
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s, transform .1s;
  display: block;
}
.card-interactive:hover { box-shadow: var(--shadow-md); border-color: #d1d5db; }
.card-interactive:active { transform: scale(.997); }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  font-family: var(--font); font-size: 14px; font-weight: 600;
  border-radius: var(--r-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
  text-decoration: none; white-space: nowrap; line-height: 1.4;
}
.btn svg { flex-shrink: 0; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-primary:active { opacity: .9; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--neutral-bg); }
.btn-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.btn-warn:hover { filter: brightness(.95); }
.btn-ghost-warn { background: transparent; color: var(--warn); border-color: var(--warn-border); }
.btn-ghost-warn:hover { background: var(--warn-bg); }
.btn-ghost-on-dark {
  background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25);
}
.btn-ghost-on-dark:hover { background: rgba(255,255,255,.22); }
.btn-text {
  background: transparent; color: var(--muted);
  border-color: transparent; padding: 6px 8px;
}
.btn-text:hover { color: var(--text); background: var(--neutral-bg); }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn-lg { padding: 12px 24px; font-size: 15px; border-radius: var(--r); }
.btn-full { width: 100%; }

/* ── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; line-height: 1.4;
  border: 1px solid transparent;
}
.badge-sm { padding: 2px 7px; font-size: 11px; gap: 4px; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-neutral { background: var(--neutral-bg); color: var(--muted); border-color: var(--neutral-border); }
.badge-info { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.badge-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-border); }

/* ── Form fields ────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 13.5px; font-weight: 600; color: var(--text-2);
  display: flex; align-items: center; justify-content: space-between;
}
.field-link { font-size: 12px; font-weight: 500; color: var(--brand); }
.field-input {
  display: flex; align-items: stretch;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.field-input:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb),.1);
}
.field-input input,
.field-input textarea {
  flex: 1; padding: 10px 12px;
  border: none; outline: none;
  font-size: 14.5px; background: transparent; color: var(--text);
  line-height: 1.4;
}
.field-input textarea { resize: vertical; min-height: 80px; }
.field-prefix {
  padding: 10px 12px;
  background: var(--neutral-bg);
  border-right: 1.5px solid var(--border);
  font-size: 14px; font-weight: 600; color: var(--muted);
  white-space: nowrap; display: flex; align-items: center;
}

/* ── Language switch ────────────────────────────────────────────── */
.lang-switch {
  display: flex; gap: 1px;
  background: var(--border);
  border-radius: var(--r-sm); overflow: hidden;
}
.lang-switch-btn {
  padding: 4px 9px;
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s;
}
.lang-switch-btn.lang-switch-on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.lang-switch-dark { background: rgba(255,255,255,.18); }
.lang-switch-dark .lang-switch-btn { color: rgba(255,255,255,.55); }
.lang-switch-dark .lang-switch-btn.lang-switch-on { background: rgba(255,255,255,.22); color: #fff; }

/* ── Progress bar ───────────────────────────────────────────────── */
.progress-bar { display: flex; align-items: center; width: 100%; }
.progress-node {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  background: var(--border); border: 2px solid var(--border);
  transition: background .25s, border-color .25s;
}
.progress-node-done { background: var(--ok); border-color: var(--ok); }
.progress-node-active {
  background: var(--ok); border-color: var(--ok);
  box-shadow: 0 0 0 3px rgba(22,163,74,.2);
  width: 11px; height: 11px;
}
.progress-line {
  flex: 1; height: 2px; background: var(--border); transition: background .25s;
}
.progress-line-done { background: var(--ok); }

/* ── Image tile ─────────────────────────────────────────────────── */
.img-tile { border-radius: var(--r-sm); overflow: hidden; flex-shrink: 0; }
.img-tile svg { width: 100%; height: 100%; }

/* ── Empty state ────────────────────────────────────────────────── */
.empty {
  display: flex; flex-direction: column; align-items: center;
  padding: 56px 24px; text-align: center; gap: 10px; color: var(--muted);
}
.empty-icon { opacity: .35; margin-bottom: 4px; }
.empty h3 { font-size: 16px; font-weight: 700; color: var(--text-2); }
.empty p { font-size: 14px; color: var(--muted); max-width: 280px; line-height: 1.5; }

/* ── Stat card ──────────────────────────────────────────────────── */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .055em; margin-bottom: 5px; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1.15; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-ok .stat-value { color: var(--ok); }

.shared-account-balance {
  display: inline-flex;
  align-items: center;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}
.shared-account-balance-positive {
  color: var(--ok);
}
.shared-account-balance-negative {
  color: var(--warn);
}
.shared-account-card {
  transition: border-color .15s, box-shadow .15s;
}
.shared-account-card-blue {
  border-color: var(--info-border);
  box-shadow: 0 5px 16px rgba(0, 85, 199, .16);
}
.shared-account-card-orange {
  border-color: var(--warn-border);
  box-shadow: 0 5px 16px rgba(217, 119, 6, .16);
}
.shared-account-card-neutral {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.shared-account-unrealized {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
  padding-left: 17px;
  color: var(--muted);
  font-size: 12px;
}
.shared-account-unrealized strong { color: var(--muted); font-size: 13px; }
.shared-account-unrealized-positive { color: var(--info) !important; }
.shared-account-unrealized-negative { color: var(--warn) !important; }

/* ── Section header ─────────────────────────────────────────────── */
.section-hd {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 20px 0 10px;
}
.section-kicker { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px; }
.section-title { font-size: 17px; font-weight: 700; color: var(--text); }

/* ── Tabs ───────────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); overflow-x: auto; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px;
  font-size: 13.5px; font-weight: 600; color: var(--muted);
  border-bottom: 2.5px solid transparent; margin-bottom: -2px;
  transition: color .15s, border-color .15s; white-space: nowrap; flex-shrink: 0;
}
.tab:hover { color: var(--text); }
.tab-active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-count {
  background: var(--neutral-bg); color: var(--muted);
  font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 20px;
}
.tab-active .tab-count { background: rgba(var(--brand-rgb),.12); color: var(--brand); }
.btn-primary .tab-count { background: rgba(255,255,255,.22); color: rgba(255,255,255,.9); }
.btn-ghost .tab-count { background: var(--border); color: var(--muted); }

/* ── Table ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.ships-table { background: var(--surface); font-size: 13.5px; }
.ships-table thead { background: var(--neutral-bg); }
.ships-table th {
  padding: 10px 14px;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.ships-table td { padding: 12px 14px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.ships-table tbody tr:last-child td { border-bottom: none; }
.ships-table tbody tr { cursor: pointer; transition: background .1s; }
.ships-table tbody tr:hover { background: var(--neutral-bg); }
.num { text-align: right; font-weight: 600; }

/* ── Search input ───────────────────────────────────────────────── */
.search-input {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  transition: border-color .15s;
}
.search-input:focus-within { border-color: var(--brand); }
.search-input svg { color: var(--faint); flex-shrink: 0; }
.search-input input { border: none; outline: none; background: transparent; font-size: 14px; color: var(--text); width: 100%; }

/* ── Theme modes ─────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0e0e10;
    --surface: #1c1c1e;
    --border: #3a3a3c;
    --border-light: #2c2c2e;

    --text: #f2f2f7;
    --text-2: #ebebf0;
    --muted: #8e8e93;
    --faint: #636366;

    --brand: #C8392E;
    --brand-dark: #A12D24;
    --brand-rgb: 200,57,46;
    --brand-gold: #E8C547;
    --brand-cream: #F5E6D3;
    --brand-ink: #1A1A1A;
    --hero-gradient-end: #2d1a18;

    --neutral-bg: #2a2a2c;
    --neutral-border: #3a3a3c;

    --ok: #4ade80;
    --ok-bg: #0a2218;
    --ok-border: #154d32;

    --warn: #fbbf24;
    --warn-bg: #261c06;
    --warn-border: #4d380c;

    --bad: #f87171;
    --bad-bg: #260a0a;
    --bad-border: #4d1414;

    --info: #38bdf8;
    --info-bg: #061420;
    --info-border: #0e2840;

    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,.5);
    --shadow: 0 1px 3px 0 rgba(0,0,0,.6), 0 1px 2px -1px rgba(0,0,0,.5);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.6), 0 2px 4px -2px rgba(0,0,0,.4);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.6), 0 4px 6px -4px rgba(0,0,0,.4);
  }

  .login-tab-active { background: var(--border); color: var(--text); box-shadow: none; }
}

:root[data-portal-theme="light"] {
  color-scheme: light;

  --bg: #f4f8ff;
  --surface: #ffffff;
  --border: #dbe7f8;
  --border-light: #edf4ff;

  --text: #0d1b2f;
  --text-2: #1c3557;
  --muted: #60728d;
  --faint: #95a6bd;

  --brand: #0055c7;
  --brand-dark: #003f94;
  --brand-rgb: 0,85,199;
  --brand-gold: #f6c445;
  --brand-cream: #ffffff;
  --brand-ink: #062348;
  --hero-gradient-end: #0b3c78;

  --neutral-bg: #f0f6ff;
  --neutral-border: #dbe7f8;

  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --ok-border: #bbf7d0;

  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;

  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --bad-border: #fecaca;

  --info: #0055c7;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;

  --shadow-sm: 0 1px 2px 0 rgba(12,42,78,.06);
  --shadow: 0 1px 3px 0 rgba(12,42,78,.08), 0 1px 2px -1px rgba(12,42,78,.06);
  --shadow-md: 0 4px 6px -1px rgba(12,42,78,.08), 0 2px 4px -2px rgba(12,42,78,.05);
  --shadow-lg: 0 10px 15px -3px rgba(12,42,78,.08), 0 4px 6px -4px rgba(12,42,78,.05);
}

:root[data-portal-theme="dark"] {
  color-scheme: dark;

  --bg: #0e0e10;
  --surface: #1c1c1e;
  --border: #3a3a3c;
  --border-light: #2c2c2e;

  --text: #f2f2f7;
  --text-2: #ebebf0;
  --muted: #8e8e93;
  --faint: #636366;

  --brand: #C8392E;
  --brand-dark: #A12D24;
  --brand-rgb: 200,57,46;
  --brand-gold: #E8C547;
  --brand-cream: #F5E6D3;
  --brand-ink: #1A1A1A;
  --hero-gradient-end: #2d1a18;

  --neutral-bg: #2a2a2c;
  --neutral-border: #3a3a3c;

  --ok: #4ade80;
  --ok-bg: #0a2218;
  --ok-border: #154d32;

  --warn: #fbbf24;
  --warn-bg: #261c06;
  --warn-border: #4d380c;

  --bad: #f87171;
  --bad-bg: #260a0a;
  --bad-border: #4d1414;

  --info: #38bdf8;
  --info-bg: #061420;
  --info-border: #0e2840;

  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,.5);
  --shadow: 0 1px 3px 0 rgba(0,0,0,.6), 0 1px 2px -1px rgba(0,0,0,.5);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.6), 0 2px 4px -2px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.6), 0 4px 6px -4px rgba(0,0,0,.4);
}

:root[data-portal-theme="dark"] .login-tab-active { background: var(--border); color: var(--text); box-shadow: none; }
