:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-soft: #edf1f5;
  --text: #1a2332;
  --muted: #64748b;
  --navy: #1e3a5f;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.04);
  --shadow-paper: 0 2px 8px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

/* Slim Remit header — quieter navy */
.site-header {
  background: var(--navy);
  color: #e8eef5;
  border-bottom: none;
}
.header-inner {
  max-width: 1260px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.site-header h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 600;
  color: #fff;
}
.site-header .tag {
  color: rgba(232, 238, 245, 0.65);
  font-size: 0.75rem;
  font-weight: 500;
}
.header-meta {
  color: rgba(232, 238, 245, 0.7);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Centered hero */
.hero {
  text-align: center;
  padding: 1.75rem 1.25rem 0.5rem;
  max-width: 1260px;
  margin: 0 auto;
}
.hero-title {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
}
.hero-sub {
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}

/* Workspace */
.workspace {
  max-width: 1260px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2.5rem;
}
.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 32px;
  align-items: start;
}

/* Left form */
.form-col { min-width: 0; }
.top-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

/* Accordion cards */
.card.accordion {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.85rem;
  overflow: hidden;
}
.card.accordion > .card-summary {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-weight: 600;
  color: var(--text);
}
.card.accordion > .card-summary::-webkit-details-marker { display: none; }
.card-title { flex: 1; font-size: 0.95rem; }
.card-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--accent-soft);
  position: relative;
}
.card-icon::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.85;
}
.brand-icon { background: #ecfdf5; }
.brand-icon::after { background: #059669; }
.csv-icon { background: #eff6ff; }
.csv-icon::after { background: var(--accent); }
.rules-icon { background: #fef3c7; }
.rules-icon::after { background: #d97706; }
.chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  margin-right: 0.25rem;
}
.card.accordion[open] > .card-summary .chevron {
  transform: rotate(-135deg);
  margin-top: 4px;
}
.card-body {
  padding: 0 1.15rem 1.15rem;
  border-top: 1px solid var(--border-soft);
  padding-top: 1rem;
}

.subhead {
  margin: 1rem 0 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
input[type="number"],
input[type="text"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  margin-bottom: 0.75rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea {
  min-height: 88px;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.checks label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  margin-bottom: 0.5rem;
  cursor: pointer;
}
.checks input { width: auto; margin: 0; }
.radio-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.radio-row label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text);
  margin: 0;
  cursor: pointer;
}

/* Buttons */
button, .btn-primary, .btn-secondary, .btn-outline, a.btn-secondary {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.15rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--accent);
  color: var(--accent);
}
.btn-outline:hover { background: var(--accent-soft); }
.btn-secondary, a.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
}
.btn-secondary:hover, a.btn-secondary:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}
button:disabled, a.btn-secondary[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.file-btn { display: inline-flex; padding: 0.5rem 0.9rem; }
.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
  margin-bottom: 0.5rem;
}
.primary-row { margin-top: 1.1rem; }
.primary-row .btn-primary {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  width: 100%;
}

/* Stats frame — own card above pack preview */
.stats-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.15rem 1.05rem;
  margin-bottom: 0.85rem;
}
.stats-period {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}
.stats-frame.is-empty .stats-period { color: var(--muted); }
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.55rem;
  margin-bottom: 0;
}
.stats-frame.is-empty .stats { opacity: 0.55; }
.stat {
  background: #f8fafc;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border-soft);
}
.stat .label { font-size: 0.7rem; color: var(--muted); }
.stat .value {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  margin-top: 0.15rem;
}
.stat.accent .value { color: var(--ok); }
.stats-empty {
  display: none;
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.stats-frame.is-empty .stats-empty { display: block; }

.calc-line {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border-soft);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}
.calc-line.total {
  font-weight: 700;
  border-bottom: none;
  margin-top: 0.35rem;
  color: var(--accent);
}
.exclusions { padding-left: 1.1rem; margin: 0.25rem 0 0; }
.exclusions li { margin: 0.25rem 0; }
.exclusions .amt { color: var(--warn); font-variant-numeric: tabular-nums; }
.audit { font-size: 0.8rem; color: var(--muted); }
.audit code { color: var(--text); }

