/* DeepSea ERP — shared styles. Plain CSS, no framework. */
:root {
  --navy: #0b2545; --blue: #2563eb; --teal: #0891b2; --purple: #7c3aed;
  --ink: #1e293b; --muted: #64748b; --line: #e2e8f0; --bg: #f8fafc;
  --card: #ffffff; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --radius: 10px; --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top nav */
.nav {
  display: flex; align-items: center; gap: 4px; background: var(--navy);
  color: #fff; padding: 0 16px; height: 52px; position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow);
  overflow-x: auto; -webkit-overflow-scrolling: touch;   /* scroll the nav, not the page, on mobile */
}
.nav::-webkit-scrollbar { height: 0; }
/* nav items keep their size and scroll horizontally instead of stretching the page */
.nav .brand, .nav a.link, .nav .who, .nav button.signout { flex: 0 0 auto; }
.nav .brand { font-weight: 700; letter-spacing: .3px; margin-right: 14px; white-space: nowrap; }
.nav .brand small { font-weight: 400; opacity: .7; }
.nav a.link {
  color: #cbd5e1; padding: 8px 11px; border-radius: 7px; font-weight: 500; white-space: nowrap;
}
.nav a.link:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav a.link.active { background: rgba(255,255,255,.16); color: #fff; }
.nav .spacer { flex: 1; }
.nav .who { color: #cbd5e1; font-size: 13px; }
.nav button.signout {
  background: transparent; color: #cbd5e1; border: 1px solid rgba(255,255,255,.25);
  padding: 6px 10px; border-radius: 7px; cursor: pointer;
}
.nav button.signout:hover { background: rgba(255,255,255,.1); color: #fff; }
@media (max-width: 720px) {
  .nav { padding: 0 10px; }
  .nav .who { display: none; }        /* email hidden on mobile to save width */
  .nav .brand { margin-right: 8px; }
  .wrap { padding: 16px 12px 60px; }
}
html, body { max-width: 100%; }

/* Layout */
.wrap { max-width: 1320px; margin: 0 auto; padding: 22px 18px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin: 6px 0 18px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .sub { color: var(--muted); }

/* Cards & grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .n { font-size: 26px; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 13px; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--card); }
/* max-height makes the wrapper the vertical scroller so the sticky header
   actually engages (page-level scrolling never triggered it). */
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); max-height: calc(100vh - 150px); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f1f5f9; font-weight: 600; color: #334155; position: sticky; top: 0; z-index: 2; cursor: default; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Controls */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.field span.req::after { content: " *"; color: var(--bad); }

.btn { background: var(--blue); color: #fff; border: 0; border-radius: 8px; padding: 9px 14px;
  font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f8fafc; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.scope1 { background: #dbeafe; color: #1d4ed8; }
.badge.scope2 { background: #cffafe; color: #0e7490; }
.badge.scope3 { background: #ede9fe; color: #6d28d9; }
.badge.st-enquiry { background:#f1f5f9; color:#475569; }
.badge.st-quoted { background:#fef9c3; color:#854d0e; }
.badge.st-in_progress { background:#dbeafe; color:#1d4ed8; }
.badge.st-delivered { background:#e0e7ff; color:#4338ca; }
.badge.st-invoiced { background:#fae8ff; color:#a21caf; }
.badge.st-paid { background:#dcfce7; color:#15803d; }
.badge.st-closed { background:#f1f5f9; color:#475569; }
.badge.st-lost { background:#fee2e2; color:#b91c1c; }
.badge.st-cancelled { background:#fef3c7; color:#92400e; }

.muted { color: var(--muted); }
.right { text-align: right; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.legal { font-style: italic; color: var(--navy); }
.banner { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; }
.banner.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.banner.err  { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.banner.ok   { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.hidden { display: none !important; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none;
  align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal-bg.show { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; padding: 20px; max-height: 92vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(15,23,42,.3); }
.modal.lg { max-width: 1120px; padding: 24px 28px; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .modal .row { grid-template-columns: 1fr; } }
/* Grid/flex children default to min-width:auto — a select with long options
   would blow out of the modal (billing "Vessel" bug, 06 Jul). Clamp them. */
.modal .row > * { min-width: 0; }
label.field > input, label.field > select, label.field > textarea { width: 100%; min-width: 0; box-sizing: border-box; }
/* Sortable table headers */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { text-decoration: underline; }
th.sortable.on::after { content: " ▼"; font-size: 9px; }
th.sortable.on[data-dir="asc"]::after { content: " ▲"; font-size: 9px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
