/* ============================================================================
   DocGen — shadcn-flavoured design system (plain CSS, no build step).
   Mirrors shadcn/ui's token model: HSL design tokens on :root, a .dark theme,
   --radius, and component classes (button / card / input / badge / table).
   The EJS views keep their semantic class names; this file gives them the look.
   ========================================================================== */

:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --primary: 221 83% 53%;          /* brand blue — the one accent */
  --primary-foreground: 0 0% 100%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 72% 51%;
  --destructive-foreground: 0 0% 100%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 221 83% 53%;
  --radius: 0.6rem;
  --shadow-sm: 0 1px 2px 0 hsl(240 10% 3.9% / 0.05);
  --shadow: 0 1px 3px 0 hsl(240 10% 3.9% / 0.08), 0 1px 2px -1px hsl(240 10% 3.9% / 0.08);
  --shadow-md: 0 4px 12px -2px hsl(240 10% 3.9% / 0.10);
}

.dark {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 5.5%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 5.5%;
  --primary: 217 91% 60%;
  --primary-foreground: 240 10% 3.9%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 17%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 72% 56%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 3.7% 18%;
  --input: 240 3.7% 20%;
  --ring: 217 91% 60%;
  --shadow-sm: 0 1px 2px 0 hsl(0 0% 0% / 0.3);
  --shadow: 0 1px 3px 0 hsl(0 0% 0% / 0.4), 0 1px 2px -1px hsl(0 0% 0% / 0.4);
  --shadow-md: 0 6px 16px -4px hsl(0 0% 0% / 0.5);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: hsl(var(--primary)); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Top navigation -------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center;
  height: 56px; padding: 0 20px;
  background: hsl(var(--card) / 0.8);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid hsl(var(--border));
}
.topbar a { color: hsl(var(--foreground)); }
.topbar a:hover { text-decoration: none; }
.brand {
  font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  display: inline-flex; align-items: center; gap: 8px;
}
.brand .dot {
  width: 22px; height: 22px; border-radius: 7px; display: inline-grid; place-items: center;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  font-size: 13px; font-weight: 800;
}
.topbar nav { display: flex; gap: 4px; align-items: center; }
.topbar nav > a {
  padding: 7px 12px; border-radius: calc(var(--radius) - 0.2rem);
  font-size: 14px; font-weight: 500; color: hsl(var(--muted-foreground));
  transition: color .15s, background .15s;
}
.topbar nav > a:hover { color: hsl(var(--foreground)); background: hsl(var(--accent)); }
.inline { display: inline; margin: 0; }
button.link {
  background: none; border: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 500;
  color: hsl(var(--muted-foreground)); padding: 7px 12px; border-radius: calc(var(--radius) - 0.2rem);
  transition: color .15s, background .15s;
}
button.link:hover { color: hsl(var(--foreground)); background: hsl(var(--accent)); }

/* Theme toggle */
.theme-toggle {
  width: 34px; height: 34px; display: inline-grid; place-items: center;
  border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 0.2rem);
  background: hsl(var(--card)); color: hsl(var(--foreground)); cursor: pointer;
}
.theme-toggle:hover { background: hsl(var(--accent)); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .sun { display: none; }
.dark .theme-toggle .sun { display: block; }
.dark .theme-toggle .moon { display: none; }

/* ---- Layout ---------------------------------------------------------------- */
main { max-width: 1000px; margin: 32px auto 64px; padding: 0 20px; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 26px 0 0; }
h3 { font-size: 14px; font-weight: 600; }

/* ---- Cards ----------------------------------------------------------------- */
.card {
  background: hsl(var(--card)); color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--shadow-sm);
}
.card.narrow { max-width: 380px; margin: 10vh auto; }
.card + .card { margin-top: 16px; }
.card.info { background: hsl(var(--muted) / 0.5); }
.card.info ol { margin: 10px 0 0 18px; padding: 0; } .card.info li { margin: 6px 0; }

/* ---- Forms & inputs -------------------------------------------------------- */
label { display: block; margin: 14px 0; font-weight: 500; font-size: 13px; color: hsl(var(--foreground)); }
input, textarea, select {
  display: block; width: 100%; margin-top: 6px; padding: 9px 12px; font: inherit; font-size: 14px;
  background: hsl(var(--background)); color: hsl(var(--foreground));
  border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 0.15rem);
  transition: border-color .15s, box-shadow .15s; font-weight: 400;
}
input::placeholder, textarea::placeholder { color: hsl(var(--muted-foreground)); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.25);
}
input[type="file"] { padding: 7px 12px; cursor: pointer; }
textarea { resize: vertical; min-height: 64px; }
.kv-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
label.full { grid-column: 1 / -1; }
.hint { display: block; font-weight: 400; color: hsl(var(--muted-foreground)); font-size: 12px; margin-top: 5px; }