.error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  display: none;
}
.error.show { display: block; }
.hint { font-size: 0.8rem; color: var(--muted); margin: 0.35rem 0 0.5rem; }
.hint.tight { margin-top: 0; margin-bottom: 0.65rem; }
.hidden { display: none !important; }

.period-banner {
  font-size: 0.85rem;
  color: var(--text);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0 0.75rem;
  border: 1px solid #dbeafe;
}

.more-opts {
  margin: 0.5rem 0 0.25rem;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  padding: 0.35rem 0.75rem 0.5rem;
  background: #fafbfc;
}
.more-opts > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0;
  list-style: none;
}
.more-opts > summary::-webkit-details-marker { display: none; }
.more-opts > summary::before { content: "▸ "; color: var(--accent); }
.more-opts[open] > summary::before { content: "▾ "; }
.stats-frame .calc-detail {
  margin-top: 0.75rem;
  margin-bottom: 0;
}

footer {
  text-align: center;
  padding: 1.5rem 1rem 2.5rem;
  color: var(--muted);
  font-size: 0.75rem;
}

/* Right preview column — no sticky/max-height so page scrolls with tall pack */
.preview-col {
  min-width: 0;
  align-self: start;
  padding-bottom: 0.5rem;
}

/* Pack ready? soft gate — thin quiet card above toolbar */
.pack-ready {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem 1rem 0.85rem;
  margin-bottom: 0.75rem;
}
.pack-ready-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
}
.pack-ready-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.01em;
}
.pack-ready-status {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.pack-ready-status.is-ready { color: var(--ok); }
.pack-ready-status.is-blocked { color: var(--warn); }
.pack-ready-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.2rem 0.75rem;
}
.pack-ready-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 0;
}
.pack-ready-list li.is-ok { color: var(--text); }
.pack-ready-list li.is-ok .pr-mark { color: var(--ok); }
.pack-ready-list li.is-fail .pr-mark { color: var(--danger); }
.pr-mark {
  font-size: 0.75rem;
  font-weight: 700;
  width: 0.9rem;
  text-align: center;
  flex-shrink: 0;
}
.pr-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pack-ready-ack {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.55rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}
.pack-ready-ack input { margin: 0; }
.pack-ready-warn {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}
.pack-ready-anyway {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
}
button.linkish, .linkish {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  border-radius: 0;
  box-shadow: none;
}
button.linkish:hover { color: var(--accent); background: none; }
@media (max-width: 520px) {
  .pack-ready-list { grid-template-columns: 1fr; }
}

.preview-toolbar {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin: 0 0 0.75rem;
}

/* Pack preview frame — expands to full pack height; page body scrolls */
.pack-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-paper);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  overflow: visible;
}
.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  text-align: center;
  min-height: 280px;
}
.placeholder-doc {
  width: 70%;
  max-width: 280px;
  margin-bottom: 1.25rem;
  opacity: 0.55;
}
.ph-line {
  height: 10px;
  background: #e2e8f0;
  border-radius: 4px;
  margin-bottom: 0.55rem;
}
.ph-title { width: 45%; height: 14px; background: #cbd5e1; }
.ph-wide { width: 100%; }
.ph-mid { width: 65%; }
.ph-table { margin: 1rem 0; }
.ph-total { width: 35%; margin-left: auto; background: #bfdbfe; height: 12px; }
.placeholder-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 260px;
}
.preview-built {
  min-width: 0;
  display: block;
}
#packFrame {
  width: 100%;
  display: block;
  height: 200px; /* set by JS to content height */
  min-height: 0;
  border: none;
  border-radius: 0;
  background: #fff;
  overflow: hidden;
}

.map-panel {
  margin-top: 0.75rem;
  padding: 0.85rem;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
}
.map-heading {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}
.map-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
}
.map-row label { margin-bottom: 0.2rem; }
.map-row select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  margin-bottom: 0;
}
.tips-note {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .editor-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
  .hero-title { font-size: 1.35rem; }
  .header-meta { font-size: 0.72rem; }
}
@media (max-width: 600px) {
  .map-fields { grid-template-columns: 1fr; }
  .workspace { padding: 0.85rem 0.85rem 2rem; }
  .header-inner { flex-wrap: wrap; gap: 0.35rem; }
  .preview-toolbar .btn-secondary { font-size: 0.8rem; padding: 0.4rem 0.65rem; }
}

