/* =============================================================
   PCL Design Tokens — v2 redesign
   ============================================================= */
:root {
  /* Neutrals — warm paper (light surface) */
  --pcl-ink:       #0F0F10;
  --pcl-graphite:  #1A1A1C;
  --pcl-slate:     #3A3A3E;
  --pcl-steel:     #6B6B70;
  --pcl-mute:      #9A9A9F;
  --pcl-rule:      #E4E2DC;
  --pcl-rule-soft: #EFEDE7;
  --pcl-paper:     #FAFAF7;
  --pcl-paper-2:   #F3F1EB;
  --pcl-card:      #FFFFFF;

  /* Signal — hue preserved across surfaces */
  --pcl-ember: oklch(0.68 0.17 50);
  --pcl-ok:    oklch(0.62 0.11 155);
  --pcl-warn:  oklch(0.76 0.13 80);
  --pcl-bad:   oklch(0.60 0.19 25);
  --pcl-cool:  oklch(0.58 0.09 240);

  /* Chip tints — LIGHT surface */
  --pcl-ember-tint: oklch(0.95 0.04 55);
  --pcl-ember-ink:  oklch(0.42 0.15 40);
  --pcl-ok-tint:    oklch(0.95 0.04 155);
  --pcl-ok-ink:     oklch(0.35 0.09 155);
  --pcl-warn-tint:  oklch(0.96 0.05 85);
  --pcl-warn-ink:   oklch(0.42 0.10 80);
  --pcl-bad-tint:   oklch(0.95 0.04 25);
  --pcl-bad-ink:    oklch(0.40 0.15 25);
  --pcl-cool-tint:  oklch(0.95 0.03 240);
  --pcl-cool-ink:   oklch(0.38 0.08 240);

  /* Hairlines + focus */
  --pcl-swatch-edge:  rgba(0, 0, 0, 0.14);
  --pcl-focus-offset: var(--pcl-paper);

  /* Bootstrap binding */
  --bs-body-bg:      var(--pcl-paper);
  --bs-body-color:   var(--pcl-ink);
  --bs-border-color: var(--pcl-rule);
  --bs-primary:      var(--pcl-ink);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  /* Radius */
  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 8px;

  /* Typography */
  --font-display: 'Fraunces', Georgia, serif;
  --font-ui:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, 'Cascadia Code', monospace;
}

/* DARK surface */
[data-surface="ink"] {
  --pcl-paper:    #0E0E10;
  --pcl-paper-2:  #17171A;
  --pcl-card:     #1C1C20;
  --pcl-ink:      #F4F2EC;
  --pcl-graphite: #E8E6DF;
  --pcl-slate:    #C2C0BA;
  --pcl-steel:    #8A8883;
  --pcl-mute:     #6A6864;

  /* Rules — better contrast on --pcl-card */
  --pcl-rule:      #34343A;
  --pcl-rule-soft: #26262B;

  /* Chip tints — DARK surface */
  --pcl-ember-tint: oklch(0.26 0.06 55);
  --pcl-ember-ink:  oklch(0.82 0.15 55);
  --pcl-ok-tint:    oklch(0.24 0.05 155);
  --pcl-ok-ink:     oklch(0.80 0.12 155);
  --pcl-warn-tint:  oklch(0.26 0.05 85);
  --pcl-warn-ink:   oklch(0.85 0.13 85);
  --pcl-bad-tint:   oklch(0.26 0.07 25);
  --pcl-bad-ink:    oklch(0.80 0.16 25);
  --pcl-cool-tint:  oklch(0.26 0.04 240);
  --pcl-cool-ink:   oklch(0.80 0.10 240);

  /* Hairlines flip to light */
  --pcl-swatch-edge:  rgba(255, 255, 255, 0.18);
  --pcl-focus-offset: var(--pcl-card);

  /* Bootstrap binding */
  --bs-body-bg:      var(--pcl-paper);
  --bs-body-color:   var(--pcl-ink);
  --bs-border-color: var(--pcl-rule);
  --bs-primary:      var(--pcl-ink);
}

/* Mono utility */
.mono {
  font-family: var(--font-mono);
  font-feature-settings: "zero";
}

