/* Calibre Pricing Tool — application shell.
   Design: minimal, calm, precise. Calibre red only for primary actions, the
   active nav state and the logo; everything else neutral grey. 8px spacing
   scale, 1px borders, 6px radius, system font. */

:root {
  --red: #c8102e;
  --red-dark: #a50d26;
  --ink: #1a1a1a;
  --ink-2: #444;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #fafafa;
  --panel: #ffffff;
  --sidebar: #ffffff;
  --ok: #157347;
  --warn: #b45309;
  --danger: #c8102e;
  --radius: 6px;
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App layout ----------
   The content column needs min-width:0 or a wide table stretches the grid track
   and the whole page scrolls sideways instead of the table. */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  min-width: 0;
}
.sidebar .logo {
  font-weight: 800; font-size: 20px; letter-spacing: 0.5px;
  color: var(--red); padding: var(--s3) var(--s2) var(--s2);
}
/* The brandmark is an uploaded logo when one is set, a wordmark otherwise. */
.sidebar .logo img { display: block; max-width: 100%; max-height: 60px; }
.nav { display: flex; flex-direction: column; padding: 0 var(--s1); gap: 2px; flex: 1; }
.nav a {
  color: var(--ink-2); padding: 10px 12px; border-radius: var(--radius);
  font-weight: 500; display: flex; align-items: center; gap: 10px;
}
.nav a:hover { background: #f3f4f6; text-decoration: none; }
.nav a.active { background: #fdecec; color: var(--red); }
.nav a.active .dot { background: var(--red); }
.nav .dot { width: 6px; height: 6px; border-radius: 50%; background: #cbd0d6; }
.sidebar .account {
  border-top: 1px solid var(--line); padding: var(--s2);
  font-size: 13px; color: var(--muted);
}
.sidebar .account .email {
  color: var(--ink-2); font-weight: 600; display: block; margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Fluid gutters, capped reading width, centred on very wide screens. */
.content {
  padding: clamp(16px, 3vw, 32px);
  width: 100%; max-width: 1440px; margin: 0 auto; min-width: 0;
}
.pagehead {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s3);
}
.pagehead-text { min-width: 0; }
.breadcrumb { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.pagehead h1 { font-size: clamp(19px, 2.2vw, 24px); margin: 0; font-weight: 700; line-height: 1.25; }
.pagehead .sub { color: var(--muted); margin-top: 4px; }
.pagehead .actions { display: flex; gap: var(--s1); flex-wrap: wrap; }

/* ---------- Components ---------- */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); color: #fff; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: var(--s2); }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--s2) var(--s2) 18px;
}
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.card .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.card .value.empty { color: #b6bcc4; font-weight: 600; font-size: 18px; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.card.alert { border-color: #f3c9cf; background: #fef6f7; }
.card.alert .value { color: var(--red); }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: clamp(16px, 2.4vw, 24px); margin-top: var(--s3);
  min-width: 0;
}
/* Any panel holding a wide table scrolls itself instead of the page. */
.panel:has(> table.grid), .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.panel h2 { font-size: 15px; margin: 0 0 var(--s1); }
.panel > h2:first-child { margin-top: 0; }
.empty-state { color: var(--muted); padding: var(--s3) 0; text-align: center; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.3px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel);
}
table.grid td { padding: 9px 10px; border-bottom: 1px solid #f0f1f3; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.blocked { background: #fdecec; color: var(--red); }
.badge.ok { background: #e7f4ec; color: var(--ok); }
.badge.warn { background: #fef3e2; color: var(--warn); }

/* ---------- Auth (centered card) ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: #f6f7f8; padding: var(--s2); }
.auth-card {
  width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: var(--s4); box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.auth-card .logo { text-align: center; font-weight: 800; font-size: 26px; color: var(--red); margin-bottom: var(--s3); letter-spacing: 0.5px; }
.auth-card .logo img { display: block; margin: 0 auto; max-height: 72px; max-width: 70%; }
.auth-card h1 { font-size: 18px; margin: 0 0 var(--s2); }
.field { margin-bottom: var(--s2); }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px; font-family: var(--font);
}
.field input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px #fdecec; }
.auth-card .btn-primary { width: 100%; }
.auth-links { margin-top: var(--s2); font-size: 13px; text-align: center; }
.form-error { background: #fdecec; color: var(--red-dark); border: 1px solid #f3c9cf; border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin-bottom: var(--s2); }
.helptext { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* messages / toasts */
.messages { list-style: none; padding: 0; margin: 0 0 var(--s2); }
.messages li { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 8px; font-size: 13px; }
.messages li.success { background: #e7f4ec; color: var(--ok); }
.messages li.error { background: #fdecec; color: var(--red-dark); }
.messages li.info { background: #eef2ff; color: #3730a3; }

/* ---------- Progress (send run) ---------- */
.progress-block { margin-bottom: var(--s3); }
.progress-block .phase-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.progress-block .phase-label .name { font-weight: 600; }
.bar { height: 16px; background: #eef0f2; border-radius: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--red); width: 0; transition: width .4s ease; }
.bar > span.ok { background: var(--ok); }
.progress-block .sub { color: var(--muted); font-size: 12px; margin-top: 6px; }
.run-controls { display: flex; gap: var(--s1); margin-top: var(--s1); }
.summary-band { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--s1); }
.summary-band .stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; background: var(--panel); }
.summary-band .stat .n { font-size: 22px; font-weight: 700; }
.summary-band .stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }

/* ---------- List toolbar, pagination, forms ---------- */
.toolbar { display: flex; gap: var(--s1); align-items: center; margin-bottom: var(--s2); flex-wrap: wrap; }
.toolbar form { display: flex; gap: var(--s1); align-items: center; }
.toolbar input[type=search], .toolbar select {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 14px; font-family: var(--font); min-width: 220px;
}
.toolbar .spacer { flex: 1; }
.toolbar .count { color: var(--muted); font-size: 13px; }
table.grid td a { font-weight: 600; }
/* Single searchable field built by searchable-select.js; the source <select> is
   hidden but still submitted, so it must not be display:none-d out of the form. */
.searchable-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px; font-family: var(--font); background: #fff;
}
.searchable-input.is-unmatched { border-color: var(--red); }
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin: 2px 0 0;
  padding: 4px; list-style: none; max-height: 280px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.combo-list[hidden] { display: none; }
.combo-option { padding: 8px 10px; border-radius: var(--radius); cursor: pointer; font-size: 14px; }
.combo-option:hover, .combo-option.is-active { background: #fdf5f6; color: var(--red-dark); }
.combo-empty { padding: 8px 10px; font-size: 13px; color: var(--muted); }
/* Outspecifies `form.stack select { width: 100% }`, which would otherwise keep the
   hidden source select full width and force a horizontal scrollbar on the page. */
select.searchable-source,
form.stack select.searchable-source,
form.stack .field select.searchable-source {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); border: 0; opacity: 0; pointer-events: none;
}

/* Active-filter chips: each removes one filter, the button clears them all. */
.filterchips { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: var(--s2); font-size: 13px; }
.filterchips .muted { color: var(--muted); }
.filterchips .chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink-2);
}
.filterchips .chip:hover { border-color: var(--red); color: var(--red); }
.filterchips .chip .x { font-size: 15px; line-height: 1; color: var(--muted); }
.filterchips .chip:hover .x { color: var(--red); }
.btn.btn-small { padding: 4px 10px; font-size: 12px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.pagination { display: flex; gap: 6px; align-items: center; margin-top: var(--s2); font-size: 13px; }
.pagination a, .pagination span.current {
  padding: 6px 11px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink-2);
}
.pagination span.current { background: var(--red); color: #fff; border-color: var(--red); }
.pagination .muted { border: none; color: var(--muted); }
.pagination .spacer { flex: 1; }
.pagination .pagesize { display: flex; align-items: center; gap: 6px; }
.pagination .pagesize select {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px; font-family: var(--font); background: #fff; color: var(--ink-2);
}

form.stack .field textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); font-family: var(--font); }
form.stack .field select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; font-family: var(--font); background: #fff; }
form.stack { max-width: 560px; }
.checkline { display: flex; align-items: center; gap: 8px; margin-bottom: var(--s2); }
.checkline input { width: 16px; height: 16px; }
.form-actions { display: flex; gap: var(--s1); margin-top: var(--s2); }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--red-dark); font-size: 12px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.detail-cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.linkbtn { background: none; border: none; color: var(--red); font: inherit; cursor: pointer; padding: 0; font-weight: 600; }
.muted-inline { color: var(--muted); }

