/* ── Modal ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-dialog {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-dialog.modal-lg { max-width: 720px; }
.modal-dialog.modal-sm { max-width: 380px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: var(--font-lg); }
.modal-close {
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 var(--space-2);
  color: var(--color-text-muted);
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}
.modal-body p { margin-bottom: var(--space-3); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ── Data table ──────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sm);
}
.data-table th {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  font-weight: 600;
  font-size: var(--font-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}
.data-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tbody tr:hover td { background: var(--color-bg); }
.data-table .actions { text-align: right; white-space: nowrap; }
.data-table .actions button { margin-left: var(--space-1); }

/* ── Filters bar ─────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  align-items: center;
  flex-wrap: wrap;
}
.filters input[type=text],
.filters input[type=search],
.filters select {
  width: auto;
  min-width: 180px;
}
.filters label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-sm);
  font-weight: normal;
  margin: 0;
}

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--space-5);
}
.tab {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}
.tab:hover { color: var(--color-text); }
.tab.active {
  border-bottom-color: var(--color-primary);
  color: var(--color-primary);
}

/* ── Collapsible (<details>) ─────────────────────────────────── */
details.collapsible {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: var(--space-2);
  overflow: hidden;
}
details.collapsible > summary {
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  font-weight: 600;
  font-size: var(--font-sm);
  background: var(--color-bg);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
details.collapsible > summary::before {
  content: '▶';
  font-size: 0.65rem;
  color: var(--color-text-muted);
  transition: transform var(--transition-fast);
}
details.collapsible[open] > summary::before { transform: rotate(90deg); }
details.collapsible > summary::-webkit-details-marker { display: none; }

.collapsible-body {
  padding: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* ── Inline edit ─────────────────────────────────────────────── */
.inline-edit {
  display: inline-block;
  width: 100%;
  padding: var(--space-1) var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: var(--font-sm);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.inline-edit:hover { border-color: var(--color-border-strong); background: var(--color-surface); }
.inline-edit:focus { border-color: var(--color-primary); background: var(--color-surface); outline: none; box-shadow: 0 0 0 2px var(--color-primary-light); }
.inline-edit.saving { opacity: 0.5; }
.inline-edit.saved { background: var(--color-success-light); border-color: var(--color-success); }

/* ── Family group (products) ─────────────────────────────────── */
.family-label {
  font-size: var(--font-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* ── Empty state ─────────────────────────────────────────────── */
/* C.8.A — duplicate declaration removed; styling lives in the later
   "EMPTY STATE" block. Kept this comment as a signpost. */

/* ==============================================================
   UI PASS 2/5 — Components core (buttons, badges, cards, inputs, modals)
   These rules override any earlier declarations via cascade order.
   ============================================================== */

/* === BUTTONS ============================================== */

button,
.btn,
.btn-primary,
.btn-accent,
.btn-secondary,
.btn-ghost,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  font-weight: 600;
  letter-spacing: -0.005em;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--transition-button),
              border-color var(--transition-button),
              color var(--transition-button),
              transform 0.05s ease-out;
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
  line-height: 1.2;
}

button:active,
.btn:active,
.btn-primary:active,
.btn-accent:active,
.btn-secondary:active,
.btn-ghost:active,
.btn-danger:active {
  transform: scale(0.98);
}

button:disabled,
.btn:disabled,
.btn-primary:disabled,
.btn-accent:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary,
button.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
}
.btn-primary:hover,
button.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: #ffffff;
}

.btn-accent {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
}
.btn-accent:hover {
  background: #e64d2e;
  border-color: #e64d2e;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-line);
}
.btn-secondary:hover {
  background: var(--color-surface-alt);
  border-color: var(--color-line-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-soft);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.btn-danger {
  background: var(--color-rose);
  color: #ffffff;
  border-color: var(--color-rose);
}
.btn-danger:hover {
  background: #be123c;
  border-color: #be123c;
}

.btn-sm {
  padding: 5px 12px;
  font-size: var(--font-size-sm);
}
.btn-lg {
  padding: 11px 22px;
  font-size: var(--font-size-md);
}

/* === BADGES (Status pills) ============================================== */

.badge,
[class*="badge-"],
[class*="status-"] {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: var(--radius-pill);
  line-height: 1.5;
  white-space: nowrap;
}

.badge::before,
[class*="badge-"]::before,
[class*="status-"]::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  opacity: 0.9;
}

.badge {
  background: var(--color-slate-soft);
  color: var(--color-slate);
}

.badge-info,
.status-active,
.status-confirmed {
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
}

.badge-success,
.status-completed,
.status-done,
.status-approved {
  background: var(--color-emerald-soft);
  color: #065f46;
}

.badge-warning,
.status-pending,
.status-in_progress,
.status-suspended {
  background: var(--color-amber-soft);
  color: #92400e;
}

.badge-danger,
.status-cancelled,
.status-rejected,
.status-overdue {
  background: var(--color-rose-soft);
  color: #9f1239;
}

.badge-violet,
.status-planning,
.status-planned {
  background: var(--color-violet-soft);
  color: #5b21b6;
}

.badge-neutral,
.status-draft {
  background: var(--color-slate-soft);
  color: #475569;
}

.badge-signal {
  background: var(--color-signal-soft);
  color: #3f6212;
}

/* === CARDS ============================================== */

.card,
.form-section {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: border-color var(--transition-card),
              box-shadow var(--transition-card),
              transform var(--transition-card);
}

.card-hero {
  padding: 28px;
}

.card-clickable,
.card[onclick],
.card[data-href] {
  cursor: pointer;
}

.card-clickable:hover,
.card[onclick]:hover,
.card[data-href]:hover {
  border-color: var(--color-line-strong);
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-1px);
}