/* Oven meter pulse — only permitted loop animation */
@keyframes pcl-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }  /* 0.5 stays visible on dark surfaces */
}

/* Focus ring */
:focus-visible {
  outline: 2px solid var(--pcl-ember);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--pcl-focus-offset);
}

/* =============================================================
   PCL Status Chips
   ============================================================= */
.pcl-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 500 10.5px/1.2 var(--font-mono);
  font-feature-settings: "zero";
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}
.pcl-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 99px;
  flex-shrink: 0;
}
/* Foreground uses *-ink paired token — lightness-adjusted per surface */
.pcl-chip-ok      { background: var(--pcl-ok-tint);    color: var(--pcl-ok-ink); }
.pcl-chip-ok      .pcl-chip-dot { background: var(--pcl-ok); }
.pcl-chip-warn    { background: var(--pcl-warn-tint);  color: var(--pcl-warn-ink); }
.pcl-chip-warn    .pcl-chip-dot { background: var(--pcl-warn); }
.pcl-chip-bad     { background: var(--pcl-bad-tint);   color: var(--pcl-bad-ink); }
.pcl-chip-bad     .pcl-chip-dot { background: var(--pcl-bad); }
.pcl-chip-cool    { background: var(--pcl-cool-tint);  color: var(--pcl-cool-ink); }
.pcl-chip-cool    .pcl-chip-dot { background: var(--pcl-cool); }
.pcl-chip-ember   { background: var(--pcl-ember-tint); color: var(--pcl-ember-ink); }
.pcl-chip-ember   .pcl-chip-dot { background: var(--pcl-ember); }
.pcl-chip-neutral { background: var(--pcl-paper-2);    color: var(--pcl-slate); }
.pcl-chip-neutral .pcl-chip-dot { background: var(--pcl-steel); }

/* =============================================================
   PCL Metric tile
   ============================================================= */
.pcl-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pcl-metric-kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--pcl-steel);
  line-height: 1.2;
}
.pcl-metric-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 500;
  line-height: 1;
  color: var(--pcl-ink);
}
.pcl-metric-delta {
  font-family: var(--font-mono);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.pcl-metric-delta.up   { color: var(--pcl-ok); }
.pcl-metric-delta.down { color: var(--pcl-bad); }

/* =============================================================
   PCL Powder swatch
   ============================================================= */
.pcl-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px var(--pcl-swatch-edge);
  flex-shrink: 0;
  vertical-align: middle;
}

/* =============================================================
   PCL Section Header
   ============================================================= */
.pcl-section-header {
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--pcl-rule);
  margin-bottom: var(--space-4);
}
.pcl-section-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.005em;
  color: var(--pcl-ink);
}
.pcl-section-meta {
  font-size: 12px;
  color: var(--pcl-steel);
}

/* =============================================================
   PCL Metric strip — replaces stats-cards-desktop + mobile-stats-compact
   ============================================================= */
.pcl-metric-strip {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
  border: 1px solid var(--pcl-rule);
  border-radius: var(--radius-lg);
  background: var(--pcl-card);
  overflow: hidden;
}
.pcl-metric-strip-cell {
  flex: 1 1 120px;
  padding: var(--space-4) var(--space-5);
  border-right: 1px solid var(--pcl-rule);
}
.pcl-metric-strip-cell:last-child {
  border-right: none;
}
@media (max-width: 576px) {
  .pcl-metric-strip-cell {
    flex-basis: 50%;
    border-right: 1px solid var(--pcl-rule);
    border-bottom: 1px solid var(--pcl-rule);
  }
  .pcl-metric-strip-cell:nth-child(even) {
    border-right: none;
  }
  .pcl-metric-strip-cell:nth-last-child(-n+2):not(:nth-child(even) ~ *) {
    border-bottom: none;
  }
  .pcl-metric-strip-cell:last-child {
    border-bottom: none;
  }
}

/* =============================================================
   Jobs list — hot-job 2px left edge on first cell
   ============================================================= */
.job-hot-cell {
  box-shadow: inset 2px 0 0 var(--pcl-bad);
}

/* Table kicker headers — mono uppercase 10px */
.table thead th.th-kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pcl-steel);
  border-bottom: 1px solid var(--pcl-rule);
  white-space: nowrap;
}

