/* Design tokens. Spacing follows an 8pt grid; type scale 12/14/16/20/24/32. */
:root {
  color-scheme: dark light;
  --color-bg: #0b1622;
  --color-surface: #122131;
  --color-raised: #182b3e;
  --color-border: #26405a;
  --color-text-primary: #eef4f9;
  --color-text-secondary: #b6c6d6;
  --color-text-muted: #86a0b8;
  --color-accent: #4cc2e8;
  --color-accent-hover: #7bd6f2;
  --color-on-accent: #04202c;
  --color-danger: #ff8a80;
  --color-danger-bg: #3a1c20;
  --color-success: #6fdc9c;
  --color-success-bg: #143226;
  --color-warning: #f2c14e;
  --color-warning-bg: #3a2f12;
  --font-display: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --font-body: 'Segoe UI Variable Text', 'Segoe UI', 'Helvetica Neue', sans-serif;
  --font-mono: 'Cascadia Mono', Consolas, 'SF Mono', monospace;
  --radius: 8px;
  --shadow: 0 8px 24px rgb(0 0 0 / 0.28);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}
@media (prefers-color-scheme: light) {
  :root {
    --color-bg: #f2f5f8;
    --color-surface: #ffffff;
    --color-raised: #f6f9fb;
    --color-border: #cfdae4;
    --color-text-primary: #0d2233;
    --color-text-secondary: #38536b;
    --color-text-muted: #5b7388;
    --color-accent: #00628a;
    --color-accent-hover: #004e6f;
    --color-on-accent: #ffffff;
    --color-danger: #a8261c;
    --color-danger-bg: #fdecea;
    --color-success: #17693c;
    --color-success-bg: #e5f5ec;
    --color-warning: #7a5600;
    --color-warning-bg: #fdf3d7;
    --shadow: 0 8px 24px rgb(13 34 51 / 0.12);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--color-bg); color: var(--color-text-primary);
  font: 14px/1.5 var(--font-body);
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: 24px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-size: 16px; font-weight: 600; white-space: nowrap; }
.brand__mark { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--color-accent); box-shadow: inset 0 -6px 0 var(--color-accent); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 32px; padding: 4px 12px; border-radius: var(--radius);
  border: 1px solid var(--color-border); background: var(--color-raised);
  color: var(--color-text-primary); cursor: pointer; white-space: nowrap;
  transition: background 150ms, border-color 150ms, transform 150ms;
}
.btn:hover { border-color: var(--color-accent); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn--primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); font-weight: 600; }
.btn--primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--color-danger); }
.btn--danger:hover { border-color: var(--color-danger); background: var(--color-danger-bg); }
.btn--small { min-height: 24px; padding: 0 8px; font-size: 12px; }
.btn--wide { width: 100%; min-height: 40px; }

/* ---- fields ---- */
.field { display: grid; gap: 4px; }
.field > span { font-size: 12px; color: var(--color-text-secondary); }
input[type=text], input[type=password], input[type=search], input[type=number], input:not([type]), textarea, select {
  width: 100%; min-height: 32px; padding: 4px 8px; border-radius: var(--radius);
  border: 1px solid var(--color-border); background: var(--color-bg);
  transition: border-color 150ms;
}
input:focus, textarea:focus, select:focus { border-color: var(--color-accent); }
textarea { min-height: 96px; resize: vertical; font-family: var(--font-mono); font-size: 12px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--color-accent); cursor: pointer; }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login__card { width: min(360px, 100%); display: grid; gap: 16px; padding: 32px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---- shell ---- */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; padding: 8px 24px; background: var(--color-surface); border-bottom: 1px solid var(--color-border); }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { padding: 8px 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--color-text-secondary); cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--color-text-primary); }
.tabs button.is-active { color: var(--color-text-primary); border-bottom-color: var(--color-accent); font-weight: 600; }
.view { max-width: 1280px; margin: 0 auto; padding: 24px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; transform: translateX(-50%); max-width: min(640px, calc(100% - 32px)); padding: 12px 16px; border-radius: var(--radius); background: var(--color-success-bg); color: var(--color-success); border: 1px solid currentColor; box-shadow: var(--shadow); }
.toast.is-error { background: var(--color-danger-bg); color: var(--color-danger); }
.note { padding: 8px 12px; border-radius: var(--radius); font-size: 12px; background: var(--color-raised); color: var(--color-text-secondary); }
.note--error { background: var(--color-danger-bg); color: var(--color-danger); }
.muted { color: var(--color-text-muted); }
.mono { font-family: var(--font-mono); font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 16px; }
.empty { padding: 48px 16px; text-align: center; color: var(--color-text-muted); border: 1px dashed var(--color-border); border-radius: var(--radius); }
.empty strong { display: block; margin-bottom: 4px; font-family: var(--font-display); font-size: 16px; color: var(--color-text-primary); }

