/* Dispatch Register — mobile-first styles (360px baseline, 768px+ comfortable). */

:root {
  --ink: #12212f;
  --ink-soft: #4a5b6b;
  --line: #d7dee6;
  --paper: #ffffff;
  --bg: #f4f6f9;
  --brand: #0d1b2e;
  --accent: #1f6feb;
  --ok: #1c7c4a;
  --warn: #9a6a00;
  --danger: #b42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(18, 33, 47, 0.08), 0 6px 18px rgba(18, 33, 47, 0.06);
  --tap: 44px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win over a component's own `display`
   (.mainnav is flex, .dialog-backdrop is grid, .toast/.banner have their own
   layout). Without this rule the untouched confirm dialog, the signed-out nav,
   the empty Sign out button and the empty banner all stay on screen and the
   dialog backdrop covers the sign-in form. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 10px; }
a { color: var(--accent); }

.skip-link { position: absolute; left: -9999px; top: 0; background: var(--brand); color: #fff; padding: 10px 14px; z-index: 99; }
.skip-link:focus { left: 8px; }

/* ---------- top bar ---------- */
.topbar { background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent); font-weight: 700; font-size: 0.85rem; letter-spacing: 0.5px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 1rem; }
.brand-text small { font-size: 0.72rem; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.who { font-size: 0.78rem; opacity: 0.85; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mainnav { display: flex; gap: 2px; overflow-x: auto; padding: 0 8px 8px; scrollbar-width: none; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a { color: #cfd8e3; text-decoration: none; font-size: 0.85rem; font-weight: 600; padding: 9px 12px; border-radius: 999px; white-space: nowrap; min-height: var(--tap); display: inline-flex; align-items: center; }
.mainnav a[aria-current="page"] { background: #fff; color: var(--brand); }

/* ---------- layout ---------- */
.main { padding: 14px 14px 96px; max-width: 1200px; margin: 0 auto; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.card-tight { padding: 10px 12px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.muted { color: var(--ink-soft); font-size: 0.85rem; }
.tiny { font-size: 0.76rem; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-between { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.grow { flex: 1 1 160px; }
.loading { padding: 28px 0; text-align: center; color: var(--ink-soft); }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; font-size: 0.92rem; border-radius: 9px; padding: 10px 14px;
  min-height: var(--tap); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { font-size: 0.8rem; padding: 7px 10px; min-height: 36px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
input[type="text"], input[type="password"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; font: inherit; font-size: 0.95rem; padding: 10px 11px; min-height: var(--tap);
  border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 3px solid rgba(31, 111, 235, 0.45); outline-offset: 1px;
}
.hint { font-size: 0.76rem; color: var(--ink-soft); margin-top: 4px; }
.form-grid { display: grid; gap: 12px; }
.error-text { color: var(--danger); font-size: 0.85rem; font-weight: 600; }
.ok-text { color: var(--ok); font-size: 0.85rem; font-weight: 600; }

/* ---------- chips / presets ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.chip { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 999px; padding: 8px 12px; font-size: 0.82rem; font-weight: 600; white-space: nowrap; min-height: 38px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- summary strip ---------- */
.summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { background: #f7f9fc; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; }
.stat b { display: block; font-size: 1.15rem; }
.stat span { font-size: 0.74rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-wide { grid-column: 1 / -1; }
.mode-line { font-size: 0.8rem; color: var(--ink-soft); }

/* ---------- table + cards ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data th, table.data td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data thead th {
  position: sticky; top: 0; background: #eef2f7; font-size: 0.76rem; text-transform: uppercase;
  letter-spacing: 0.03em; color: var(--ink-soft); z-index: 2; white-space: nowrap;
}
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: #f7faff; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sortbtn { background: none; border: 0; font: inherit; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; color: inherit; font-weight: 700; cursor: pointer; padding: 0; }
.row-deleted { background: #fff6f5; }
.tag { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.tag-pending { color: var(--warn); border-color: #e3c98a; background: #fff9e8; }
.tag-received { color: var(--ok); border-color: #a9d5bd; background: #effaf3; }
.tag-returned { color: var(--danger); border-color: #f0b4ae; background: #fdf1f0; }
.tag-deleted { color: var(--danger); border-color: #f0b4ae; background: #fdf1f0; }

.cards { display: grid; gap: 10px; }
.entry-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.entry-card h3 { font-size: 0.98rem; margin-bottom: 4px; }
.entry-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 0.8rem; color: var(--ink-soft); }
.sl-badge { font-weight: 700; font-variant-numeric: tabular-nums; }
.dept-chip { font-weight: 700; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--accent); }
table.data td.docno { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.desktop-only { display: none; }

/* ---------- filters panel ---------- */
.filters { display: none; }
.filters.open { display: block; }
.filter-grid { display: grid; gap: 10px; grid-template-columns: 1fr; }

/* ---------- activity log ---------- */
.log-item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.log-item:last-child { border-bottom: 0; }
.log-main { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; font-size: 0.88rem; }
.log-when { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: 0.8rem; }
.log-who { font-weight: 700; }
.diff { margin: 8px 0 0; padding: 8px 10px; background: #f7f9fc; border: 1px dashed var(--line); border-radius: 8px; font-size: 0.82rem; }
.diff div + div { margin-top: 3px; }
.diff b { font-weight: 700; }
.old { color: var(--danger); }
.new { color: var(--ok); }

/* ---------- misc ---------- */
.banner { background: #fff4e5; color: #7a4b00; padding: 8px 14px; font-size: 0.85rem; border-bottom: 1px solid #f0d9b5; }
.banner-error { background: #fdf1f0; color: var(--danger); border-bottom-color: #f0b4ae; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--brand); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 0.88rem; box-shadow: var(--shadow); max-width: min(92vw, 460px); z-index: 40; }
.dialog-backdrop { position: fixed; inset: 0; background: rgba(13, 27, 46, 0.5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.dialog { background: #fff; border-radius: 12px; padding: 16px; width: min(100%, 420px); box-shadow: var(--shadow); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.empty { text-align: center; color: var(--ink-soft); padding: 26px 10px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 1fr; gap: 8px; }
.kv > div { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.kv dt { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.kv dd { margin: 2px 0 0; font-size: 0.95rem; word-break: break-word; }
.print-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.history-item { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; margin-bottom: 10px; }

/* ---------- tablet / desktop ---------- */
@media (min-width: 640px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filter-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 900px) {
  .main { padding: 20px 24px 80px; }
  .cards { display: none; }
  .desktop-only { display: block; }
  .filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kv { grid-template-columns: 1fr 1fr; }
  .who { max-width: 220px; }
}
