/* 3PL Order Sync admin - standalone light theme */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f8f9fb;
  --surface-hover: #eef0f4;
  --sidebar: #111827;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1f2937;
  --text: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-tint: #e6f4f2;
  --on-primary: #ffffff;
  --success: #15803d;
  --success-bg: #e8f6ed;
  --warning: #92400e;
  --warning-bg: #fdf3e1;
  --warning-border: #f3d7a5;
  --error: #b91c1c;
  --error-bg: #fdecec;
  --error-border: #f5c2c2;
  --info: #1e40af;
  --info-bg: #eaf1fd;
  --info-border: #c3d5f7;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.05);
  --focus: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

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

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 13px; }
code { background: var(--surface-hover); padding: 1px 5px; border-radius: 4px; }
h1, h2, h3 { margin: 0; }

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

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Layout ---------- */

.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; color: #fff; font-weight: 600; font-size: 15px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius);
  background: var(--primary); color: #fff; font-size: 15px; flex: none;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius);
  color: var(--sidebar-text); font-weight: 500; transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-nav a i { width: 18px; text-align: center; opacity: 0.8; }
.sidebar-nav a:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #2dd4bf; }

.sidebar-footer { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid #1f2937; display: flex; flex-direction: column; gap: 8px; }
.sidebar-user { font-size: 13px; color: #94a3b8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer .btn-ghost { color: var(--sidebar-text); justify-content: flex-start; padding-left: 0; }
.sidebar-footer .btn-ghost:hover { color: #fff; background: transparent; }

.content { padding: 28px 32px 60px; max-width: 1280px; width: 100%; min-width: 0; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-title { font-size: 26px; font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; }
.page-subtitle { margin: 6px 0 0; color: var(--text-secondary); max-width: 720px; }
.breadcrumb { margin: 0 0 4px; font-size: 13px; color: var(--text-muted); }

/* ---------- Cards ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-title i { color: var(--text-muted); }
.card-body { padding: 18px 20px; }
.card-body-divided { border-top: 1px solid var(--border); }
.subhead { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.muted { color: var(--text-secondary); margin-top: 0; }
.small { font-size: 13px; }
.strong { font-weight: 600; }

.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.two-col .card { margin-bottom: 0; }
.two-col + .card { margin-top: 20px; }

/* ---------- Stats ---------- */

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
a.stat:hover { border-color: var(--border-strong); text-decoration: none; }
.stat.is-selected { border-color: var(--primary); box-shadow: var(--focus); }
.stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.stat-value { font-size: 26px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-meta { font-size: 14px; font-weight: 500; color: var(--text-secondary); padding-top: 6px; }
.stat-warning .stat-value { color: var(--warning); }
.stat-error .stat-value { color: var(--error); }

/* ---------- Checklist ---------- */

.checklist { list-style: none; margin: 0; padding: 8px 20px 12px; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 8px 0; color: var(--text); flex-wrap: wrap; }
.checklist li i { color: var(--border-strong); }
.checklist li.is-done { color: var(--text-muted); }
.checklist li.is-done i { color: var(--success); }
.inline-form { display: inline; margin-left: 4px; }
.input-sm { width: auto; min-width: 180px; padding: 6px 10px; font-size: 13px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); background: var(--surface-muted); padding: 10px 16px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-muted); }
.table-compact td, .table-compact th { padding: 8px 14px; font-size: 13px; }
.cell-meta { font-size: 12px; color: var(--text-muted); font-family: var(--font); }
.cell-detail { color: var(--text-secondary); min-width: 220px; max-width: 420px; overflow-wrap: anywhere; font-size: 13px; }
.nowrap { white-space: nowrap; }
.sku-description { color: var(--text-secondary); font-size: 13px; min-width: 160px; }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions form { display: inline; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.badge-error { background: var(--error); color: #fff; }
.badge-error-soft { background: var(--error-bg); color: var(--error); }
.badge-muted { background: var(--surface-hover); color: var(--text-secondary); }

/* ---------- Segmented filter ---------- */

.segmented { display: inline-flex; background: var(--surface-hover); padding: 3px; border-radius: var(--radius); gap: 2px; flex-wrap: wrap; }
.segmented a { padding: 5px 12px; border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px; font-weight: 500; }
.segmented a:hover { color: var(--text); text-decoration: none; }
.segmented a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px;
  padding: 8px 16px; border-radius: var(--radius); border: 1px solid transparent; font: inherit;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.1s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--error); border-color: var(--error-border); }
.btn-danger:hover { background: var(--error); color: #fff; border-color: var(--error); }
.btn-danger-ghost { background: transparent; color: var(--text-muted); }
.btn-danger-ghost:hover { background: var(--error-bg); color: var(--error); }
.btn-push { margin-left: auto; }

/* ---------- Forms ---------- */

.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .field-row-label label { font-weight: 500; font-size: 14px; }
.required { color: var(--error); }

.input {
  width: 100%; min-height: 38px; padding: 8px 12px; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius); transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input::placeholder { color: #9ca3af; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
select.input {
  appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer;
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 12px;
}
select.input:hover { border-color: var(--text-muted); }
select.input:disabled { cursor: not-allowed; opacity: 0.6; }
select.input::-ms-expand { display: none; }
.input.mono { font-family: var(--mono); font-size: 13px; }

.field-row { display: grid; grid-template-columns: minmax(200px, 320px) 1fr; gap: 8px 32px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.field-row:last-child { border-bottom: 0; }
.field-row-control { max-width: 460px; display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.field-description { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }

.form-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 12px; align-items: end; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }

.checkbox { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
input[type="checkbox"] { accent-color: var(--primary); }

.toggle { position: relative; display: inline-block; width: 44px; height: 26px; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.toggle-track { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background 0.2s ease; }
.toggle-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.2s ease;
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle-track { box-shadow: var(--focus); }

.sticky-actions {
  position: sticky; bottom: 0; display: flex; gap: 8px; align-items: center; padding: 14px 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* ---------- Notices ---------- */

.notice {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid; margin-bottom: 16px; font-size: 14px;
}
.notice i { margin-top: 3px; }
.notice-success { background: var(--success-bg); border-color: #bfe3cb; color: var(--success); }
.notice-error { background: var(--error-bg); border-color: var(--error-border); color: var(--error); }
.notice-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.notice-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }
.notice a { color: inherit; text-decoration: underline; }

/* ---------- Empty state / log ---------- */

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-state i { font-size: 36px; color: var(--border-strong); margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty-state p { max-width: 460px; margin: 0 auto 16px; }

.log {
  margin: 0; padding: 16px 20px; background: #0f172a; color: #e2e8f0; font: 12.5px/1.6 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 70vh; overflow: auto;
}

/* ---------- Login ---------- */

.login-body { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px; box-shadow: 0 8px 24px rgba(17, 24, 39, 0.06);
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .brand-mark { width: 44px; height: 44px; font-size: 20px; margin-bottom: 12px; }
.login-brand h1 { font-size: 20px; font-weight: 650; }
.login-brand p { margin: 4px 0 0; color: var(--text-secondary); }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; }
  .sidebar-brand { padding: 0 8px 0 0; }
  .sidebar-nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; }
  .sidebar-nav a { padding: 8px 10px; white-space: nowrap; }
  .sidebar-nav a.active { box-shadow: inset 0 -2px 0 #2dd4bf; }
  .sidebar-footer { margin: 0 0 0 auto; border: 0; padding: 0; flex-direction: row; align-items: center; }
  .sidebar-user { display: none; }
  .content { padding: 20px 16px 48px; }
  .two-col { grid-template-columns: 1fr; }
  .two-col .card { margin-bottom: 20px; }
  .field-row { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .page-header { flex-direction: column; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar-nav a span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .sidebar-nav a i { width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Logs ---------- */

.badge-info { background: var(--info-bg); color: var(--info); }
.badge-lg { font-size: 13px; padding: 6px 12px; }
.page-title .badge { vertical-align: middle; font-size: 13px; margin-left: 6px; }
.text-error { color: var(--error); }
.no-margin { margin: 0; }
.card-footnote { margin: 0; padding: 10px 20px; border-top: 1px solid var(--border); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; color: var(--text-secondary);
  font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.filter-bar .input { width: auto; min-width: 160px; }
.filter-bar input[type="search"] { min-width: 260px; flex: 1; max-width: 420px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; border-top: 1px solid var(--border); }

/* Timeline: a rail connects the steps; each step's colour says how it went. */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item {
  --tone: #64748b; --tone-bg: #f1f5f9;
  position: relative; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; padding: 8px 0 14px;
}
.timeline-item::before {
  content: ""; position: absolute; left: 13px; top: 36px; bottom: -2px; width: 2px; background: var(--border);
}
.timeline-item:last-child::before { display: none; }
.timeline-icon {
  display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--tone-bg); color: var(--tone); font-size: 13px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--tone) 25%, transparent);
}
.timeline-body { padding-top: 3px; min-width: 0; }
.timeline-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; }
.timeline-title { font-weight: 600; overflow-wrap: anywhere; }
.timeline-time { font-size: 12px; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.timeline-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.timeline-po { font-weight: 600; }
.timeline-po i { font-size: 11px; opacity: 0.7; }
.timeline-now { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.timeline-what { margin: 4px 0 0; color: var(--text-secondary); overflow-wrap: anywhere; }
.timeline-next {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-top: 10px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
}
.timeline-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 10px; }
.timeline-foot details.data { margin-top: 0; flex-basis: 100%; order: 2; }
.timeline-retry { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--tone); }

.timeline-item.tone-success { --tone: var(--success); --tone-bg: var(--success-bg); }
.timeline-item.tone-info { --tone: var(--info); --tone-bg: var(--info-bg); }
.timeline-item.tone-muted { --tone: #64748b; --tone-bg: #f1f5f9; }
.timeline-item.tone-warning { --tone: #b45309; --tone-bg: var(--warning-bg); }
.timeline-item.tone-error { --tone: var(--error); --tone-bg: var(--error-bg); }
.timeline-item.tone-success .timeline-title { color: var(--success); }
.timeline-item.tone-muted .timeline-title { color: var(--text-secondary); font-weight: 500; }
.timeline-item.tone-muted .timeline-what, .timeline-item.tone-info .timeline-what { font-size: 13px; }

/* Problems stand out as a tinted card on the rail. */
.timeline-item.is-problem .timeline-body {
  padding: 10px 14px 12px; border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--tone-bg) 55%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--tone) 22%, var(--border));
}
.timeline-item.is-problem .timeline-title { color: var(--tone); }
.timeline-item.is-problem .timeline-what { color: var(--text); }
.timeline-item.is-problem.is-resolved .timeline-body { background: var(--surface); border-color: var(--border); }
.timeline-item.is-resolved .timeline-icon { opacity: 0.7; }
.timeline-resolved { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--success); }
.timeline-item.is-problem + .timeline-item, .timeline-day + .timeline-item.is-problem { margin-top: 2px; }

.timeline-day {
  display: flex; align-items: center; gap: 10px; padding: 14px 0 8px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted);
}
.timeline-day::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.timeline-day:first-child { padding-top: 0; }

/* Who can fix it */
.fixer {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  font-size: 12px; font-weight: 600; background: var(--surface-hover); color: var(--text-secondary);
}
.fixer i { font-size: 11px; }
.fixer-syncore { background: var(--info-bg); color: var(--info); }
.fixer-tpl { background: var(--primary-tint); color: var(--primary); }
.fixer-warehouse { background: var(--warning-bg); color: var(--warning); }
.fixer-auto { background: var(--success-bg); color: var(--success); }
.fixer-support { background: var(--error-bg); color: var(--error); }

/* Problem summary on the PO events tab */
.problem-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.problem-card {
  display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
a.problem-card:hover { text-decoration: none; border-color: var(--border-strong); }
.problem-card.is-selected { border-color: var(--primary); box-shadow: var(--focus); }
.problem-card-label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.problem-card-label i { color: var(--text-muted); width: 14px; text-align: center; }
.problem-card-count { font-size: 13px; color: var(--text-secondary); }
.problem-card.has-open { border-color: var(--error-border); background: color-mix(in srgb, var(--error-bg) 45%, var(--surface)); }
.problem-card.has-open .problem-card-count strong { color: var(--error); }
.problem-cards-head { grid-column: 1 / -1; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; align-items: baseline; }
.problem-cards-head h2 { font-size: 15px; }
.events-help { margin: 16px 20px 0; }

details.data { margin-top: 6px; }
details.data summary, details.email summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; }
details.data pre, details.email pre {
  margin: 8px 0 0; padding: 12px; background: var(--surface-muted); border: 1px solid var(--border);
  border-radius: var(--radius); font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 420px; overflow: auto;
}

.email-list { display: flex; flex-direction: column; gap: 8px; }
details.email { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
details.email summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--text); }
.email-subject { font-weight: 600; }
.email-meta { color: var(--text-muted); font-size: 12px; }
details.email .notice { margin: 8px 0 0; }

.log-lines { background: #0f172a; color: #e2e8f0; font: 12px/1.6 var(--mono); padding: 12px 0; max-height: 70vh; overflow: auto; }
.log-line { display: grid; grid-template-columns: 96px 64px minmax(0, 1fr); gap: 10px; padding: 1px 20px; }
.log-line:hover { background: #1e293b; }
.log-time { color: #64748b; white-space: nowrap; }
.log-level { color: #94a3b8; }
.log-msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-warning .log-level, .log-warning .log-msg { color: #fbbf24; }
.log-error .log-level, .log-error .log-msg, .log-critical .log-msg { color: #f87171; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0; margin: 0; }
.facts > div { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.facts dt { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.facts dd { margin: 4px 0 0; font-weight: 500; }

@media (max-width: 600px) {
  .log-line { grid-template-columns: 1fr; gap: 0; padding: 4px 16px; }
  .filter-bar .input, .filter-bar input[type="search"] { width: 100%; max-width: none; }
}

/* ---------- Ship Via ---------- */

.form-row-2 { grid-template-columns: minmax(0, 1fr) auto; max-width: 640px; }
.match-result { margin: 14px 0 0; }
.carrier-list { display: flex; flex-direction: column; gap: 8px; }
.carrier-list details { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.carrier-list summary { cursor: pointer; }
.carrier-list .table { margin-top: 10px; }
.carrier-list p { margin: 8px 0 0; }

/* ---------- Clients ---------- */

.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.header-actions form { margin: 0; }
.sync-note { margin: -8px 0 16px; }
.stat-success .stat-value { color: var(--success); }
.missing { color: var(--warning); max-width: 240px; }
.check-ok { color: var(--success); font-weight: 500; white-space: nowrap; }
.check-partial { color: var(--warning); font-weight: 500; white-space: nowrap; }
.check-missing { color: var(--text-muted); }
.setup-steps { display: flex; flex-wrap: wrap; gap: 4px 24px; padding: 12px 20px; }
.setup-steps li { padding: 4px 0; }
.card-details > summary { list-style: none; cursor: pointer; border-bottom: 0; }
.card-details > summary::-webkit-details-marker { display: none; }
.card-details[open] > summary { border-bottom: 1px solid var(--border); }
textarea.input { resize: vertical; min-height: 120px; font-family: inherit; }
.client-cell { min-width: 200px; }
.setup-pills { display: flex; flex-wrap: wrap; gap: 4px; max-width: 420px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid; }
.pill i { font-size: 10px; }
.pill-done { color: var(--success); background: var(--success-bg); border-color: #bfe3cb; }
.pill-missing { color: var(--text-muted); background: var(--surface); border-color: var(--border-strong); border-style: dashed; }
.page-header .header-actions { flex-shrink: 0; }
.suggestion-list { list-style: none; margin: 0; padding: 0; }
.suggestion-list li { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.suggestion-list li:last-child { border-bottom: 0; }
.suggestion-list form { margin: 0; flex-shrink: 0; }

/* ---------- Polish (Oct 2026) ---------- */

/* Dashboard status line under the title */
.status-strip { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 8px 0 0; padding: 0; font-size: 13px; color: var(--text-secondary); }
.status-strip li { display: inline-flex; align-items: center; gap: 6px; }
.status-strip i { color: var(--text-muted); font-size: 12px; }

/* Count tiles: one row of four */
.stats-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-label { display: inline-flex; align-items: center; gap: 6px; }
.stat-label i { font-size: 11px; opacity: 0.8; }
.stat-success .stat-value { color: var(--success); }
.stat-info .stat-value { color: var(--info); }

/* Card header tools: search + filters */
.card-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.search-form { position: relative; display: inline-flex; align-items: center; margin: 0; }
.search-form > i { position: absolute; left: 10px; color: var(--text-muted); font-size: 12px; pointer-events: none; }
.search-form .input-sm { padding-left: 30px; min-width: 260px; }
.client-col { min-width: 140px; }
.card-note { margin: 0; padding: 10px 20px; font-size: 13px; color: var(--text-secondary); background: var(--surface-muted); border-bottom: 1px solid var(--border); }
.empty-filter { margin: 0; padding: 24px 20px; text-align: center; color: var(--text-muted); }

/* Badges with icons */
.badge i { font-size: 10px; }
.page-title .badge i { font-size: 11px; }

/* Collapsible help */
.help-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 16px; margin-bottom: 20px; font-size: 14px; }
.help-box summary { cursor: pointer; font-weight: 500; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; list-style: none; }
.help-box summary::-webkit-details-marker { display: none; }
.help-box summary::after { content: "\f078"; font: var(--fa-font-solid); font-size: 11px; margin-left: auto; color: var(--text-muted); transition: transform 0.2s ease; }
.help-box[open] summary::after { transform: rotate(180deg); }
.help-box summary i { color: var(--primary); }
.help-box p, .help-box ul { margin: 10px 0 0; color: var(--text-secondary); }
.help-box ul { padding-left: 20px; }
.help-box li + li { margin-top: 4px; }

/* Settings: jump to a section */
.jump-nav { position: sticky; top: 0; z-index: 2; display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 0; margin: -6px 0 10px; background: var(--bg); }
.jump-nav a { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text-secondary); font-size: 13px; font-weight: 500; }
.jump-nav a:hover { color: var(--text); border-color: var(--border-strong); text-decoration: none; }
.jump-nav a i { font-size: 12px; color: var(--text-muted); }
.card[id] { scroll-margin-top: 64px; }

/* Flash messages can be closed */
.notice-flash { align-items: center; }
.notice-flash > span { flex: 1; }
.notice-close { margin-left: auto; border: 0; background: transparent; color: inherit; opacity: 0.6; cursor: pointer; padding: 2px 4px; border-radius: 4px; font-size: 14px; line-height: 1; }
.notice-close:hover { opacity: 1; background: color-mix(in srgb, currentColor 10%, transparent); }
.notice-close i { margin: 0; }

/* Whole row opens the run */
tr.row-link[data-href] { cursor: pointer; }

@media (max-width: 900px) {
  .stats-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-tools { width: 100%; }
  .search-form, .search-form .input-sm { width: 100%; min-width: 0; }
}

/* Phones: tables become stacked cards, one row per card */
@media (max-width: 640px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack td { padding: 3px 0; border: 0; min-width: 0; max-width: none; white-space: normal; }
  .table-stack td[data-label] { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; align-items: baseline; }
  .table-stack td[data-label]::before {
    content: attr(data-label); font: 600 11px/1.4 var(--font); text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--text-muted);
  }
  .table-stack td[data-label] > * { justify-self: start; max-width: 100%; }
  .table-stack td:first-child { display: block; font-size: 15px; padding-bottom: 6px; }
  .table-stack td:first-child::before { display: none; }
  .table-stack td.row-actions .sr-only { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
  .table-stack td:empty, .table-stack td.cell-detail:empty { display: none; }
  .table-stack td.row-actions { text-align: left; padding-top: 8px; }
  .table-stack tbody tr:hover td { background: transparent; }
  .table-stack .setup-pills { max-width: none; }
  .status-strip { gap: 4px 12px; }
  .jump-nav { overflow-x: auto; flex-wrap: nowrap; }
  .jump-nav a { white-space: nowrap; }
}

.notice-action { align-items: center; }
.notice-action > span { flex: 1; }
.notice-action form { margin: 0; flex-shrink: 0; }
.card-attention { border-color: var(--warning-border); }
.card-attention .card-header { background: var(--warning-bg); }
.card-attention .card-title i { color: var(--warning); }
.sku-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.sku-actions form { margin: 0; }
.narrow { max-width: 560px; }
.plain-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.plain-fieldset[disabled] .input { background: var(--surface-muted); color: var(--text-secondary); }

/* PO notes */
.note-list { list-style: none; margin: 0; padding: 0; }
.note-list li { padding: 12px 20px; border-bottom: 1px solid var(--border); }
.note-list li:last-child { border-bottom: 0; }
.note-head { display: flex; align-items: center; gap: 8px; }
.note-head form { margin: 0 0 0 auto; }
.note-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-form { display: flex; gap: 10px; align-items: flex-start; }
.note-form textarea { min-height: 42px; flex: 1; }
@media (max-width: 640px) { .note-form { flex-direction: column; align-items: stretch; } }

/* Bulk actions */
.bulk-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 20px; background: var(--primary-tint); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1; }
.bulk-bar[hidden] { display: none; }
.bulk-count { font-weight: 600; font-size: 13px; margin-right: 4px; }
.check-col { width: 36px; padding-right: 0 !important; }
.check-col input { width: 16px; height: 16px; }
@media (max-width: 640px) { .table-stack td.check-col { display: block; padding-bottom: 0; } }

/* Trends card: three figures and a column chart (orders sent per day) */
.trend-card { --series: #0d9488; }
.trend-body { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 8px 24px; padding: 16px 20px 8px; align-items: center; }
.trend-figures { margin: 0; display: flex; flex-direction: column; gap: 14px; }
.trend-figures dt { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.trend-figures dd { margin: 2px 0 0; font-size: 24px; font-weight: 650; line-height: 1.2; }
.trend-figures .cell-meta { margin: 2px 0 0; }
.trend-chart { position: relative; margin: 0; min-width: 0; }
.trend-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.trend-chart .bar { fill: var(--series); }
.trend-chart .bar-hit { fill: transparent; cursor: default; outline: none; }
.trend-chart .bar-hit.is-active, .trend-chart .bar-hit:focus-visible { fill: color-mix(in srgb, var(--series) 10%, transparent); }
.trend-chart .axis-grid { stroke: #eef0f4; stroke-width: 1; }
.trend-chart .axis-base { stroke: var(--border-strong); stroke-width: 1; }
.trend-chart .axis-text { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.chart-tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: #111827; color: #fff;
  font-size: 12px; padding: 5px 9px; border-radius: 6px; white-space: nowrap; pointer-events: none; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.chart-tip strong { font-weight: 700; }
.chart-tip span { color: #cbd5e1; }
.trend-table { padding: 0 20px 12px; }
.trend-table summary { cursor: pointer; font-size: 13px; color: var(--text-secondary); }
.trend-table .table-wrap { max-height: 260px; overflow: auto; margin-top: 8px; border: 1px solid var(--border); border-radius: var(--radius); }
@media (max-width: 900px) {
  .trend-body { grid-template-columns: 1fr; }
  .trend-figures { flex-direction: row; flex-wrap: wrap; gap: 12px 28px; }
}
.change-list { list-style: none; margin: 0; padding: 6px 20px 12px; }
.change-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.change-list li:last-child { border-bottom: 0; }
.facts .fact-wide { grid-column: span 2; }
@media (max-width: 640px) { .facts .fact-wide { grid-column: auto; } }

/* Invites */
.login-foot { margin: 16px 0 0; text-align: center; font-size: 13px; }
.email-edit { display: flex; gap: 2px; align-items: center; margin-top: 4px; max-width: 280px; }
.email-edit .input-sm { min-width: 200px; flex: 1; padding: 4px 8px; }
.manual-password { margin-top: 10px; font-size: 13px; }
.manual-password summary { cursor: pointer; color: var(--text-secondary); }
.manual-password .field { margin-top: 10px; max-width: 320px; }
.users-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.users-layout > .card { margin-bottom: 0; }
.users-layout > .card:last-child { max-width: 560px; }
.users-layout + .card { margin-top: 20px; }

/* Users */
.user-list { list-style: none; margin: 0; padding: 0; }
.user-row { display: grid; grid-template-columns: 40px minmax(180px, 1.4fr) 130px minmax(200px, 1fr) 240px; gap: 14px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-tint); color: var(--primary); font-weight: 700; }
.user-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.user-email { font-size: 13px; color: var(--text-secondary); overflow-wrap: anywhere; }
.user-status { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; }
.user-actions form { margin: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex: none; }
.dot-ok { background: var(--success); }
.dot-wait { background: #d97706; }
.dot-bad { background: var(--error); }
.form-narrow { max-width: 760px; }
.action-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.action-row form { margin: 0; flex-shrink: 0; }
.inline-field { display: flex; gap: 10px; align-items: flex-start; }
.inline-field .field { flex: 1; }
.inline-field > .btn { margin-top: 26px; }
.sidebar-user:hover { color: #fff; text-decoration: none; }
@media (max-width: 760px) {
  .user-row { grid-template-columns: 40px minmax(0, 1fr); }
  .user-access, .user-status, .user-actions { grid-column: 2; justify-content: flex-start; }
  .action-row, .inline-field { flex-direction: column; align-items: stretch; }
  .inline-field > .btn { margin-top: 0; }
}

.tracking-line { white-space: nowrap; }
.tracking-line i { margin-right: 4px; }
.setup-missing { color: var(--warning); font-size: 13px; }
.setup-ok { color: var(--success); font-size: 13px; }
.setup-missing i, .setup-ok i { margin-right: 4px; }