/* ---- badges ---- */
.badge { display: inline-flex; align-items: center; padding: 0 8px; min-height: 20px; border-radius: 12px; font-size: 12px; background: var(--color-raised); color: var(--color-text-secondary); border: 1px solid var(--color-border); white-space: nowrap; }
.badge--ok { background: var(--color-success-bg); color: var(--color-success); border-color: transparent; }
.badge--warn { background: var(--color-warning-bg); color: var(--color-warning); border-color: transparent; }
.badge--bad { background: var(--color-danger-bg); color: var(--color-danger); border-color: transparent; }

/* ---- clients layout ---- */
.split { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 24px; align-items: start; }
.side { position: sticky; top: 72px; display: grid; gap: 8px; }
.list { display: grid; gap: 4px; max-height: calc(100vh - 200px); overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.list button { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; text-align: left; border: 1px solid transparent; border-radius: var(--radius); background: none; cursor: pointer; }
.list button:hover { background: var(--color-surface); }
.list button.is-active { background: var(--color-surface); border-color: var(--color-accent); }
.list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }
.card + .card { margin-top: 12px; }
.vessel__head { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 16px; border: 0; background: none; text-align: left; cursor: pointer; border-radius: var(--radius); }
.vessel__head:hover { background: var(--color-raised); }
.vessel__chevron { width: 8px; height: 8px; border-right: 2px solid var(--color-text-muted); border-bottom: 2px solid var(--color-text-muted); transform: rotate(-45deg); transition: transform 250ms var(--ease); flex: none; }
.vessel.is-open .vessel__chevron { transform: rotate(45deg); }
.vessel__body { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 24px; padding: 16px; border-top: 1px solid var(--color-border); }
.section-title { font-family: var(--font-body); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-text-muted); }

/* ---- book switches ---- */
.books { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; max-height: 480px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: var(--radius); }
.book { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--color-border); }
.book:last-child { border-bottom: 0; }
.book:hover { background: var(--color-raised); }
.book label { display: contents; cursor: pointer; }
.book__title { min-width: 0; }
.book__title b { font-weight: 600; }
.book__title span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--color-text-muted); }
.book.is-on .book__title b { color: var(--color-accent); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--color-border); }
th { font-size: 12px; font-weight: 600; color: var(--color-text-muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.is-off td { color: var(--color-text-muted); }

/* ---- upload ---- */
.drop { display: grid; gap: 8px; place-items: center; padding: 32px 16px; text-align: center; border: 2px dashed var(--color-border); border-radius: var(--radius); background: var(--color-surface); cursor: pointer; transition: border-color 150ms, background 150ms; }
.drop:hover, .drop.is-over { border-color: var(--color-accent); background: var(--color-raised); }
.drop input { display: none; }
.queue td input { min-width: 80px; }
.queue td.wide input { min-width: 160px; }

/* ---- credential card ---- */
.credential { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--color-accent); border-radius: var(--radius); background: var(--color-raised); }
.credential dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.credential dt { color: var(--color-text-muted); }
.credential dd { margin: 0; font-family: var(--font-mono); user-select: all; word-break: break-all; }

/* ---- dialog ---- */
.dialog { width: min(480px, calc(100% - 32px)); padding: 24px; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); color: var(--color-text-primary); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(0 0 0 / 0.5); }
.dialog form { display: grid; gap: 16px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- motion ---- */
@media (prefers-reduced-motion: no-preference) {
  .view.is-entering > * { animation: rise 400ms var(--ease) both; }
  /* Signature: a freshly granted book gets its date "stamped" in. */
  .badge.is-new { animation: stamp 400ms var(--ease) both; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
  @keyframes stamp { from { opacity: 0; transform: scale(1.6) rotate(-6deg); } 60% { opacity: 1; transform: scale(0.94) rotate(1deg); } }
}

@media (max-width: 1024px) {
  .vessel__body { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 768px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .view { padding: 16px; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
  .list { max-height: 240px; }
  .book { grid-template-columns: auto minmax(0, 1fr); }
  .book .badge, .book .btn { grid-column: 2; justify-self: start; }
  .btn, .tabs button { min-height: 44px; }
}

.vessel__name { display: block; font-family: var(--font-display); font-size: 16px; font-weight: 600; line-height: 1.2; }