/* Quick-view pills row */
.pcl-pill-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.pcl-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--pcl-rule);
  background: var(--pcl-card);
  color: var(--pcl-steel);
  text-decoration: none;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  cursor: pointer;
}
.pcl-pill:hover {
  background: var(--pcl-paper-2);
  color: var(--pcl-ink);
  border-color: var(--pcl-steel);
}
.pcl-pill.active {
  background: var(--pcl-ink);
  color: var(--pcl-paper);
  border-color: var(--pcl-ink);
}
.pcl-pill .pcl-pill-count {
  font-family: var(--font-mono);
  font-size: 10px;
  opacity: 0.7;
}

/* Keyboard hint footer */
.pcl-kbd-footer {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--pcl-mute);
  padding: 6px 16px;
  border-top: 1px solid var(--pcl-rule-soft);
  letter-spacing: 0.02em;
}

/* =============================================================
   Hover lift — list-item row hover in dashboard feeds
   ============================================================= */
.hover-lift {
  transition: background-color 0.15s ease;
}
.hover-lift:hover {
  background-color: var(--pcl-paper-2) !important;
}

/* =============================================================
   Mono numerics — any td/th with class="num" renders in IBM Plex Mono
   ============================================================= */
.table td.num,
.table th.num {
  font-family: var(--font-mono);
  font-feature-settings: "zero";
}

/* =============================================================
   Toastr dark-surface overrides
   (Toastr doesn't follow data-bs-theme; override manually)
   ============================================================= */
[data-surface="ink"] #toast-container > .toast-success {
  background-color: var(--pcl-ok-tint);
  color: var(--pcl-ok-ink);
}
[data-surface="ink"] #toast-container > .toast-error {
  background-color: var(--pcl-bad-tint);
  color: var(--pcl-bad-ink);
}
[data-surface="ink"] #toast-container > .toast-warning {
  background-color: var(--pcl-warn-tint);
  color: var(--pcl-warn-ink);
}
[data-surface="ink"] #toast-container > .toast-info {
  background-color: var(--pcl-cool-tint);
  color: var(--pcl-cool-ink);
}

/* =============================================================
   Theme toggle button
   ============================================================= */
.pcl-theme-toggle {
  color: var(--pcl-slate);
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.pcl-theme-toggle:hover {
  color: var(--pcl-ink);
  background: var(--pcl-paper-2);
  border-color: var(--pcl-rule);
}

/* =============================================================
   Global focus ring — ember
   ============================================================= */
:focus-visible {
  outline: 2px solid var(--pcl-ember);
  outline-offset: 2px;
}

/* =============================================================
   Equipment Status Colors */
.equipment-status-operational {
    background-color: #d1fae5;
    color: #065f46;
}

.equipment-status-needs-maintenance {
    background-color: #fef3c7;
    color: #92400e;
}

.equipment-status-under-maintenance {
    background-color: #dbeafe;
    color: #1e40af;
}

.equipment-status-out-of-service {
    background-color: #fee2e2;
    color: #991b1b;
}

.equipment-status-retired {
    background-color: #e5e7eb;
    color: #4b5563;
}

/* Maintenance Status Colors */
.maintenance-status-scheduled {
    background-color: #dbeafe;
    color: #1e40af;
}

.maintenance-status-in-progress {
    background-color: #fef3c7;
    color: #92400e;
}

.maintenance-status-completed {
    background-color: #d1fae5;
    color: #065f46;
}

.maintenance-status-overdue {
    background-color: #fee2e2;
    color: #991b1b;
}

.maintenance-status-cancelled {
    background-color: #e5e7eb;
    color: #4b5563;
}

/* Maintenance Priority Colors */
.maintenance-priority-low {
    background-color: #e5e7eb;
    color: #4b5563;
}

.maintenance-priority-normal {
    background-color: #dbeafe;
    color: #1e40af;
}

.maintenance-priority-high {
    background-color: #fef3c7;
    color: #92400e;
}

.maintenance-priority-critical {
    background-color: #fee2e2;
    color: #991b1b;
}

/* File Upload Styles */
.file-upload-zone {
    border: 2px dashed var(--bs-border-color);
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
}

.file-upload-zone:hover {
    border-color: #4f46e5;
    background-color: var(--bs-tertiary-bg);
}

.file-upload-zone.dragover {
    border-color: #4f46e5;
    background-color: var(--bs-primary-bg-subtle);
}

/* Timeline Styles */
.timeline {
    position: relative;
    padding-left: 0;
}

.timeline-item {
    position: relative;
    padding-left: 0;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: 17px;
    top: 40px;
    bottom: -20px;
    width: 2px;
    background-color: var(--bs-border-color);
}

.timeline-item:last-child::before {
    display: none;
}

/* Alert Permanent */
.alert-permanent {
    /* Prevents auto-dismiss */
}

/* Custom Badge Styles */
.badge {
    font-weight: 500;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
}

/* Loading State */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

/* Responsive Table */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Custom Form Styles */
.form-control,
.form-select {
    border: 1.5px solid #9ca3af;
}

.form-control:focus,
.form-select:focus {
    border-color: #4f46e5;
    border-width: 1.5px;
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.25);
}

