/* ===== Checks & Balances — client escalation board (#174 + #178) =====
   Overdue is the loudest thing on this page on purpose: a red rail down the
   card, a red deadline block and an OVERDUE badge. The ticket is "make sure no
   one misses that deadline", so a late task must be impossible to skim past.
   Dark-mode overrides are appended at the bottom, matching the other page CSS
   files in pages/. */

.cb-page {
  width: 100%;
  padding: 0;
}

/* ── header ─────────────────────────────────────────────────────────────── */
.cb-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.cb-title {
  color: #1a1a1a;
  font-size: var(--font-size-subtitle);
  font-weight: 600;
}

.cb-desc {
  color: rgba(0, 0, 0, 0.55);
  font-size: 13px;
  margin-top: 6px;
  max-width: 620px;
  line-height: 1.5;
}

.cb-new-btn {
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s, transform 0.15s;
}

.cb-new-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.cb-new-btn:active { transform: translateY(0); }

/* ── summary chips ──────────────────────────────────────────────────────── */
.cb-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.cb-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 108px;
  padding: 10px 14px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.02);
}

.cb-chip-num {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
  color: #1a1a1a;
}

.cb-chip-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.48);
}

/* Only painted red when the count is non-zero — a zero overdue count is good
   news and must not read as an alarm. */
.cb-chip-overdue {
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.07);
}

.cb-chip-overdue .cb-chip-num { color: #dc2626; }
.cb-chip-overdue .cb-chip-label { color: rgba(185, 28, 28, 0.85); }

/* ── tabs ───────────────────────────────────────────────────────────────── */
.cb-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  margin-bottom: 14px;
}

.cb-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.cb-tab:hover { color: #1a1a1a; }

.cb-tab-active {
  color: #f5a623;
  border-bottom-color: #f5a623;
}

.cb-tab:focus-visible,
.cb-btn:focus-visible,
.cb-new-btn:focus-visible,
.cb-input:focus-visible,
.cb-search:focus-visible,
.cb-filter:focus-visible,
.cb-status-select:focus-visible,
.cb-modal-close:focus-visible {
  outline: 2px solid #f5a623;
  outline-offset: 2px;
}

/* ── toolbar ────────────────────────────────────────────────────────────── */
.cb-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.cb-search {
  flex: 1 1 260px;
  min-width: 0;
  padding: 9px 12px;
  font-size: 13px;
  color: #1a1a1a;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-md);
}

.cb-filter {
  padding: 9px 12px;
  font-size: 13px;
  color: #1a1a1a;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-md);
  cursor: pointer;
}

/* ── status line ────────────────────────────────────────────────────────── */
.cb-status {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.5);
  margin-bottom: 10px;
}

.cb-status-error { color: #c0392b; font-weight: 600; }

.cb-empty {
  padding: 40px 20px;
  text-align: center;
  font-size: 13px;
  color: rgba(0, 0, 0, 0.45);
  border: 1px dashed rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-md);
}

/* ── cards ──────────────────────────────────────────────────────────────── */
.cb-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cb-card {
  position: relative;
  padding: 14px 16px 14px 18px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-md);
  background: #fff;
  transition: box-shadow 0.15s, transform 0.15s;
}

.cb-card:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

/* The rail. 4px of colour down the left edge is what makes an overdue row
   findable while scrolling past thirty cards. */
.cb-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  background: transparent;
}

.cb-card-overdue {
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.035);
}

.cb-card-overdue::before { background: #dc2626; }

.cb-card-resolved { opacity: 0.72; }
.cb-card-resolved::before { background: #27ae60; }
.cb-card-resolved .cb-card-title { text-decoration: line-through; }

.cb-card-archived { opacity: 0.6; }

.cb-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.cb-client {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #f5a623;
}

.cb-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.cb-overdue-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.cb-priority {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.cb-priority-low {
  background: rgba(0, 0, 0, 0.05);
  color: rgba(0, 0, 0, 0.5);
  border-color: rgba(0, 0, 0, 0.1);
}

.cb-priority-high {
  background: rgba(245, 166, 35, 0.14);
  color: #b26a00;
  border-color: rgba(245, 166, 35, 0.42);
}

.cb-priority-critical {
  background: rgba(220, 38, 38, 0.12);
  color: #b91c1c;
  border-color: rgba(220, 38, 38, 0.4);
}

.cb-archived-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.5);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cb-card-title {
  font-size: 15px;
  font-weight: 600;
  color: #1a1a1a;
  line-height: 1.35;
  margin: 0 0 4px;
}

.cb-card-body {
  font-size: 13px;
  color: rgba(0, 0, 0, 0.6);
  line-height: 1.5;
  margin: 0 0 6px;
  white-space: pre-wrap;
}

/* The escalation note is already prefixed "Escalation:" in the markup, so it
   does not need a coloured tab down its side to announce itself — a quiet tint
   and a hairline are enough to set it apart from the task body. */
.cb-escalation {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.62);
  line-height: 1.5;
  margin: 0 0 8px;
  padding: 7px 10px;
  border: 1px solid rgba(245, 166, 35, 0.28);
  background: rgba(245, 166, 35, 0.07);
  border-radius: var(--radius-md);
  white-space: pre-wrap;
}

/* ── meta row ───────────────────────────────────────────────────────────── */
.cb-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.cb-who {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.cb-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.cb-who-name {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
}

.cb-from {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.45);
}

.cb-due {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  margin-left: auto;
  padding: 4px 10px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.07);
}