.card-accent {
  border-left: 3px solid var(--color-accent);
}
.card-accent-primary {
  border-left: 3px solid var(--color-primary);
}
.card-accent-warning {
  border-left: 3px solid var(--color-amber);
}
.card-accent-danger {
  border-left: 3px solid var(--color-rose);
}

.card h3:first-child,
.form-section h3:first-child {
  margin: 0 0 14px 0;
  font-size: var(--font-size-lg);
  font-weight: 600;
  letter-spacing: -0.015em;
}

/* === INPUTS ============================================== */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  line-height: 1.4;
  transition: border-color var(--transition-button),
              box-shadow var(--transition-button);
}

textarea {
  min-height: 80px;
  resize: vertical;
  font-family: var(--font-sans);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

input.mono-input,
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="number"] {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.form-group label .required,
label .required {
  color: var(--color-accent);
  margin-left: 2px;
}

input.error,
select.error,
textarea.error,
.form-group.has-error input,
.form-group.has-error select,
.form-group.has-error textarea {
  border-color: var(--color-rose);
}
input.error:focus,
.form-group.has-error input:focus {
  box-shadow: 0 0 0 3px var(--color-rose-soft);
}

.form-error,
.form-group.has-error .error-message {
  font-size: var(--font-size-xs);
  color: var(--color-rose);
  margin-top: 4px;
  font-weight: 500;
}

.form-group label,
label {
  display: block;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-soft);
  margin-bottom: 5px;
  letter-spacing: 0.005em;
}

/* === MODALS ============================================== */

.modal-backdrop,
[class*="modal-overlay"] {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal,
.modal-dialog,
.modal-panel,
[class*="modal-content"] {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-line);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
}

.modal-lg,
.modal-dialog.modal-lg,
.modal-panel.lg,
.modal-panel.modal-lg {
  max-width: 800px;
}

.modal-sm,
.modal-dialog.modal-sm,
.modal-panel.sm {
  max-width: 420px;
}

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--color-line);
  background: var(--color-surface);
}

.modal-header h3 {
  font-size: var(--font-size-lg);
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0;
}

.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--color-line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--color-surface-alt);
}

/* === TOASTS ============================================== */

.toast,
.toast-item {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--color-text);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  display: flex;
  align-items: center;
  gap: 8px;
  border-left: 3px solid var(--color-primary);
  max-width: 400px;
}