/* ---------- Django as_div forms ---------- */
form.stack > div { margin-bottom: var(--s2); }
form.stack label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
form.stack input[type=text], form.stack input[type=email], form.stack input[type=password],
form.stack input[type=date], form.stack input[type=number], form.stack input[type=search],
form.stack input[type=file], form.stack textarea, form.stack select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px; font-family: var(--font); background: #fff;
}
form.stack input[type=color] { width: 56px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
form.stack input:focus, form.stack textarea:focus, form.stack select:focus {
  outline: none; border-color: var(--red); box-shadow: 0 0 0 3px #fdecec;
}
form.stack input[type=checkbox] { width: 16px; height: 16px; }
form.stack .helptext { display: block; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--s3); align-items: start; }
.settings-grid .panel { margin-top: 0; }
.avatar-row { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s2); }
.avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.avatar-empty { display: grid; place-items: center; background: #fdecec; color: var(--red); font-weight: 700; font-size: 24px; }
.logo-preview { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s2); flex-wrap: wrap; }
.logo-preview img { max-height: 56px; max-width: 240px; }
.mail-result { margin-top: var(--s2); border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius); padding: 12px 14px; font-size: 13px; }
.mail-result.ok { border-left-color: var(--ok); background: #f3faf5; }
.mail-result.fail { border-left-color: var(--danger); background: #fef6f7; }
.mail-summary { font-weight: 700; margin-bottom: 4px; }
.mail-detail { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--ink-2); word-break: break-word; }
.mail-hint { margin-top: 6px; color: var(--ink-2); }
.mail-config { margin-top: 10px; font-size: 12px; grid-template-columns: 90px minmax(0, 1fr); }

/* ---------- Send run controls ---------- */
.send-actions { display: flex; gap: var(--s1); align-items: center; flex-wrap: wrap; }
.bulk-resolve { display: flex; gap: var(--s1); flex-wrap: wrap; margin: var(--s1) 0; }
.bulk-resolve input[type=text] {
  flex: 1 1 320px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); font-family: var(--font); font-size: 14px;
}

