/* Pelagia Portal — design tokens & base styles */

:root {
  /* Palette — warm-cool paper, ink navy, single maritime primary */
  --paper: oklch(98% 0.005 240);
  --paper-2: oklch(96.5% 0.006 240);
  --surface: #ffffff;
  --ink: oklch(22% 0.02 245);
  --ink-2: oklch(35% 0.02 245);
  --muted: oklch(55% 0.015 245);
  --faint: oklch(72% 0.012 245);
  --line: oklch(91% 0.006 245);
  --line-2: oklch(87% 0.008 245);

  --primary: oklch(38% 0.06 230);
  --primary-ink: oklch(28% 0.06 230);
  --primary-soft: oklch(95% 0.02 230);

  /* Status badges — distinct hue, similar chroma/lightness */
  --st-draft-bg: oklch(94% 0.005 245);     --st-draft-fg: oklch(40% 0.015 245);
  --st-review-bg: oklch(94% 0.03 245);     --st-review-fg: oklch(38% 0.09 245);
  --st-vendor-bg: oklch(94% 0.04 60);      --st-vendor-fg: oklch(42% 0.12 60);
  --st-edits-bg: oklch(95% 0.05 95);       --st-edits-fg: oklch(42% 0.1 80);
  --st-approved-bg: oklch(94% 0.04 190);   --st-approved-fg: oklch(38% 0.08 195);
  --st-sent-bg: oklch(94% 0.04 300);       --st-sent-fg: oklch(40% 0.1 300);
  --st-paid-bg: oklch(94% 0.04 215);       --st-paid-fg: oklch(38% 0.08 220);
  --st-closed-bg: oklch(94% 0.04 150);     --st-closed-fg: oklch(38% 0.08 150);
  --st-rejected-bg: oklch(94% 0.04 25);    --st-rejected-fg: oklch(45% 0.13 28);

  /* Type */
  --font-sans: "Geist", "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, monospace;

  /* Spacing scale */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  --sidebar-w: 232px;
  --header-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit; color: inherit;
}

a { color: inherit; text-decoration: none; }

.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; letter-spacing: -0.01em; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* ─────────── App shell ─────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  padding: 0 16px 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  gap: 14px;
  height: var(--header-h);
}

.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; letter-spacing: -0.01em;
  width: calc(var(--sidebar-w) - 18px);
}
.brand-mark {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--primary);
  position: relative; flex-shrink: 0;
}
.brand-mark::before {
  content: ""; position: absolute; inset: 4px;
  border: 1.5px solid var(--paper); border-top-color: transparent; border-right-color: transparent;
  border-radius: 50%;
  transform: rotate(-45deg);
}
.brand-name { font-size: 14px; }

.header-search {
  flex: 0 0 320px;
  display: flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 10px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: 12.5px;
}
.header-search input {
  flex: 1; background: transparent; border: 0; outline: 0;
  color: var(--ink);
}
.header-search .kbd {
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 1px 5px; border: 1px solid var(--line-2);
  border-radius: 3px; color: var(--muted);
  background: var(--surface);
}

.header-spacer { flex: 1; }

.role-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 4px 0 10px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: 12px;
}
.role-pill select {
  background: transparent; border: 0; outline: 0;
  padding: 0 18px 0 4px;
  font-family: var(--font-mono); font-size: 11.5px;
  -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 9px) 13px, calc(100% - 5px) 13px;
  background-size: 4px 4px; background-repeat: no-repeat;
  cursor: pointer;
}

.user-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px;
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: var(--paper);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
}

/* ─────────── Sidebar ─────────── */
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 14px 10px 24px;
  overflow-y: auto;
}
.nav-group { margin-bottom: 14px; }
.nav-group-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--faint); padding: 6px 10px 4px;
  font-weight: 500;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 10px;
  border-radius: var(--r-md);
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  margin-bottom: 1px;
  position: relative;
}
.nav-item:hover { background: var(--paper-2); color: var(--ink); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-weight: 500;
}
.nav-item .nav-count {
  margin-left: auto;
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--muted);
  background: var(--paper-2);
  border-radius: 8px; padding: 1px 6px;
}
.nav-item.active .nav-count { background: var(--surface); color: var(--primary-ink); }
.nav-icon {
  width: 14px; height: 14px; flex-shrink: 0; color: var(--muted);
}
.nav-item.active .nav-icon { color: var(--primary-ink); }

