/* Resell Ops design system. Page-specific rules live in /static/pages/<slice>.css. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --border: #e5e7eb;
  --border-soft: #eff0f3;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --navy: #0f172a;
  --navy-hover: #1e293b;
  --link: #3730a3;
  --focus: #6366f1;

  --ok: #15803d;
  --ok-bg: #dcfce7;
  --ok-line: #16a34a;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --warn-line: #f59e0b;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info: #4338ca;
  --info-bg: #e0e7ff;
  --grey: #4b5563;
  --grey-bg: #f3f4f6;

  --radius: 10px;
  --radius-sm: 8px;
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

img, svg { max-width: 100%; }

h1, h2, h3, h4 { color: var(--text); line-height: 1.25; }
h2 { font-family: var(--font-serif); font-weight: 500; font-size: 22px; margin: 32px 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 24px 0 8px; }
p { margin: 0 0 12px; }

code, pre, kbd { font-family: var(--font-mono); font-size: 0.92em; }
pre {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------------------------------------------------------------- shell */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 20px;
}

.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { display: block; }
.brand .eyebrow { color: var(--text); }

.company-switch {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  padding: 3px;
  gap: 2px;
  background: var(--grey-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.company-switch a {
  padding: 4px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.company-switch a:hover { color: var(--text); text-decoration: none; }
.company-switch a.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.user-box { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }

.topbar-tabs {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px 24px;
  margin-bottom: 24px;
}
.page-title { min-width: 0; }
.page-header h1 {
  margin: 4px 0 0;
  font-family: var(--font-serif);
  font-size: clamp(28px, 3.4vw, 38px);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.subheading { margin-top: 6px; color: var(--muted); }
.page-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 16px;
}
.toolbar form { margin: 0; }
.spacer { flex: 1 1 auto; }

/* ---------------------------------------------------------------- cards + helpers */

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  min-width: 0;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
}
.grid-cards > .card { margin-bottom: 0; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.card-title {
  margin: 0 0 12px;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: 0.92em; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  margin-top: 4px;
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.stat-value.good, .stat.good .stat-value { color: var(--ok); }
.stat-value.warn, .stat.warn .stat-value { color: var(--warn); }
.stat-value.bad, .stat.bad .stat-value { color: var(--bad); }

/* ---------------------------------------------------------------- tables */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.table-wrap > table.data { margin: 0; }

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
table.data th {
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #fafbfc; }
table.data tfoot td {
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 0;
  font-weight: 600;
}
table.data td.num, table.data th.num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
table.data td.empty { padding: 32px 14px; }
table.data input[type="checkbox"] { width: 16px; height: 16px; margin: 0; vertical-align: middle; accent-color: var(--navy); }

/* Left edge marks the row state; inset shadow keeps column alignment untouched. */
tr.row-open > td:first-child { box-shadow: inset 3px 0 0 #fde68a; }
tr.row-ready > td:first-child { box-shadow: inset 3px 0 0 var(--ok-line); }
tr.row-closed > td { color: var(--muted); }
tr.row-closed > td:first-child { box-shadow: inset 3px 0 0 var(--border-strong); }

/* ---------------------------------------------------------------- pills + chips */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--grey-bg);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  line-height: 20px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.pill-muted { background: var(--grey-bg); color: var(--muted); }
.pill-info { background: var(--info-bg); color: var(--info); }

.flag {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 18px;
  vertical-align: middle;
}

/* ---------------------------------------------------------------- progress */

.progress {
  height: 6px;
  min-width: 80px;
  background: #eceef2;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  max-width: 100%;
  background: #475569;
  border-radius: inherit;
  transition: width 0.3s ease;
}
.progress-ok > .progress-bar, .progress-bar.progress-ok { background: var(--ok-line); }
.progress-warn > .progress-bar, .progress-bar.progress-warn { background: var(--warn-line); }
.progress-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: #f9fafb; border-color: #9ca3af; text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-hover); border-color: var(--navy-hover); }

.btn-danger { color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--grey-bg); border-color: transparent; }

.btn-small { height: 28px; padding: 0 10px; border-radius: 6px; font-size: 12.5px; }

/* ---------------------------------------------------------------- forms */

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="month"], input[type="search"], input[type="url"],
input:not([type]), select, textarea {
  height: 34px;
  max-width: 100%;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
select { padding-right: 28px; }
textarea { height: auto; min-height: 84px; padding: 8px 10px; line-height: 1.45; resize: vertical; }
input[type="file"] { max-width: 100%; font: inherit; font-size: 13px; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: 2px solid #c7d2fe; outline-offset: 0; }
input::placeholder, textarea::placeholder { color: #9ca3af; }

.form { display: flex; flex-direction: column; gap: 16px; }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .field-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea { width: 100%; }

.inline-form { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0; }

.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--navy); }

.help { margin: 0; color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- messages */

.flashes { margin-bottom: 20px; }
.flash {
  margin-bottom: 8px;
  padding: 10px 14px;
  border: 1px solid #c7d2fe;
  border-radius: var(--radius-sm);
  background: #eef2ff;
  color: #3730a3;
  overflow-wrap: anywhere;
}
.flash-ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.notice {
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  background: #eef2ff;
  color: #312e81;
  overflow-wrap: anywhere;
}
.notice > :last-child { margin-bottom: 0; }
.notice-warn { background: #fffbeb; border-color: #fde68a; color: #78350f; }

.empty {
  padding: 40px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}
table.data td.empty, .table-wrap .empty { border: 0; border-radius: 0; background: none; }

/* ---------------------------------------------------------------- tabs */

.tabs, .subtabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar, .subtabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--navy); font-weight: 600; }

/* Baseline as an inset shadow: a real border plus overflow-x would clip the active underline. */
.subtabs { margin-bottom: 16px; box-shadow: inset 0 -1px 0 var(--border); }
.subtabs .tab { padding: 8px 10px; font-size: 13px; }
.tab-count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--grey-bg);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.tab.active .tab-count { background: var(--navy); color: #fff; }

/* ---------------------------------------------------------------- expandable */

details.expand {
  margin-bottom: 16px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
details.expand > summary {
  margin: 0 -16px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.expand > summary::-webkit-details-marker { display: none; }
details.expand > summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
  flex: none;
}
details.expand[open] > summary::before { transform: rotate(45deg); }
details.expand[open] { padding-bottom: 16px; }
details.expand[open] > summary { margin-bottom: 12px; border-bottom: 1px solid var(--border-soft); }

/* ---------------------------------------------------------------- auth + error pages */

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 380px; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 16px; }
.auth-brand .eyebrow { color: var(--text); }
.auth-card { padding: 28px; }
.auth-card h1 { margin: 0 0 4px; font-family: var(--font-serif); font-size: 30px; font-weight: 500; }
.auth-card .btn-primary { width: 100%; height: 38px; }

.error-card { max-width: 560px; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 720px) {
  .topbar-inner { padding: 10px 16px; gap: 8px 12px; }
  .company-switch { order: 3; width: 100%; }
  .company-switch a { flex: 1 0 auto; text-align: center; }
  .user-email { max-width: 150px; }
  .topbar-tabs { padding: 0 16px; }
  .page { padding: 20px 16px 48px; }
  .page-header { align-items: flex-start; margin-bottom: 18px; }
  .card { padding: 16px; }
  .toolbar > * { max-width: 100%; }
  table.data th, table.data td { white-space: nowrap; }
  .stat-value { font-size: 22px; }
}