/* Equipment Card Styles */
.equipment-card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.equipment-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}


/* Sortable Column Styles */
th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    background-color: var(--bs-tertiary-bg);
}

th.sortable a {
    display: block;
    padding: 0.5rem;
    margin: -0.5rem;
}

th.sortable a:hover {
    text-decoration: none !important;
}

th.sortable i {
    font-size: 0.875rem;
    opacity: 0.6;
}

th.sortable:hover i {
    opacity: 1;
}

/* Pagination Styles */
.pagination {
    margin-bottom: 0;
}

.pagination .page-link {
    color: var(--pcl-steel);
    background-color: var(--pcl-card);
    border-color: var(--pcl-rule);
    font-family: var(--font-mono);
    font-size: 13px;
}

.pagination .page-item.active .page-link {
    background-color: var(--pcl-ink);
    border-color: var(--pcl-ink);
    color: var(--pcl-paper);  /* flips correctly: dark bg+light text in light; light bg+dark text in dark */
}

.pagination .page-item.disabled .page-link {
    color: var(--pcl-mute);
    pointer-events: none;
    background-color: var(--pcl-card);
    border-color: var(--pcl-rule);
}

.pagination .page-link:hover {
    background-color: var(--pcl-paper-2);
    border-color: var(--pcl-rule);
    color: var(--pcl-ink);
}

.form-select-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

/* Mobile Responsiveness - Stats Cards (deprecated - now using compact card) */

/* Mobile Touch Optimization */
@media (max-width: 768px) {
    /* Touch Target Sizes - Minimum 44px */
    .btn, .btn-sm {
        min-height: 44px;
        padding: 0.625rem 1rem;
        font-size: 0.9375rem;
    }

    .btn-group .btn {
        min-width: 44px;
        padding: 0.625rem;
    }

    .form-control, .form-select {
        min-height: 44px;
        font-size: 1rem;
    }

    .pagination .page-link {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Modal Optimization */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-title {
        font-size: 1.125rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }

    /* Form Layout Optimization */
    .row.g-3 > [class*="col-md-"] {
        width: 100%;
        max-width: 100%;
    }

    .row.g-3 > .col-6 {
        width: 50%;
        max-width: 50%;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }
}

/* Mobile Tab Selector for Settings Pages */
#mobileTabSelector {
    font-size: 1rem;
    font-weight: 500;
    border: 2px solid var(--bs-border-color);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    cursor: pointer;
}

#mobileTabSelector:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

@media (max-width: 767px) {
    /* Ensure tab content has proper spacing on mobile */
    .tab-content {
        margin-top: 0 !important;
    }

    .tab-content .card {
        margin-top: 0 !important;
    }
}

/* Validation - Hide empty validation summary */
.validation-summary-valid {
    display: none !important;
}

/* ===== Dark Mode Overrides ===== */