/* ─────────── Main ─────────── */
.main {
  overflow-y: auto;
  padding: 22px 32px 60px;
  max-width: 1280px;
  width: 100%;
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 22px; gap: 16px;
}
.crumbs {
  font-size: 11.5px; color: var(--muted);
  margin-bottom: 6px;
  display: flex; gap: 6px;
}
.crumbs .sep { color: var(--faint); }
.page-title {
  font-size: 22px; font-weight: 600; letter-spacing: -0.01em;
  margin: 0;
}
.page-sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* ─────────── Buttons ─────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--paper-2); border-color: var(--line-2); }
.btn.primary {
  background: var(--ink); color: var(--paper);
  border-color: var(--ink);
}
.btn.primary:hover { background: oklch(15% 0.02 245); }
.btn.maritime {
  background: var(--primary); color: var(--paper);
  border-color: var(--primary);
}
.btn.maritime:hover { background: var(--primary-ink); }
.btn.danger {
  background: var(--surface); color: var(--st-rejected-fg);
  border-color: var(--st-rejected-bg);
}
.btn.danger:hover { background: var(--st-rejected-bg); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 11.5px; }
.btn.icon { padding: 0; width: 30px; justify-content: center; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ─────────── Cards & sections ─────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.card-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: 13px; font-weight: 600; margin: 0; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 500;
  margin: 26px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ─────────── Tables ─────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.table th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable:hover td { background: var(--paper-2); cursor: pointer; }
.table .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.table .po-num { font-family: var(--font-mono); font-size: 12px; color: var(--primary-ink); }

/* ─────────── Status badges ─────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor;
}
.badge.no-dot::before { display: none; }

.badge.draft     { background: var(--st-draft-bg);     color: var(--st-draft-fg); }
.badge.submitted { background: var(--st-review-bg);    color: var(--st-review-fg); }
.badge.review    { background: var(--st-review-bg);    color: var(--st-review-fg); }
.badge.vendor    { background: var(--st-vendor-bg);    color: var(--st-vendor-fg); }
.badge.edits     { background: var(--st-edits-bg);     color: var(--st-edits-fg); }
.badge.approved  { background: var(--st-approved-bg);  color: var(--st-approved-fg); }
.badge.sent      { background: var(--st-sent-bg);      color: var(--st-sent-fg); }
.badge.paid      { background: var(--st-paid-bg);      color: var(--st-paid-fg); }
.badge.closed    { background: var(--st-closed-bg);    color: var(--st-closed-fg); }
.badge.rejected  { background: var(--st-rejected-bg);  color: var(--st-rejected-fg); }

.role-badge {
  display: inline-flex; padding: 2px 7px;
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--ink-2); letter-spacing: 0.02em;
}

.verified-mark {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--st-closed-fg);
}

/* ─────────── Stat cards ─────────── */
.stat-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px 16px;
}
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 500;
}
.stat-value {
  font-size: 26px; font-weight: 500;
  letter-spacing: -0.02em;
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  margin-top: 6px;
  color: var(--ink);
}
.stat-sub {
  font-size: 11.5px; color: var(--muted);
  margin-top: 3px;
  display: flex; gap: 6px; align-items: center;
}
.stat .trend-up { color: var(--st-closed-fg); }
.stat .trend-dn { color: var(--st-rejected-fg); }
.stat.clickable { cursor: pointer; transition: border-color 0.12s; }
.stat.clickable:hover { border-color: var(--ink-2); }

/* ─────────── Forms ─────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 11px; color: var(--muted); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.field-label .req { color: var(--st-rejected-fg); margin-left: 2px; }
.input, .select, .textarea {
  height: 32px; padding: 0 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  font-size: 13px;
  outline: 0;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.textarea { height: auto; padding: 9px 11px; resize: vertical; min-height: 72px; }
.input.mono { font-family: var(--font-mono); }

.form-row {
  display: grid; gap: 14px;
}
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ─────────── Filter bar ─────────── */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.filter-bar .input,
.filter-bar .select { height: 28px; font-size: 12px; background: var(--surface); }