/* ---- Buttons --------------------------------------------------------------- */
button.primary, .primary.btn, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; font: inherit; font-size: 14px; font-weight: 500; line-height: 1;
  border-radius: calc(var(--radius) - 0.15rem); cursor: pointer; white-space: nowrap;
  text-decoration: none; transition: background .15s, border-color .15s, box-shadow .15s, opacity .15s;
  border: 1px solid transparent;
}
button.primary, .primary.btn {
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  box-shadow: var(--shadow-sm);
}
button.primary:hover, .primary.btn:hover { background: hsl(var(--primary) / 0.9); text-decoration: none; }
.btn {
  background: hsl(var(--card)); color: hsl(var(--foreground)); border-color: hsl(var(--border));
}
.btn:hover { background: hsl(var(--accent)); text-decoration: none; }
.btn.danger, button.del { color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / 0.4); background: hsl(var(--card)); }
.btn.danger:hover { background: hsl(var(--destructive) / 0.1); text-decoration: none; }
button:focus-visible, a.btn:focus-visible, .primary.btn:focus-visible {
  outline: none; box-shadow: 0 0 0 3px hsl(var(--ring) / 0.4);
}
.actions { margin-top: 24px; display: flex; gap: 10px; }

/* ---- Layout helpers -------------------------------------------------------- */
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 4px; }
.search { display: flex; gap: 8px; } .search input { width: 280px; margin-top: 0; }
.search button { flex: none; }

/* ---- Tables ---------------------------------------------------------------- */
table.grid {
  width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 14px;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: var(--radius); overflow: hidden;
}
.grid th, .grid td { text-align: left; padding: 11px 14px; border-bottom: 1px solid hsl(var(--border)); }
.grid thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: hsl(var(--muted-foreground)); font-weight: 600; background: hsl(var(--muted) / 0.4);
}
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr { transition: background .12s; }
.grid tbody tr:hover { background: hsl(var(--accent) / 0.5); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid input { margin: 0; }
.grid tfoot td { font-weight: 700; }
/* Loop tables hold inputs — let them breathe and don't hover-highlight. */
.loop-table { overflow: visible; }
.loop-table td { padding: 6px 8px; }
.loop-table tbody tr:hover { background: transparent; }
.grid.sub { margin: 8px 0 2px; border-radius: calc(var(--radius) - 0.2rem); }
.grid.sub td { border-bottom: 1px dashed hsl(var(--border)); padding: 6px 10px; }

/* ---- Key/value blocks ------------------------------------------------------ */
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 28px; margin-bottom: 18px; }
.kv > div span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: hsl(var(--muted-foreground)); margin-bottom: 2px; }
.klabel { color: hsl(var(--muted-foreground)); width: 30%; font-weight: 500; }
.kvpair { display: inline-block; margin-right: 16px; }
.kvpair b { color: hsl(var(--muted-foreground)); font-weight: 500; }

/* ---- Badges & chips -------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; vertical-align: middle;
  background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 999px; border: 1px solid hsl(var(--border));
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  background: hsl(var(--muted) / 0.5); border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.2rem); padding: 6px 11px; font-size: 13px; font-weight: 500;
}
.chip small { color: hsl(var(--muted-foreground)); font-weight: 400; }

/* ---- Tiles (template launcher) -------------------------------------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-top: 14px; }
.tile {
  display: flex; flex-direction: column; gap: 8px; padding: 18px;
  background: hsl(var(--card)); color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s, transform .08s;
}
.tile:hover { border-color: hsl(var(--primary) / 0.5); box-shadow: var(--shadow-md); transform: translateY(-2px); text-decoration: none; }
.tile strong { font-size: 15px; font-weight: 600; }
.tile .badge { align-self: flex-start; }
.tile .muted { font-size: 13px; }

/* ---- Section headings within forms ---------------------------------------- */
.grouphead {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: hsl(var(--muted-foreground)); font-weight: 600;
  border-bottom: 1px solid hsl(var(--border)); padding-bottom: 8px; margin: 26px 0 14px;
}
.grouphead small { text-transform: none; letter-spacing: 0; font-weight: 400; }

/* ---- Misc ------------------------------------------------------------------ */
.muted { color: hsl(var(--muted-foreground)); }
.error {
  background: hsl(var(--destructive) / 0.1); color: hsl(var(--destructive));
  padding: 11px 14px; border-radius: calc(var(--radius) - 0.15rem);
  border: 1px solid hsl(var(--destructive) / 0.3); font-size: 14px; margin: 16px 0;
}
code {
  background: hsl(var(--muted)); padding: 1px 6px; border-radius: 5px; font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
.danger-zone { border-color: hsl(var(--destructive) / 0.4); background: hsl(var(--destructive) / 0.04); }
button.del {
  width: 36px; height: 36px; padding: 0; border-radius: calc(var(--radius) - 0.2rem);
  font-size: 18px; line-height: 1;
}
.empty {
  text-align: center; padding: 44px 20px; color: hsl(var(--muted-foreground));
  border: 1px dashed hsl(var(--border)); border-radius: var(--radius); margin-top: 14px;
}

/* ---- Status badges --------------------------------------------------------- */
.badge.status-draft     { background: hsl(45 90% 90%); color: hsl(35 80% 30%); border-color: hsl(45 70% 75%); }
.badge.status-issued    { background: hsl(142 60% 90%); color: hsl(142 60% 25%); border-color: hsl(142 45% 72%); }
.badge.status-cancelled { background: hsl(0 75% 93%);  color: hsl(0 65% 42%);  border-color: hsl(0 60% 80%); }
.dark .badge.status-draft     { background: hsl(45 60% 18%); color: hsl(45 90% 75%); border-color: hsl(45 50% 30%); }
.dark .badge.status-issued    { background: hsl(142 40% 16%); color: hsl(142 60% 72%); border-color: hsl(142 35% 28%); }
.dark .badge.status-cancelled { background: hsl(0 45% 20%); color: hsl(0 80% 78%); border-color: hsl(0 45% 34%); }
.status-form { display: inline-block; }
.status-form select { width: auto; margin: 0; padding: 4px 8px; }

/* ---- Label row + inline mini buttons --------------------------------------- */
.lbl-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
button.mini {
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
  padding: 2px 8px; border-radius: 999px; border: 1px solid hsl(var(--border));
  background: hsl(var(--card)); color: hsl(var(--muted-foreground));
}
button.mini:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }

/* ---- Address-book autocomplete -------------------------------------------- */
.ac-wrap { position: relative; }
.ac-menu {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 40; margin-top: 4px;
  background: hsl(var(--popover)); border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 0.15rem); box-shadow: var(--shadow-md);
  max-height: 240px; overflow-y: auto;
}
.ac-item { padding: 8px 11px; cursor: pointer; border-bottom: 1px solid hsl(var(--border)); }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: hsl(var(--accent)); }
.ac-item strong { display: block; font-size: 13px; font-weight: 600; }
.ac-item small { color: hsl(var(--muted-foreground)); font-size: 12px; }

/* ---- CSV import button (file input styled as a button) --------------------- */
.csv-btn { cursor: pointer; font-size: 13px; padding: 7px 12px; }
.csv-btn input { display: none; }

/* ---- Document filter bar --------------------------------------------------- */
.filterbar { margin-bottom: 16px; }
.filter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 18px; }
.filter-grid label { margin: 8px 0; }
select {
  display: block; width: 100%; margin-top: 6px; padding: 9px 12px; font: inherit; font-size: 14px;
  background: hsl(var(--background)); color: hsl(var(--foreground));
  border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 0.15rem); cursor: pointer;
}
select:focus { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 3px hsl(var(--ring) / 0.25); }

/* ---- Template picker tiles (shipment select) ------------------------------ */
.tile.pick { cursor: pointer; flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; }
.tile.pick input { width: auto; margin: 0; }
.tile.pick:has(input:checked) { border-color: hsl(var(--primary)); box-shadow: 0 0 0 1px hsl(var(--primary)); }
.tile.pick strong { flex: 1 1 100%; }

/* ---- Responsive ------------------------------------------------------------ */
@media (max-width: 680px) { .filter-grid { grid-template-columns: 1fr; } }
@media (max-width: 680px) {
  .kv-form, .kv { grid-template-columns: 1fr; }
  .row-between { flex-direction: column; align-items: stretch; }
  .search input { width: 100%; }
  .topbar { padding: 0 14px; }
  .topbar nav > a { padding: 7px 9px; }
  main { margin-top: 22px; }
}