.toast-success,
.toast.success {
  border-left-color: var(--color-emerald);
  background: var(--color-surface);
  color: var(--color-text);
}
.toast-error,
.toast.error,
.toast.danger {
  border-left-color: var(--color-rose);
  background: var(--color-surface);
  color: var(--color-text);
}
.toast-warning,
.toast.warning {
  border-left-color: var(--color-amber);
  background: var(--color-surface);
  color: var(--color-text);
}
.toast-info,
.toast.info {
  border-left-color: var(--color-primary);
  background: var(--color-surface);
  color: var(--color-text);
}

/* === Mono numbers utility === */

.data-num,
.data-id,
.data-date,
.data-amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
}

/* === Checkbox & radio === */

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  display: inline-block;
  accent-color: var(--color-primary);
  margin-right: 6px;
  cursor: pointer;
}

.checkbox-group,
.radio-group {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.checkbox-group label,
.radio-group label {
  display: inline-flex;
  align-items: center;
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 0;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
}

/* ==============================================================
   UI PASS 4/5 — Tabs + Tables + Form layout + Page header + Filters
   Overrides earlier rules via cascade order.
   ============================================================== */

/* === PAGE HEADER ============================================ */

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--color-line);
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: var(--font-size-3xl);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--color-text);
  line-height: 1.15;
}

/* Optional eyebrow above page title */
.page-header .eyebrow,
.page-eyebrow {
  display: block;
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.page-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* === TABS ================================================== */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-line);
  margin-bottom: 22px;
  align-items: stretch;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 10px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 0;
  transition: color var(--transition-button), border-color var(--transition-button);
  white-space: nowrap;
  letter-spacing: -0.005em;
}
.tab:hover {
  color: var(--color-text);
  background: transparent;
}
.tab.active {
  color: var(--color-text);
  border-bottom-color: var(--color-accent);
  font-weight: 700;
}

/* Optional tab counter pill (when <span class="tab-count">3</span>) */
.tab .tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 1px 7px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  background: var(--color-surface-alt);
  color: var(--color-text-soft);
  border-radius: var(--radius-pill);
  min-width: 20px;
}
.tab.active .tab-count {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

/* === TABLES ================================================ */

.data-table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-base);
}

.data-table thead {
  background: var(--color-surface-alt);
}

.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-soft);
  border-bottom: 1px solid var(--color-line);
  white-space: nowrap;
  vertical-align: middle;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-line);
  vertical-align: middle;
  color: var(--color-text);
  font-size: var(--font-size-base);
}

.data-table tbody tr {
  background: var(--color-surface);
  transition: background var(--transition-button);
}
.data-table tbody tr:hover {
  background: var(--color-surface-alt);
}
.data-table tbody tr:hover td {
  background: transparent;
}

.data-table tbody tr:last-child td { border-bottom: none; }

/* Cells with numbers/dates auto-mono */
.data-table td.num,
.data-table td.date,
.data-table td.amount,
.data-table td.id,
.data-table td.code {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.data-table .actions {
  text-align: right;
  white-space: nowrap;
}
.data-table .actions button {
  margin-left: 4px;
  padding: 4px 10px;
  font-size: var(--font-size-xs);
  font-weight: 600;
}

/* Clickable rows */
.data-table tbody tr[data-id],
.data-table tbody tr[onclick],
.data-table tbody tr.row-clickable {
  cursor: pointer;
}

/* === FORM LAYOUT ============================================ */

.form-section {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 16px;
}

.form-section h3 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 16px 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-line);
  color: var(--color-text);
}

.form-group {
  margin-bottom: 16px;
}
.form-group:last-child { margin-bottom: 0; }

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
@media (max-width: 768px) {
  .form-grid-2,
  .form-grid-3 { grid-template-columns: 1fr; }
}

/* Form actions row (footer) */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 16px;
  margin-top: 8px;
  border-top: 1px solid var(--color-line);
  flex-wrap: wrap;
}

/* Help text under input */
.form-help,
.form-group .help {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-top: 4px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

/* Fieldset wrapper */
fieldset {
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 0 0 16px;
}
fieldset legend {
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-soft);
  padding: 0 6px;
}

/* === FILTERS BAR =========================================== */

.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
}