.cb-due-date {
  font-size: 12px;
  font-weight: 700;
  color: #1a1a1a;
}

.cb-due-note {
  font-size: 11px;
  color: rgba(0, 0, 0, 0.5);
}

.cb-due-overdue {
  background: rgba(220, 38, 38, 0.1);
  border-color: rgba(220, 38, 38, 0.35);
}

.cb-due-overdue .cb-due-date,
.cb-due-overdue .cb-due-note { color: #b91c1c; }

/* ── actions ────────────────────────────────────────────────────────────── */
.cb-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.cb-status-select {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #1a1a1a;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.cb-status-select:disabled { cursor: not-allowed; opacity: 0.6; }

.cb-status-open { border-color: rgba(0, 0, 0, 0.18); }
.cb-status-in_progress { border-color: rgba(37, 99, 235, 0.45); color: #1d4ed8; }
.cb-status-blocked { border-color: rgba(220, 38, 38, 0.45); color: #b91c1c; }
.cb-status-resolved { border-color: rgba(39, 174, 96, 0.5); color: #1e7e46; }

.cb-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: #fff;
  color: #1a1a1a;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.cb-btn:hover { background: rgba(0, 0, 0, 0.04); }
.cb-btn:disabled { cursor: not-allowed; opacity: 0.55; }

.cb-btn-primary {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
}

.cb-btn-primary:hover { filter: brightness(1.06); background: var(--accent-gradient); }

.cb-btn-danger {
  border-color: rgba(220, 38, 38, 0.3);
  color: #c0392b;
  background: rgba(220, 38, 38, 0.05);
}

.cb-btn-danger:hover { background: #e74c3c; color: #fff; border-color: #e74c3c; }

/* ── modal ──────────────────────────────────────────────────────────────── */
.cb-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.cb-modal {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}

.cb-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.cb-modal-title {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0;
}

.cb-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  padding: 0 4px;
}

.cb-modal-close:hover { color: #1a1a1a; }

.cb-form {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cb-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cb-field-label {
  font-size: 12px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.7);
}

.cb-field-hint {
  font-size: 11px;
  color: rgba(0, 0, 0, 0.45);
  line-height: 1.4;
}

.cb-input {
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  color: #1a1a1a;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: var(--radius-md);
}

.cb-textarea { resize: vertical; line-height: 1.5; }

.cb-form-error {
  padding: 9px 12px;
  border-radius: var(--radius-md);
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: #b91c1c;
  font-size: 12px;
  font-weight: 600;
}

.cb-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ── narrow screens ─────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .cb-header { flex-direction: column; align-items: stretch; }
  .cb-new-btn { width: 100%; }
  .cb-chip { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .cb-due { margin-left: 0; }
  .cb-meta { gap: 10px; }
  .cb-actions > * { flex: 1 1 auto; }
}

/* Anyone who has asked the OS for less motion gets none of the lift/hover
   transforms. */
@media (prefers-reduced-motion: reduce) {
  .cb-card,
  .cb-card:hover,
  .cb-new-btn,
  .cb-new-btn:hover,
  .cb-btn {
    transition: none;
    transform: none;
  }
}

/* ===== Dark mode ===== */
html[data-theme="dark"] .cb-title,
html[data-theme="dark"] .cb-card-title,
html[data-theme="dark"] .cb-who-name,
html[data-theme="dark"] .cb-chip-num,
html[data-theme="dark"] .cb-modal-title,
html[data-theme="dark"] .cb-due-date { color: #e2e8f0; }

html[data-theme="dark"] .cb-desc,
html[data-theme="dark"] .cb-status,
html[data-theme="dark"] .cb-empty,
html[data-theme="dark"] .cb-from,
html[data-theme="dark"] .cb-card-body,
html[data-theme="dark"] .cb-escalation,
html[data-theme="dark"] .cb-due-note,
html[data-theme="dark"] .cb-field-hint { color: #94a3b8; }

html[data-theme="dark"] .cb-chip-label,
html[data-theme="dark"] .cb-field-label { color: #cbd5e1; }

html[data-theme="dark"] .cb-status-error { color: #fca5a5; }

/* Surfaces flip polarity — a black film is invisible on slate. */
html[data-theme="dark"] .cb-chip {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] .cb-card {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] .cb-card:hover { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }

html[data-theme="dark"] .cb-empty { border-color: rgba(255, 255, 255, 0.14); }

html[data-theme="dark"] .cb-tabs { border-bottom-color: rgba(255, 255, 255, 0.1); }
html[data-theme="dark"] .cb-tab { color: #94a3b8; }
html[data-theme="dark"] .cb-tab:hover { color: #e2e8f0; }
html[data-theme="dark"] .cb-tab-active { color: #f5a623; }

html[data-theme="dark"] .cb-actions { border-top-color: rgba(255, 255, 255, 0.08); }

/* Inputs need an explicit dark background: left transparent they inherit the
   browser's white default and the typed text goes white-on-white. */
html[data-theme="dark"] .cb-search,
html[data-theme="dark"] .cb-filter,
html[data-theme="dark"] .cb-input,
html[data-theme="dark"] .cb-status-select {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
  color: #e2e8f0;
}

html[data-theme="dark"] .cb-search::placeholder,
html[data-theme="dark"] .cb-input::placeholder { color: #64748b; }

/* The native date/select glyphs are drawn by the browser in the OS colour, so
   the control scheme has to be declared or they render black on slate. */
html[data-theme="dark"] .cb-input[type="date"],
html[data-theme="dark"] .cb-filter,
html[data-theme="dark"] .cb-status-select { color-scheme: dark; }

html[data-theme="dark"] .cb-btn {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
  color: #e2e8f0;
}

html[data-theme="dark"] .cb-btn:hover { background: rgba(255, 255, 255, 0.12); }

html[data-theme="dark"] .cb-btn-primary { color: #fff; border-color: transparent; }

html[data-theme="dark"] .cb-btn-danger {
  border-color: rgba(248, 113, 113, 0.32);
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
}

html[data-theme="dark"] .cb-btn-danger:hover { background: #e74c3c; color: #fff; }

/* Overdue stays the loudest thing on the page in dark mode too — the red is
   lifted so it still reads as an alarm against slate rather than going muddy. */
html[data-theme="dark"] .cb-card-overdue {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(248, 113, 113, 0.4);
}

html[data-theme="dark"] .cb-card-overdue::before { background: #ef4444; }

html[data-theme="dark"] .cb-chip-overdue {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(248, 113, 113, 0.4);
}

html[data-theme="dark"] .cb-chip-overdue .cb-chip-num { color: #fca5a5; }
html[data-theme="dark"] .cb-chip-overdue .cb-chip-label { color: #fca5a5; }

html[data-theme="dark"] .cb-overdue-badge { background: #ef4444; color: #fff; }

html[data-theme="dark"] .cb-due {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
}

html[data-theme="dark"] .cb-due-overdue {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(248, 113, 113, 0.4);
}

html[data-theme="dark"] .cb-due-overdue .cb-due-date,
html[data-theme="dark"] .cb-due-overdue .cb-due-note { color: #fca5a5; }

html[data-theme="dark"] .cb-escalation {
  background: rgba(245, 166, 35, 0.1);
  border-left-color: rgba(245, 166, 35, 0.5);
}

html[data-theme="dark"] .cb-priority-low {
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
  border-color: rgba(255, 255, 255, 0.14);
}

html[data-theme="dark"] .cb-priority-high {
  background: rgba(245, 166, 35, 0.16);
  color: #f5a623;
  border-color: rgba(245, 166, 35, 0.38);
}

html[data-theme="dark"] .cb-priority-critical {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.4);
}

html[data-theme="dark"] .cb-archived-badge {
  background: rgba(255, 255, 255, 0.08);
  color: #94a3b8;
}

html[data-theme="dark"] .cb-status-in_progress { color: #93c5fd; border-color: rgba(96, 165, 250, 0.5); }
html[data-theme="dark"] .cb-status-blocked { color: #fca5a5; border-color: rgba(248, 113, 113, 0.5); }
html[data-theme="dark"] .cb-status-resolved { color: #86efac; border-color: rgba(74, 222, 128, 0.5); }

html[data-theme="dark"] .cb-modal {
  background: #1e293b;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

html[data-theme="dark"] .cb-modal-head { border-bottom-color: rgba(255, 255, 255, 0.1); }
html[data-theme="dark"] .cb-modal-close { color: #94a3b8; }
html[data-theme="dark"] .cb-modal-close:hover { color: #e2e8f0; }

html[data-theme="dark"] .cb-form-error {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}
