:root {
  --ccmf-navy: #15396b;
  --ccmf-navy-dark: #0c1a32;
  --ccmf-red: #c8102e;
  --ccmf-light: #f7f7f7;
  --ccmf-steel: #565d64;
  --ccmf-focus: #5b9bd5;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #212529;
  --muted: var(--ccmf-steel);
  --line: #dee2e6;
  --brand: var(--ccmf-navy);
  --brand-hover: #12305b;
  --brand-ink: #ffffff;
  --ok: #1a7f37;
  --warn: #8a5d00;
  --err: var(--ccmf-red);
  --shadow: 0 1px 3px rgba(17, 37, 73, 0.08), 0 8px 16px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }

/* The `hidden` attribute is how every show/hide in app.js works, and it relies on
   the UA stylesheet's `[hidden] { display: none }`. Any author `display` rule beats
   that UA rule, so a layout class silently defeats `hidden` and the element stays
   on screen — which is how the Catalog Export tab came to show "Dealer pricing
   active" and a login form at the same time, with Reconnect appearing to do
   nothing. Keep this ahead of the layout rules below; `!important` is what makes it
   win against `.emery-auth`, `.field`, and any future one. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.skip-link {
  position: absolute;
  top: -48px;
  left: 0;
  z-index: 1100;
  padding: 8px 16px;
  background: var(--ccmf-navy-dark);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

.topbar {
  color: #fff;
  background: var(--ccmf-navy);
  border-bottom: 4px solid var(--ccmf-red);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  max-width: 1120px;
  min-height: 92px;
  margin: 0 auto;
  padding: 12px 24px;
}

.brand-lockup { display: flex; align-items: center; min-width: 0; }
.brand-logo { display: block; width: 190px; height: auto; flex: 0 0 auto; }
.brand-copy {
  min-width: 0;
  margin-left: 18px;
  padding-left: 18px;
  border-left: 1px solid rgba(255, 255, 255, 0.22);
}
.topbar h1 {
  margin: 0;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.1px;
}
.brand-copy p { margin: 3px 0 0; color: #c5cdd8; font-size: 13px; }

.session { display: flex; align-items: center; gap: 12px; }
.user-email { font-size: 13px; color: #dce3ec; }

.card {
  background: var(--panel);
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 6px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.card h2 { margin: 0 0 14px; color: var(--ccmf-navy); font-size: 18px; font-weight: 700; }
.login-card { max-width: 430px; margin: 48px auto 0; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

input[type="email"],
input[type="password"],
input[type="date"] {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 15px;
  color: var(--ink);
  background: #fff;
}
input:focus,
select:focus {
  outline: 0;
  border-color: var(--ccmf-focus);
  box-shadow: 0 0 0 3px rgba(91, 155, 213, 0.28);
}

.btn {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-hover); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-ghost { background: transparent; border-color: rgba(255, 255, 255, 0.36); color: #fff; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }
.card .btn-ghost { border-color: var(--line); color: var(--ccmf-navy); }
.card .btn-ghost:hover { background: #f8f9fa; }
.btn:focus-visible,
.tab:focus-visible,
.link:focus-visible {
  outline: 2px solid var(--ccmf-focus);
  outline-offset: 2px;
}

.upload-card .muted { margin-top: -6px; }
.upload-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.upload-row input[type="file"] { flex: 1; min-width: 220px; font-size: 14px; }

/* Dynamic per-source upload inputs (rendered from sources.json). */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field > span { font-weight: 600; }
.embargo-schedule {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8f9fa;
}
.embargo-schedule.has-time { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.embargo-schedule .hint { grid-column: 1 / -1; margin: 0; max-width: 72ch; }
#source-inputs { display: flex; flex-direction: column; gap: 12px; margin: 4px 0 2px; }
#source-inputs input[type="file"] { font-size: 14px; }
#source-blurb { margin: 2px 0 0; }

.list-head { display: flex; align-items: center; justify-content: space-between; }

.history-head {
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 14px;
}
.history-head h2 { margin-bottom: 5px; }
.history-note { margin: 0; max-width: 62ch; font-size: 13px; line-height: 1.45; }
.history-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8f9fa;
}
.history-filters label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.history-filters select {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 400;
}
.btn-compact { padding: 8px 11px; font-size: 13px; }
.history-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 34px;
  margin-top: 12px;
}
.history-summary { margin: 0; font-size: 13px; }
.pagination { display: flex; align-items: center; gap: 10px; }
.pagination-page {
  min-width: 76px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.table-wrap { overflow-x: auto; }
table.uploads { width: 100%; border-collapse: collapse; font-size: 14px; }
table.uploads th, table.uploads td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); }
table.uploads th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
table.uploads tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-uploaded { background: #e9ecef; color: var(--muted); }
.badge-queued { background: #e9ecef; color: var(--muted); }
.badge-processing { background: #fff3d6; color: var(--warn); }
.badge-done { background: #e6f4ea; color: var(--ok); }
.badge-imported { background: #d7f0e0; color: var(--ok); }
.badge-failed { background: #ffe3e3; color: var(--err); }
.badge-import_failed { background: #ffe3e3; color: var(--err); }
.badge-scheduled { background: #e8eef6; color: var(--ccmf-navy); }
.badge-held { background: #fff3d6; color: var(--warn); }
.badge-blocked { background: #ffe3e3; color: var(--err); }
.badge-releasing { background: #fff3d6; color: var(--warn); }
.badge-released { background: #d7f0e0; color: var(--ok); }
.substatus { font-size: 12px; margin-top: 3px; }
.substatus.ok { color: var(--ok); }
.substatus.err { color: var(--err); cursor: help; }

.link { background: none; border: none; padding: 0; color: var(--brand); cursor: pointer; font-size: 14px; text-decoration: underline; }
.link:hover { color: var(--brand-hover); }

.muted { color: var(--muted); }
.status { margin: 12px 0 0; font-size: 14px; color: var(--ok); }
.status.error, .error { color: var(--err); }
.status.error { font-weight: 500; }

code { background: #e9ecef; padding: 1px 5px; border-radius: 3px; font-size: 90%; }

.cell-file .fname { font-weight: 550; }
.cell-file .fsize { font-size: 12px; color: var(--muted); margin-top: 2px; }
.count { font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 14px; flex-wrap: wrap; }

/* ---- catalog releases -------------------------------------------------- */
.release-head {
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 18px;
}
.release-head > div { max-width: 66ch; }
.release-head h2 { margin-bottom: 8px; }
.release-head .muted { margin: 0; line-height: 1.5; }
.release-name { font-weight: 650; min-width: 150px; }
.release-source { margin-top: 3px; color: var(--muted); font-size: 12px; }
table.releases td { vertical-align: top; }
.btn-release {
  padding: 7px 10px;
  border-color: var(--brand);
  background: #fff;
  color: var(--brand);
  white-space: nowrap;
}
.btn-release:hover { background: #eef2f7; }
.btn-release:disabled { opacity: 0.55; cursor: default; }

/* ---- tabs -------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(17, 37, 73, 0.08);
}
.tab {
  position: relative;
  margin-bottom: -1px;
  padding: 13px 18px 11px;
  color: var(--ccmf-steel);
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--ccmf-navy); background: #f8f9fa; }
.tab.active {
  color: var(--ccmf-navy);
  background: #f8f9fa;
}
.tab.active::after {
  position: absolute;
  right: 12px;
  bottom: 0;
  left: 12px;
  height: 3px;
  background: var(--ccmf-red);
  content: "";
}

/* ---- catalog export form ---------------------------------------------- */
input[type="text"],
select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 15px;
  color: var(--ink);
  background: #fff;
}

.emery-auth {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 18px;
  background: #f8f9fa;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.emery-auth .stack { width: 100%; }
#emery-disconnected { display: block; }
#emery-disconnected .muted { margin: 0 0 12px; }

.btn-secondary { background: #e9ecef; color: var(--ink); border-color: #ced4da; align-self: flex-start; }
.btn-secondary:hover { background: #dde1e5; }

.export-form { gap: 18px; }
.fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; margin: 0; }
.fieldset legend { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0 6px; }

.checkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-size: 14px !important; color: var(--ink) !important; }
.check input { width: auto; }

.filter-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.filter-row > label { flex: 1; min-width: 160px; }
.filter-row > label.check { flex: 0 0 auto; min-width: 0; }

.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
input:disabled + *, input:disabled, select:disabled { opacity: 0.55; }

/* Toast notifications (import finished) */
#toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  max-width: min(380px, 92vw);
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.35;
  box-shadow: inset 0 3px 0 var(--muted), var(--shadow);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { box-shadow: inset 0 3px 0 var(--ok), var(--shadow); }
.toast-err { box-shadow: inset 0 3px 0 var(--err), var(--shadow); }

@media (max-width: 760px) {
  .topbar-inner {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 10px 16px 12px;
  }
  .brand-logo { width: 160px; }
  .brand-copy { margin-left: 14px; padding-left: 14px; }
  .topbar h1 { font-size: 18px; }
  .session {
    justify-content: space-between;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.16);
  }
}

@media (max-width: 640px) {
  .shell { padding: 16px 14px 48px; }
  .card { padding: 18px; }
  .login-card { margin-top: 24px; }
  .tabs { margin-bottom: 16px; }
  .history-head { gap: 12px; }
  .history-filters { grid-template-columns: 1fr; }
  .embargo-schedule.has-time { grid-template-columns: minmax(0, 1fr); }
  .history-filters .btn { justify-self: start; }
  .history-footer { align-items: flex-start; flex-direction: column; }
  .pagination { justify-content: space-between; width: 100%; }
  .release-head { flex-direction: column; gap: 12px; }
  .release-head .btn { align-self: flex-start; }
}

@media (max-width: 420px) {
  .brand-logo { width: 128px; }
  .brand-copy {
    margin-left: 12px;
    padding-left: 12px;
  }
  .topbar h1 { font-size: 16px; line-height: 1.25; }
  .brand-copy p { font-size: 11px; line-height: 1.3; }
}