/* Equipment status badges */
[data-bs-theme="dark"] .equipment-status-operational {
    background-color: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

[data-bs-theme="dark"] .equipment-status-needs-maintenance {
    background-color: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

[data-bs-theme="dark"] .equipment-status-under-maintenance {
    background-color: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
}

[data-bs-theme="dark"] .equipment-status-out-of-service {
    background-color: rgba(248, 113, 113, 0.2);
    color: #f87171;
}

[data-bs-theme="dark"] .equipment-status-retired {
    background-color: rgba(156, 163, 175, 0.15);
    color: #9ca3af;
}

/* Maintenance status badges */
[data-bs-theme="dark"] .maintenance-status-scheduled {
    background-color: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
}

[data-bs-theme="dark"] .maintenance-status-in-progress {
    background-color: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

[data-bs-theme="dark"] .maintenance-status-completed {
    background-color: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

[data-bs-theme="dark"] .maintenance-status-overdue {
    background-color: rgba(248, 113, 113, 0.2);
    color: #f87171;
}

[data-bs-theme="dark"] .maintenance-status-cancelled {
    background-color: rgba(156, 163, 175, 0.15);
    color: #9ca3af;
}

/* Maintenance priority badges */
[data-bs-theme="dark"] .maintenance-priority-low {
    background-color: rgba(156, 163, 175, 0.15);
    color: #9ca3af;
}

[data-bs-theme="dark"] .maintenance-priority-normal {
    background-color: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
}

[data-bs-theme="dark"] .maintenance-priority-high {
    background-color: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

[data-bs-theme="dark"] .maintenance-priority-critical {
    background-color: rgba(248, 113, 113, 0.2);
    color: #f87171;
}

/* bg-warning text-dark and bg-info text-dark badges:
   In dark mode Bootstrap changes --bs-dark to a light gray,
   which gives poor contrast on yellow/cyan backgrounds.
   Force dark text so contrast is maintained. */
[data-bs-theme="dark"] .bg-warning {
    color: #000 !important;
}

[data-bs-theme="dark"] .bg-info {
    color: #000 !important;
}

/* ============================================================
   Tom Select — dark mode fixes
   Tom Select's Bootstrap 5 theme hardcodes color:#343a40 which
   is near-invisible on Bootstrap's dark body background. Using
   html prefix for maximum specificity; all colours hard-coded to
   avoid CSS variable resolution issues.
   ============================================================ */

/* Control box */
html[data-bs-theme="dark"] .ts-control {
    color: #dee2e6 !important;
    background-color: #212529 !important;
    border-color: #495057 !important;
}
html[data-bs-theme="dark"] .ts-control input {
    color: #dee2e6 !important;
}
html[data-bs-theme="dark"] .ts-control input::placeholder {
    color: #6c757d !important;
}

/* Selected item text */
html[data-bs-theme="dark"] .ts-control .item {
    color: #dee2e6 !important;
}

/* Dropdown panel */
html[data-bs-theme="dark"] .ts-dropdown {
    color: #dee2e6 !important;
    background-color: #2b3035 !important;
    border-color: #495057 !important;
}

/* Every option row — override cascaded #343a40 from Tom Select theme */
html[data-bs-theme="dark"] .ts-dropdown .option,
html[data-bs-theme="dark"] .ts-dropdown .no-results,
html[data-bs-theme="dark"] .ts-dropdown .optgroup-header,
html[data-bs-theme="dark"] .ts-dropdown .create {
    color: #dee2e6 !important;
    background-color: #2b3035 !important;
}

/* Highlighted (hover/keyboard) option */
html[data-bs-theme="dark"] .ts-dropdown .option.active,
html[data-bs-theme="dark"] .ts-dropdown .active {
    background-color: #0d6efd !important;
    color: #fff !important;
}

/* Multi-select chips */
html[data-bs-theme="dark"] .ts-wrapper.multi .ts-control > div {
    background: #343a40 !important;
    color: #dee2e6 !important;
    border-color: #495057 !important;
}

/* Dropdown caret arrow — swap dark SVG for a light one */
html[data-bs-theme="dark"] .ts-wrapper:not(.form-control, .form-select).single .ts-control {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23dee2e6' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3E%3C/svg%3E");
    background-position: right .75rem center;
    background-repeat: no-repeat;
    background-size: 16px 12px;
}

/* Search field inside open dropdown */
html[data-bs-theme="dark"] .ts-dropdown .dropdown-input {
    color: #dee2e6 !important;
    background: #212529 !important;
    border-color: #495057 !important;
}

/* ============================================================
   Item wizard (Quotes/Create, Jobs/Create, Jobs/Edit) — dark mode
   The inline styles in these views hardcode #fff/#fafafa/#dee2e6.
   ============================================================ */
[data-bs-theme="dark"] .item-type-card {
    background: var(--bs-secondary-bg) !important;
    border-color: var(--bs-border-color) !important;
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .item-type-card:hover {
    border-color: #86b7fe !important;
    background: rgba(13, 110, 253, 0.15) !important;
}

[data-bs-theme="dark"] .item-type-card.selected {
    border-color: #0d6efd !important;
    background: rgba(13, 110, 253, 0.2) !important;
}

[data-bs-theme="dark"] .quote-item-card {
    background: var(--bs-secondary-bg) !important;
    border-color: var(--bs-border-color) !important;
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .coat-row {
    border-color: var(--bs-border-color) !important;
    background: var(--bs-body-bg);
}

[data-bs-theme="dark"] .wizard-step-dot {
    background: var(--bs-secondary-bg) !important;
    border-color: var(--bs-border-color) !important;
}

[data-bs-theme="dark"] .wizard-step-line {
    background: var(--bs-border-color) !important;
}

/* ============================================================
   Tag chip input widget
   ============================================================ */

/* Chips area sits below the input — input height never changes */
.tag-chips-area {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
}

/* Remove × inside each chip */
.tag-chip .tag-remove {
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    vertical-align: middle;
}
.tag-chip .tag-remove:hover {
    opacity: 1;
}

/* Clickable tag links in Index grids — hover darkens slightly */
a.tag-index-badge:hover {
    filter: brightness(0.88);
    text-decoration: none;
}

/* =============================================================
   Design system utilities — audit fixes 2026-05
   ============================================================= */

/* ── Card consistency ──────────────────────────────────────────
   Standard is `card border-0 shadow-sm`. Any shadow card that
   drifted to just `shadow-sm` gets border stripped here.        */
.card.shadow-sm {
    border: 0 !important;
}

/* ── Card header dark-mode fix ─────────────────────────────────
   bg-white hardcodes light mode. Rebind to theme surface so
   card headers follow the user's dark/light preference.         */
.card-header.bg-white {
    background-color: var(--bs-body-bg) !important;
}

/* ── Typography scale utilities ────────────────────────────────
   Fills the gap between Bootstrap's .small and the custom
   .nav-section-title / .pcl-metric-label sizes.                 */
.text-2xs { font-size: 0.68rem; line-height: 1.4; }
.text-xs  { font-size: 0.73rem; line-height: 1.4; }

/* ── Token color utilities ─────────────────────────────────────
   Use .text-ember for the amber brand accent.
   Use .text-primary only for near-black ink (Bootstrap default).
   Never use text-primary when you want the orange accent.       */
.text-ember { color: var(--pcl-ember) !important; }
.text-ok    { color: var(--pcl-ok)    !important; }
.text-bad   { color: var(--pcl-bad)   !important; }
.text-warn  { color: var(--pcl-warn)  !important; }
.text-cool  { color: var(--pcl-cool)  !important; }
.bg-paper-2 { background-color: var(--pcl-paper-2) !important; }

/* ── Max-width layout constraints ──────────────────────────────
   Use these instead of inline style="max-width:Npx"             */
.mw-xs { max-width: 280px; }
.mw-sm { max-width: 360px; }
.mw-md { max-width: 480px; }

/* =============================================================
   MOBILE / TABLET RESPONSIVENESS — Phase 2 patches
   ============================================================= */

/* ── 1. Top-navbar: prevent left-side from overflowing on phone ──────────
   The navbar left side is: hamburger + icon + h1.page-title + company badge.
   On narrow phones (<576px) this row is ~340px of content in ~330px space.
   Fix: let the page-title shrink and truncate; hide company badge.          */
@media (max-width: 575.98px) {
  .top-navbar {
    padding: 0.625rem 0.75rem;
    gap: 0.35rem;
  }
  /* Allow left cluster to shrink — prevents pushing user-menu off-screen */
  .top-navbar > .d-flex:first-child {
    min-width: 0;
    flex: 1 1 0;
    gap: 0.35rem;
  }
  .page-title {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 40vw;
  }
  /* Company badge in top-navbar adds width without adding value on phone — hide it */
  .top-navbar .badge.bg-primary {
    display: none !important;
  }
}

/* ── 2. Content area: flex children need min-width:0 to allow shrinking ──
   Without this, h4/h5 inside a flex container can't shrink below their
   natural content width, blowing the container past the viewport edge.      */
.d-flex > h4,
.d-flex > h5 {
  min-width: 0;
}

/* ── 3. Page-header rows: let title stack above action buttons on phone ──
   The near-universal pattern is:
     d-flex justify-content-between align-items-center mb-3 / mb-4
   Adding flex-wrap lets the h4 take line 1, buttons wrap to line 2.
   The mb-3/mb-4 specificity ensures we only hit block-level separators,
   not inline rows or filter bars.                                           */
@media (max-width: 575.98px) {
  .d-flex.justify-content-between.align-items-center.mb-3,
  .d-flex.justify-content-between.align-items-center.mb-4,
  .d-flex.align-items-center.justify-content-between.mb-3,
  .d-flex.align-items-center.justify-content-between.mb-4 {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

/* ── 4. Card headers: let title + card-level actions wrap on phone ────────
   Card headers use the same justify-content-between pattern.                */
@media (max-width: 575.98px) {
  .card-header .d-flex.justify-content-between,
  .card-header .d-flex.align-items-center.gap-2 {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .card-header h5 {
    min-width: 0;
    flex-shrink: 1;
  }
}

/* ── 5. Details page top button bars: wrap instead of overflow ────────────
   Pattern: d-flex justify-content-end gap-2 mb-4 (Download PDF, Back, Edit…) */
@media (max-width: 575.98px) {
  .d-flex.justify-content-end.gap-2.mb-4,
  .d-flex.gap-2.justify-content-end.mb-4 {
    flex-wrap: wrap;
  }
}

/* ── 6. Alert filter banners: wrap action button below text on phone ──────
   Pattern: alert d-flex justify-content-between align-items-center           */
@media (max-width: 575.98px) {
  .alert.d-flex.justify-content-between.align-items-center,
  .alert.d-flex.align-items-center.justify-content-between {
    flex-wrap: wrap;
    gap: 0.4rem;
  }
}

/* ── 7. Table row buttons: exempt from the global 44px touch-target floor ─
   The global rule (.btn, .btn-sm { min-height: 44px }) is right for form
   buttons, but forces table rows to ~50px tall on mobile — too bloated.
   Buttons inside .table and inside .btn-group-sm stay compact.              */
@media (max-width: 768px) {
  .table .btn,
  .table .btn-sm,
  .btn-group-sm > .btn {
    min-height: unset !important;
    padding: 0.25rem 0.5rem !important;
    font-size: 0.8rem !important;
  }
}

/* ── 8. Notification dropdown: prevent overflow on narrow phones ──────────
   Fixed width: 360px clips content on 360px phones.                         */
@media (max-width: 575.98px) {
  .notif-dropdown {
    width: calc(100vw - 2rem) !important;
    min-width: unset !important;
  }
}

/* ── 9. Search inputs in card/page headers: remove enforced min-width ─────
   Several views set style="min-width:200px" inline on the input-group.
   This is fine on tablets but breaks layout on <400px phones.               */
@media (max-width: 400px) {
  .card-header .input-group,
  .input-group[style*="min-width"] {
    min-width: unset !important;
  }
}

/* ── 10. Tablet (768px): tighten content area padding ─────────────────────
   2rem padding on both sides = 64px wasted on a 768px screen. Use 1.25rem. */
@media (min-width: 577px) and (max-width: 991px) {
  .content-area {
    padding: 1.25rem;
  }
}
.mw-lg { max-width: 640px; }

/* ── Inline item edit ───────────────────────────────────────── */
.inline-editable:hover {
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}
.inline-edit-input {
    display: inline-block;
    padding: 1px 4px;
    height: auto;
}