.filters input[type="text"],
.filters input[type="search"],
.filters select {
  width: auto;
  min-width: 180px;
  margin: 0;
}

.filters label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-soft);
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
}

/* Filter chip variant (applied filters list) */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  font-weight: 600;
  cursor: pointer;
}
.filter-chip:hover {
  background: var(--color-primary);
  color: #ffffff;
}
.filter-chip::after {
  content: "×";
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
}

/* === DETAIL HEADER (visit/meeting/project pages) =========== */

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-line);
  flex-wrap: wrap;
}

.detail-title h1 {
  margin: 0;
  font-size: var(--font-size-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.detail-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-top: 6px;
}

.detail-meta strong {
  color: var(--color-text);
  font-weight: 600;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* === EMPTY STATE ============================================ */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
  font-size: var(--font-size-base);
  background: var(--color-surface);
  border: 1px dashed var(--color-line-strong);
  border-radius: var(--radius-lg);
}
.empty-state strong {
  display: block;
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text-soft);
  margin-bottom: 4px;
}

/* === MOBILE adjustments ==================================== */

@media (max-width: 768px) {
  .data-table-wrap {
    border-radius: var(--radius-md);
    overflow-x: auto;
  }
  .data-table th,
  .data-table td {
    padding: 8px 10px;
    font-size: var(--font-size-sm);
  }
  .form-section {
    padding: 16px;
  }
  .page-header h1 {
    font-size: var(--font-size-2xl);
  }
}

/* ==============================================================
   UI PASS 5/5 — Calendar + Map + Charts + Quick Search + Hero
   Final pass. Overrides earlier rules via cascade order.
   ============================================================== */

/* === DASHBOARD ============================================ */

.dash-section {
  margin-bottom: 28px;
}

.dash-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--color-line);
}

.dash-section-header h2,
.dash-section-header > div:first-child {
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-muted);
  margin: 0;
}

.dash-toggle-icon {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  transition: transform var(--transition-button);
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.dash-card {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: border-color var(--transition-card),
              box-shadow var(--transition-card),
              transform var(--transition-card);
}

.dash-card h3 {
  margin: 0 0 14px 0;
  font-size: var(--font-size-md);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--color-text);
}

.dash-list { display: flex; flex-direction: column; }

.dash-list-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 12px;
  margin: 0 -12px;
  border-bottom: 1px solid var(--color-line);
  gap: 12px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background var(--transition-button);
}
.dash-list-item:last-child { border-bottom: none; }
.dash-list-item:hover {
  background: var(--color-surface-alt);
}

/* Stat number inside dashboard card */
.dash-card .stat-num,
.dash-card .stat {
  font-family: var(--font-mono);
  font-size: var(--font-size-3xl);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.dash-card .stat-label {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  font-weight: 700;
  color: var(--color-text-muted);
  margin-top: 6px;
}

/* === HERO COUNTDOWN (Coral mono number) ==================== */

.hero-card,
.card-hero {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  position: relative;
  overflow: hidden;
}

.hero-card::before,
.card-hero::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--color-accent);
}

.hero-num {
  font-family: var(--font-mono);
  font-size: var(--font-size-4xl);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--color-accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hero-label {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  font-weight: 700;
  color: var(--color-text-muted);
  margin-top: 8px;
}

/* === CHARTS =============================================== */

.charts-grid {
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
}

.chart-wrap {
  height: 240px;
  position: relative;
  padding: 6px 0;
}

.chart-placeholder {
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  padding: 0 16px;
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
  border: 1px dashed var(--color-line-strong);
}

/* === FULLCALENDAR ========================================= */

.fc {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 14px;
  border: 1px solid var(--color-line);
}

/* Toolbar (header) */
.fc .fc-toolbar {
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.fc .fc-toolbar-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

/* Toolbar buttons */
.fc .fc-button,
.fc .fc-button-primary {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  text-transform: capitalize;
  box-shadow: none;
  transition: background var(--transition-button), border-color var(--transition-button);
}
.fc .fc-button-primary:not(:disabled):hover {
  background: var(--color-surface-alt);
  border-color: var(--color-line-strong);
  color: var(--color-text);
}
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
  box-shadow: none;
}
.fc .fc-button-primary:focus {
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.fc .fc-today-button {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #ffffff;
}
.fc .fc-today-button:not(:disabled):hover {
  background: #e64d2e;
  border-color: #e64d2e;
  color: #ffffff;
}

/* Grid headers (day names) */
.fc .fc-col-header-cell-cushion {
  padding: 8px 4px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-muted);
  text-decoration: none;
}

/* Day cells */
.fc .fc-daygrid-day-number {
  font-family: var(--font-mono);
  font-size: var(--font-size-base);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-soft);
  padding: 6px 8px;
  text-decoration: none;
}