/* ========== View tabs (pill strip) ========== */
.view-tabs-wrap {
  max-width: 1260px;
  margin: 0 auto;
  padding: 1rem 1.25rem 0;
  text-align: center;
}
.view-tabs {
  display: inline-flex;
  align-items: stretch;
  gap: 0.25rem;
  background: #e8edf3;
  border-radius: 999px;
  padding: 0.3rem;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
  max-width: 100%;
}
.view-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.7rem 1.75rem;
  border-radius: 999px;
  cursor: pointer;
  min-width: 7.5rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.view-tab:hover:not(.is-active) {
  background: rgba(255, 255, 255, 0.45);
}
.view-tab.is-active {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 2px 8px rgba(30, 58, 95, 0.28);
}
.view-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.view-tabs-banner {
  margin: 0.65rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.tab-panel.hidden,
.tab-panel[hidden] {
  display: none !important;
}

/* Shared pack slot */
.pack-slot {
  min-width: 0;
}
.pack-frame[hidden] {
  display: none !important;
}
.pack-slot > .pack-frame {
  display: flex;
}

/* ========== PDF view ========== */
.pdf-view {
  max-width: 820px;
  margin: 0 auto;
}
.pdf-ready-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.pdf-ready-label {
  font-weight: 600;
  color: var(--text);
}
.pdf-toolbar {
  justify-content: center;
  margin-bottom: 1rem;
}
.pdf-pack-slot .pack-frame {
  max-width: 820px;
  margin: 0 auto;
}

/* ========== Email view ========== */
.email-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
.email-col-label {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.email-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
}
.email-dot.live {
  background: var(--ok);
}
.email-editor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem 1.25rem;
}
.email-editor-card .optional {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.8rem;
}
.email-body-input {
  font-family: inherit;
  font-size: 0.9rem;
  min-height: 120px;
  resize: vertical;
}
.email-attach-note {
  margin-top: 0.25rem;
  margin-bottom: 0.85rem;
}
.email-actions {
  margin-top: 0.25rem;
  margin-bottom: 0;
}
.email-actions .btn-primary {
  width: auto;
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
}

.email-mock {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-paper);
  overflow: hidden;
  background-image: radial-gradient(circle at 1px 1px, #e8edf3 1px, transparent 0);
  background-size: 16px 16px;
  background-color: #f7f9fc;
}
.email-mock-chrome {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem;
  background: #eef2f7;
  border-bottom: 1px solid var(--border);
}
.email-mock-dots {
  display: inline-flex;
  gap: 5px;
}
.email-mock-dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5e1;
  display: block;
}
.email-mock-dots i:nth-child(1) { background: #f87171; }
.email-mock-dots i:nth-child(2) { background: #fbbf24; }
.email-mock-dots i:nth-child(3) { background: #34d399; }
.email-mock-title {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}
.email-mock-body {
  margin: 0.85rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem 1.15rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}
.email-mock-meta {
  font-size: 0.88rem;
  color: var(--text);
  margin-bottom: 0.85rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.em-k {
  display: inline-block;
  min-width: 3.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.email-mock-subject {
  margin-top: 0.45rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
}
.email-mock-message {
  font-size: 0.92rem;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.55;
  min-height: 4rem;
  margin-bottom: 1rem;
}
.email-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.75rem;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}
.attach-icon { font-size: 0.95rem; }
.attach-name { font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .view-tabs {
    width: 100%;
    justify-content: stretch;
  }
  .view-tab {
    flex: 1;
    min-width: 0;
    padding: 0.65rem 0.5rem;
    font-size: 0.85rem;
  }
  .email-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
}
@media (max-width: 600px) {
  .view-tabs-wrap { padding: 0.75rem 0.85rem 0; }
  .view-tab { font-size: 0.8rem; padding: 0.55rem 0.35rem; }
}