/* ---------- Drop zone (file uploads) ---------- */
.dropzone {
  border: 2px dashed #cfd4da; border-radius: 10px; background: #fbfbfc;
  padding: var(--s4) var(--s2); text-align: center; cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--red); background: #fdf5f6; }
.dropzone.has-file { border-style: solid; border-color: var(--ok); background: #f4faf6; }
.dropzone .dz-icon { font-size: 26px; }
.dropzone .dz-title { font-weight: 600; margin-top: 6px; }
.dropzone .dz-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.dropzone input[type=file] { display: none; }
.dz-progress { height: 8px; background: #eef0f2; border-radius: 4px; overflow: hidden; margin-top: var(--s2); }
.dz-progress > span { display: block; height: 100%; width: 0; background: var(--red); transition: width .2s ease; }
.dz-progress.done > span { background: var(--ok); }
.dz-status { font-size: 13px; margin-top: 8px; color: var(--ink-2); }
.dz-status.error { color: var(--red-dark); white-space: pre-wrap; }
.dz-status.success { color: var(--ok); }

/* ---------- Panel head with an action ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); flex-wrap: wrap; margin-bottom: var(--s1); }
.panel-head h2 { margin: 0; }
td.rowactions { white-space: nowrap; }
td.rowactions > form { display: inline; }
td.rowactions > a, td.rowactions > form { margin-right: 8px; }
.linkbtn.danger { color: var(--danger); }
.btn-danger { border-color: #f3c9cf; color: var(--red-dark); background: #fef6f7; }
.btn-danger:hover { background: #fdecec; }
.danger-zone { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s3); padding-top: var(--s2); border-top: 1px solid var(--line); }

/* ---------- Bulk selection toolbar ---------- */
/* display:flex would otherwise beat the UA's [hidden] rule and show an empty bar. */
.bulkbar[hidden] { display: none; }
.bulkbar {
  display: flex; gap: var(--s1); align-items: center; flex-wrap: wrap;
  background: #fdf5f6; border: 1px solid #f3c9cf; border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: var(--s2);
}
.bulkbar .count { font-weight: 600; }
table.grid td.check, table.grid th.check { width: 34px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 188px minmax(0, 1fr); }
  .detail-cols { grid-template-columns: 1fr; }
}

/* Tablet & phone: the sidebar becomes a sticky top bar with a scrolling nav. */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; z-index: 20; height: auto;
    flex-direction: row; align-items: center; gap: var(--s1);
    border-right: none; border-bottom: 1px solid var(--line);
    padding: 0 var(--s2); overflow: visible;
  }
  .sidebar .logo { padding: 12px 0; font-size: 17px; flex: none; }
  .nav {
    flex-direction: row; flex: 1; gap: 4px; padding: 0;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; padding: 8px 10px; }
  .nav .dot { display: none; }
  /* Sits above the scrolling nav, so it needs its own background and a rule to
     separate it from whatever nav item scrolls underneath. */
  .sidebar .account {
    border-top: none; border-left: 1px solid var(--line);
    padding: 12px 0 12px var(--s2); margin-left: var(--s1); flex: none;
    background: var(--sidebar);
    display: flex; align-items: center; gap: var(--s1);
  }
  .sidebar .account .email { display: none; }
  .detail-cols { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 120px minmax(0, 1fr); }
  form.stack { max-width: none; }
  .toolbar form { flex-wrap: wrap; width: 100%; }
  .toolbar input[type=search], .toolbar select { min-width: 0; flex: 1 1 160px; }
}

@media (max-width: 560px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
  .card .value { font-size: 24px; }
  .pagehead .actions { width: 100%; }
  .pagehead .actions .btn { flex: 1 1 auto; text-align: center; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .kv dt { margin-top: 8px; }
  .summary-band { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1 1 auto; text-align: center; }
}