.fc .fc-day-today {
  background: var(--color-accent-soft) !important;
}
.fc .fc-day-today .fc-daygrid-day-number {
  color: var(--color-accent);
  font-weight: 800;
}

.fc .fc-day-other .fc-daygrid-day-number {
  color: var(--color-text-subtle);
}

/* Borders / lines */
.fc .fc-scrollgrid,
.fc .fc-scrollgrid-section > *,
.fc .fc-scrollgrid td,
.fc .fc-scrollgrid th {
  border-color: var(--color-line);
}

/* Events */
.fc .fc-event {
  border: none;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  background: var(--color-primary);
  border-left: 3px solid var(--color-primary-hover);
}
.fc .fc-event:hover { filter: brightness(1.05); }
.fc .fc-event-title { font-weight: 600; }

/* Event colour variants by data type */
.fc .fc-event.event-visit,
.fc .fc-event[data-type="visit"] {
  background: var(--color-emerald-soft);
  color: #065f46;
  border-left-color: var(--color-emerald);
}
.fc .fc-event.event-meeting,
.fc .fc-event[data-type="meeting"] {
  background: var(--color-violet-soft);
  color: #5b21b6;
  border-left-color: var(--color-violet);
}
.fc .fc-event.event-trip,
.fc .fc-event[data-type="trip"] {
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
  border-left-color: var(--color-primary);
}

/* Time grid */
.fc .fc-timegrid-slot-label,
.fc .fc-timegrid-axis-cushion {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
}

/* === LEAFLET MAP ========================================== */

.leaflet-container {
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-line);
  font-family: var(--font-sans);
  background: var(--color-surface-alt);
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.12);
  border: 1px solid var(--color-line);
}

.leaflet-popup-content {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  margin: 12px 14px;
  color: var(--color-text);
}
.leaflet-popup-content strong {
  font-weight: 700;
  color: var(--color-text);
}

.leaflet-popup-tip {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
}

.leaflet-bar {
  border: 1px solid var(--color-line) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08) !important;
}
.leaflet-bar a {
  background: var(--color-surface) !important;
  color: var(--color-text) !important;
  border-color: var(--color-line) !important;
  font-weight: 700;
  font-family: var(--font-mono);
}
.leaflet-bar a:hover {
  background: var(--color-surface-alt) !important;
}

.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.85) !important;
  font-size: 10px !important;
  color: var(--color-text-muted) !important;
}

/* Map page wrapper */
.map-container,
#map,
.leaflet-page {
  height: calc(100vh - var(--topbar-height) - 60px);
  min-height: 400px;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* === QUICK SEARCH (Ctrl+K) ================================ */

.qs-backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.qs-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.25);
  max-width: 640px;
  max-height: 70vh;
}

.qs-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-line);
  gap: 10px;
}

.qs-icon {
  font-size: 18px;
  color: var(--color-text-muted);
}

.qs-header input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: var(--font-size-md);
  font-weight: 500;
  background: transparent;
  color: var(--color-text);
  padding: 0;
  box-shadow: none;
}
.qs-header input::placeholder {
  color: var(--color-text-subtle);
  font-weight: 400;
}

.qs-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--color-surface-alt);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: var(--color-text-soft);
  border: 1px solid var(--color-line);
  font-weight: 600;
}

.qs-results { padding: 6px 0; }

.qs-empty {
  padding: 32px 24px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-base);
  line-height: 1.6;
}

.qs-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-muted);
  padding: 10px 18px 6px;
}