/* ─────────── Charts (CSS-only bars) ─────────── */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; }
.bar {
  flex: 1; background: var(--primary-soft);
  border-radius: 3px 3px 0 0;
  position: relative;
  min-height: 4px;
  transition: background 0.15s;
}
.bar:hover { background: var(--primary); }
.bar::after {
  content: attr(data-label);
  position: absolute; bottom: -18px; left: 0; right: 0;
  text-align: center;
  font-size: 10.5px; color: var(--muted);
  font-family: var(--font-mono);
}
.bar .bar-val {
  position: absolute; top: -16px; left: 0; right: 0;
  text-align: center;
  font-size: 10px; color: var(--ink-2);
  font-family: var(--font-mono);
  opacity: 0; transition: opacity 0.15s;
}
.bar:hover .bar-val { opacity: 1; }

.hbar-row {
  display: grid; grid-template-columns: 110px 1fr 80px;
  gap: 10px; align-items: center;
  font-size: 12px;
  margin-bottom: 7px;
}
.hbar-row .name { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-row .track {
  background: var(--paper-2);
  height: 12px; border-radius: 3px;
  overflow: hidden;
}
.hbar-row .fill { background: var(--primary); height: 100%; border-radius: 3px; }
.hbar-row .v { font-family: var(--font-mono); text-align: right; color: var(--ink); font-size: 11.5px; }

/* ─────────── PO Detail layout ─────────── */
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 22px;
  align-items: start;
}
.detail-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.detail-band-left { display: flex; align-items: center; gap: 14px; }
.detail-band .po-id {
  font-family: var(--font-mono); font-size: 18px;
  letter-spacing: -0.01em;
}
.detail-band .po-title { color: var(--muted); font-size: 13.5px; }

.kv {
  display: grid; grid-template-columns: 130px 1fr;
  gap: 10px 14px; font-size: 12.5px;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--ink); }

.timeline-stop {
  display: grid; grid-template-columns: 14px 1fr auto;
  gap: 10px; align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 12px;
}
.timeline-stop:last-child { border-bottom: 0; }
.timeline-stop .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--line-2);
  margin-top: 6px;
}
.timeline-stop.done .dot { background: var(--st-closed-fg); }
.timeline-stop .actor { color: var(--ink); font-weight: 500; }
.timeline-stop .action { color: var(--muted); }
.timeline-stop .when { color: var(--faint); font-family: var(--font-mono); font-size: 11px; white-space: nowrap; }

/* ─────────── Inline action panel ─────────── */
.action-panel {
  background: oklch(99% 0.005 245);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px 16px;
}
.action-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─────────── Payment cards ─────────── */
.pay-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.pay-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.pay-card .amount {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 22px; letter-spacing: -0.01em;
}

/* ─────────── Cart ─────────── */
.cart-line {
  display: grid;
  grid-template-columns: 1fr 80px 100px 80px 24px;
  gap: 14px; align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.cart-line:last-of-type { border-bottom: 0; }

/* ─────────── Login ─────────── */
.login-shell {
  display: grid; place-items: center;
  min-height: 100vh; background: var(--paper);
}
.login-card {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 28px;
}
.login-brand {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 22px;
}
.login-brand .brand-mark { width: 28px; height: 28px; }
.login-brand .brand-name { font-size: 18px; }

/* ─────────── Misc helpers ─────────── */
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11.5px;
  margin: 2px 4px 2px 0;
  cursor: pointer;
}
.tag-chip:hover { border-color: var(--ink-2); }
.tag-chip.has-link { color: var(--primary-ink); }

.alert {
  display: flex; gap: 10px;
  padding: 11px 14px;
  border-radius: var(--r-md);
  font-size: 12.5px;
  border: 1px solid var(--st-edits-bg);
  background: oklch(97% 0.02 95);
  color: var(--st-edits-fg);
  margin-bottom: 16px;
}
.alert.info { border-color: var(--st-review-bg); background: oklch(97% 0.012 245); color: var(--st-review-fg); }
.alert strong { color: inherit; }

.empty-state {
  padding: 38px 16px; text-align: center;
  color: var(--muted); font-size: 12.5px;
}

.dot-sep { color: var(--faint); padding: 0 6px; }

.scrollable-card { max-height: 340px; overflow-y: auto; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 2px solid var(--surface); }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }
