/* =========================================================================
   Excel Print Tool — styles
   Sections:
     1. Screen UI (app chrome, sidebar, controls)
     2. Print sheet + @page (page size / orientation driven by CSS vars)
     3. Format-specific styles (cards, table, grid, compact, directory)
     4. @media print — hide UI, print only the sheet
   ========================================================================= */

/* ---------- design tokens (light + dark) ---------- */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2129;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.06);
}
:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --bg: #14161a;
    --panel: #1e2126;
    --ink: #e8eaed;
    --muted: #9aa0a8;
    --line: #2c3038;
    --accent: #3b82f6;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

/* ---------- app layout ---------- */
.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 18px 18px 60px;
}
.sidebar h1 {
  font-size: 17px;
  margin: 0 0 2px;
}
.sidebar .tagline {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 18px;
}

.workspace {
  overflow: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ---------- control groups ---------- */
.group { margin-bottom: 18px; }
.group > label.group-label,
.group-label {
  display: block;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}
.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}
.field .val { color: var(--ink); font-weight: 600; }

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.file-drop {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  transition: border-color .15s, background .15s;
}
.file-drop:hover, .file-drop.drag { border-color: var(--accent); background: rgba(37,99,235,.05); }
.file-drop strong { color: var(--ink); }
.file-drop input { display: none; }

.format-list { display: flex; flex-direction: column; gap: 8px; }
.format-opt {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.format-opt:hover { border-color: var(--accent); }
.format-opt.active { border-color: var(--accent); background: rgba(37,99,235,.07); }
.format-opt .fo-name { font-weight: 600; }
.format-opt .fo-desc { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.col-toggles { display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; }
.col-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.col-toggle input { accent-color: var(--accent); }

.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 8px; }

button.btn {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button.btn:hover { filter: brightness(1.05); }
button.btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
button.btn:disabled { opacity: .5; cursor: not-allowed; }

.hint { color: var(--muted); font-size: 12px; }
.empty-preview {
  color: var(--muted);
  text-align: center;
  margin-top: 15vh;
  max-width: 380px;
}
.status-bar {
  font-size: 12px;
  color: var(--muted);
  align-self: stretch;
}

/* =========================================================================
   2. PRINT SHEET — the live preview page that also becomes the printout.
   Page geometry is driven by CSS variables set from JS.
   ========================================================================= */
.sheet {
  --page-w: 210mm;      /* A4 portrait default */
  --page-h: 297mm;
  --margin: 12mm;
  --font: 12px;
  --gap: 8px;

  width: var(--page-w);
  min-height: var(--page-h);
  padding: var(--margin);
  background: #ffffff;
  color: #111111;         /* preview always prints dark-on-white */
  box-shadow: var(--shadow);
  font-size: var(--font);
  margin: 0 auto;
}
.sheet .doc-title {
  text-align: center;
  font-size: 1.7em;
  margin: 0 0 0.7em;
  font-weight: 700;
  color: #111;
}

/* ---------- 3a. NAME CARDS (reference PDF) ---------- */
.nc-grid {
  display: grid;
  gap: 0;                 /* cards share dashed cut-lines, like the sample */
  border-top: 1px dashed #333;
  border-left: 1px dashed #333;
}
.nc-card {
  border-right: 1px dashed #333;
  border-bottom: 1px dashed #333;
  min-height: var(--nc-card-h, 90px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  text-align: center;
}
.nc-name {
  font-weight: 700;
  font-size: 1.15em;
  color: #111;
}

/* ---------- 3b. TABLE ---------- */
.tbl {
  width: 100%;
  border-collapse: collapse;
}
.tbl th, .tbl td {
  border: 1px solid #999;
  padding: var(--gap);
  text-align: left;
  vertical-align: top;
  color: #111;
}
.tbl th { background: #f0f0f0; font-weight: 700; }
.tbl.tbl-zebra tbody tr:nth-child(even) td { background: #f7f7f7; }

/* ---------- 3c. CARD GRID ---------- */
.cg-grid { display: grid; gap: calc(var(--gap) * 1.4); }
.cg-card {
  border: 1px solid #bbb;
  border-radius: 8px;
  padding: calc(var(--gap) * 1.2);
  break-inside: avoid;
}
.cg-heading {
  font-weight: 700;
  font-size: 1.15em;
  margin-bottom: 6px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 4px;
  color: #111;
}
.cg-field { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.cg-label { color: #555; }
.cg-value { font-weight: 600; text-align: right; color: #111; }

/* ---------- 3d. COMPACT LIST ---------- */
.cl-list { list-style: none; margin: 0; padding: 0; column-gap: 24px; }
.cl-item {
  padding: 3px 0;
  border-bottom: 1px dotted #ccc;
  break-inside: avoid;
}
.cl-primary { font-weight: 700; color: #111; }
.cl-rest { color: #555; margin-left: 8px; }

/* ---------- 3e. DIRECTORY (spacious) ---------- */
.dir-wrap { display: flex; flex-direction: column; gap: calc(var(--gap) * 2.2); }
.dir-entry { break-inside: avoid; padding-bottom: 6px; border-bottom: 1px solid #e5e5e5; }
.dir-name { font-weight: 700; font-size: 1.25em; margin-bottom: 8px; color: #111; }
.dir-line { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; }
.dir-label { color: #555; white-space: nowrap; }
.dir-dots { flex: 1; border-bottom: 1px dotted #bbb; transform: translateY(-3px); }
.dir-value { font-weight: 600; color: #111; white-space: nowrap; }

/* =========================================================================
   4. PRINT — only the sheet, at the exact page size / orientation.
   @page size is injected by JS into #page-style. Here we hide the UI.
   ========================================================================= */
@media print {
  body { background: #fff; }
  .app { display: block; height: auto; }
  .sidebar, .status-bar, .no-print { display: none !important; }
  .workspace { padding: 0; display: block; overflow: visible; }
  .sheet {
    box-shadow: none;
    margin: 0;
    width: auto;         /* let @page control the physical size */
    min-height: 0;
  }
  /* Repeat table headers on each printed page. */
  .tbl thead { display: table-header-group; }
  tr, .cg-card, .dir-entry, .cl-item, .nc-card { break-inside: avoid; }
}