.qs-item {
  padding: 10px 18px;
  border-left: 3px solid transparent;
  transition: background var(--transition-button), border-color var(--transition-button);
}
.qs-item:hover,
.qs-item.qs-selected {
  background: var(--color-surface-alt);
  border-left-color: var(--color-accent);
}

.qs-item-title {
  font-weight: 600;
  font-size: var(--font-size-base);
  color: var(--color-text);
}

.qs-item-sub {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* === LOGIN PAGE ============================================ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--color-bg);
}

.login-card {
  background: var(--color-surface);
  padding: 36px 32px;
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  border: 1px solid var(--color-line);
  width: 100%;
  max-width: 400px;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--color-accent);
}

.login-card h1 {
  text-align: left;
  color: var(--color-text);
  margin-bottom: 4px;
  font-size: var(--font-size-2xl);
  font-weight: 800;
  letter-spacing: -0.025em;
}

.login-card .subtitle {
  text-align: left;
  color: var(--color-text-muted);
  margin-bottom: 24px;
  font-size: var(--font-size-sm);
  font-weight: 500;
}

/* === MOBILE adjustments for 5/5 ============================ */

@media (max-width: 768px) {
  .fc { padding: 8px; }
  .fc .fc-toolbar-title { font-size: var(--font-size-lg); }
  .fc .fc-button { padding: 4px 10px; font-size: var(--font-size-xs); }

  .hero-num { font-size: 48px; }
  .hero-card, .card-hero { padding: 22px 18px; }

  .qs-panel { width: 95%; max-height: 80vh; }

  .map-container, #map, .leaflet-page {
    height: calc(100vh - var(--topbar-height) - 40px);
  }
}

/* Geocoding typeahead dropdown for site address (project-detail) */
.geo-input-wrapper { position: relative; }
.geo-dropdown {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-line, #ccc);
  border-top: none;
  max-height: 240px;
  overflow-y: auto;
  z-index: 10000;
  box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}
.geo-dropdown-item {
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-line, #eee);
  font-size: 13px;
}
.geo-dropdown-item:hover,
.geo-dropdown-item.active {
  background: var(--color-surface-alt, #f0f6ff);
}
.geo-dropdown-empty,
.geo-dropdown-loading {
  padding: 8px 10px;
  color: var(--color-text-muted, #888);
  font-size: 13px;
}

/* + New activity button + dropdown (project Activity tab) */
.activity-action-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}
.activity-action-wrapper { position: relative; }
.new-activity-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.new-activity-trigger .caret { font-size: 10px; opacity: 0.8; }
.new-activity-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-line, #d0d7de);
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
  z-index: 10000;
  padding: 4px;
}
.new-activity-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
  color: var(--color-text, #1f2328);
}
.new-activity-item:hover { background: var(--color-surface-alt, #f0f6ff); }
.new-activity-item .ico { font-size: 14px; }
.activity-action-bar[hidden] { display: none; }

/* C.6 — post-closure edit banner */
.banner {
  padding: 10px 16px;
  border-radius: 4px;
  font-size: 0.9em;
}
.banner-warn {
  background: #fff3cd;
  border-left: 4px solid #f0ad4e;
  margin-bottom: 12px;
  color: #856404;
}
.banner-warn a { color: #6d5004; text-decoration: underline; font-weight: 500; }
.banner-muted {
  background: var(--color-surface-alt, #f4f3ee);
  border-left: 4px solid var(--color-line-strong, #d6d3c7);
  color: var(--color-text-soft, #475569);
  margin-bottom: 12px;
}

/* ============================================================
   C.8.A — Dashboard visual polish (typography, empty states,
   stat numbers, hover lift, page header)
   ============================================================ */

/* Empty state sub-elements (parent .empty-state defined earlier) */
.empty-state-glyph {
  display: block;
  font-size: 28px;
  color: var(--color-text-subtle);
  margin-bottom: 8px;
  line-height: 1;
}
.empty-state-message {
  font-size: 13px;
  color: var(--color-text-muted);
  max-width: 320px;
  margin: 0 auto;
}
.empty-state-cta {
  margin-top: 16px;
}

/* Mono utility + entity ID code */
.mono {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.01em;
}
.id-code {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.01em;
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.95em;
}

/* Section count chip inside dash-section-header */
.dash-section-count {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-left: 6px;
  font-size: 0.85em;
}

/* Overdue badge — coral, reserved for urgency */
.badge-overdue {
  background: var(--color-accent-soft);
  color: var(--color-accent-hover);
}
.badge-overdue::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-accent);
  margin-right: 5px;
  vertical-align: middle;
}

/* Dashboard page header (Dashboard title + Welcome eyebrow) */
.dash-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}
.dash-page-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--color-text);
  margin: 0;
}
.dash-welcome {
  margin: 0;
  text-align: right;
  line-height: 1.4;
}
.dash-welcome-eyebrow {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.dash-welcome-name {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
}

/* Stat numbers (big mono) — neutral by default; urgent → coral */
.dash-stat {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1;
  font-size: 28px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.02em;
  line-height: 1;
}
.dash-stat-urgent {
  color: var(--color-accent);
}

/* Hover lift for clickable dashboard cards */
.dash-card.card-clickable:hover,
.dash-card[data-href]:hover,
.dash-card[onclick]:hover {
  border-color: var(--color-line-strong);
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  transform: translateY(-1px);
  cursor: pointer;
}

/* Tighten vertical rhythm between dash-sections */
.dash-section { margin-bottom: 32px; }
.dash-section:last-child { margin-bottom: 0; }

/* ============================================================
   C.8.B.1 — List page polish (rows + table-context empty state)
   ============================================================ */

/* Hover row for clickable rows in data tables */
.data-table tbody tr[data-id] {
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.data-table tbody tr[data-id]:hover td {
  background-color: var(--color-surface-alt);
}

/* Empty state variant when rendered as a <td colspan=N> inside <tbody> —
   the global .empty-state has a dashed border + background that looks
   awkward in a table cell. Override for this context only. */
td.empty-state {
  text-align: center;
  padding: 32px 16px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 13px;
}
td.empty-state::before {
  content: "○";
  display: block;
  font-size: 24px;
  color: var(--color-text-subtle);
  margin-bottom: 6px;
  line-height: 1;
}

/* ============================================================
   C.8.B.1.1 — Stacked entity layout + semantic role badges
   ============================================================ */

/* Stacked column: name on top + ID below (or other secondary line) */
.entity-stacked {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.entity-stacked-name {
  font-weight: 600;
  color: var(--color-text);
}
.entity-stacked-secondary {
  font-size: 12px;
  color: var(--color-text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 360px;
}
.entity-stacked-more {
  margin-left: 6px;
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: 400;
}

/* Role badges — semantic colors */
.badge-role-admin {
  background: var(--color-accent-soft);
  color: var(--color-accent-hover);
}
.badge-role-manager-tec,
.badge-role-manager-com {
  background: var(--color-violet-soft);
  color: var(--color-violet);
}
.badge-role-tecnico {
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
}
.badge-role-comercial {
  background: var(--color-emerald-soft);
  color: var(--color-emerald);
}
.badge-role-adv {
  background: var(--color-slate-soft);
  color: var(--color-slate);
}
/* Secondary role: outline variant — same family color but transparent bg */
.badge-role-secondary {
  background: transparent;
  border: 1px solid currentColor;
}

/* C.9.B.3 — Timeline component for BTP history */
.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
}
.timeline-item {
  position: relative;
  padding-left: 24px;
  padding-bottom: 16px;
  border-left: 2px solid var(--color-border, #e5e7eb);
  margin-left: 8px;
}
.timeline-item:last-child {
  padding-bottom: 0;
  border-left-color: transparent;
}
.timeline-dot {
  position: absolute;
  left: -7px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-text-muted, #9ca3af);
  border: 2px solid var(--color-surface, #fff);
}
.timeline-dot-current {
  background: var(--color-primary, #1e40af);
}
.timeline-item-current {
  border-left-color: var(--color-primary, #1e40af);
}
.timeline-header {
  font-size: 14px;
  margin-bottom: 2px;
}
.timeline-meta {
  font-size: 12px;
}
.timeline-content {
  padding-bottom: 4px;
}
