/**
 * CPR Design System
 *
 * A minimal set of CSS custom properties that define the entire color scheme.
 * Dark mode is automatic via prefers-color-scheme.
 *
 * Usage: Just use var(--xxx) instead of hardcoded colors.
 * Never write a color value directly in component CSS.
 */

:root {
  /* ===== SURFACES (backgrounds) ===== */
  --bg-page: #f3f4f6;        /* Page background */
  --bg-card: #ffffff;        /* Cards, panels, modals */
  --bg-nested: #f9fafb;      /* Nested content inside cards */
  --bg-input: #ffffff;       /* Input fields */
  --bg-hover: #f3f4f6;       /* Hover states on interactive elements */

  /* ===== TEXT ===== */
  --text: #1f2937;           /* Primary text */
  --text-muted: #6b7280;     /* Secondary/helper text */
  --text-heading: #1f2937;   /* Headings */

  /* ===== BORDERS ===== */
  --border: #e5e7eb;         /* Standard borders */
  --border-strong: #d1d5db;  /* Emphasized borders (inputs) */
  --border-focus: #3b82f6;   /* Focus ring color */

  /* ===== PRIMARY BUTTON ===== */
  --btn-bg: #3b82f6;
  --btn-bg-hover: #2563eb;
  --btn-text: #ffffff;

  /* ===== SECONDARY BUTTON ===== */
  --btn-secondary-bg: #e5e7eb;
  --btn-secondary-bg-hover: #d1d5db;
  --btn-secondary-text: #374151;

  /* ===== STATUS COLORS ===== */
  --success-bg: #d1fae5;
  --success-text: #065f46;
  --success-border: #6ee7b7;
  --success: #10b981;

  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --warning-border: #fcd34d;
  --warning: #f59e0b;

  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --error-border: #fecaca;
  --error: #ef4444;

  --info-bg: #bfdbfe;
  --info-text: #1e40af;
  --info-border: #93c5fd;
  --info: #3b82f6;

  /* ===== MISC ===== */
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --radius: 0.375rem;
  --radius-lg: 0.5rem;
  --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* ===== DARK MODE ===== */
/* Auto: fires when OS/browser is in dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    /* Surfaces */
    --bg-page: #111827;
    --bg-card: #1f2937;
    --bg-nested: #374151;
    --bg-input: #374151;
    --bg-hover: #374151;

    /* Text */
    --text: #f3f4f6;
    --text-muted: #9ca3af;
    --text-heading: #f3f4f6;

    /* Borders */
    --border: #4b5563;
    --border-strong: #6b7280;
    --border-focus: #60a5fa;

    /* Primary Button */
    --btn-bg: #3b82f6;
    --btn-bg-hover: #60a5fa;
    --btn-text: #ffffff;

    /* Secondary Button */
    --btn-secondary-bg: #374151;
    --btn-secondary-bg-hover: #4b5563;
    --btn-secondary-text: #d1d5db;

    /* Status Colors */
    --success-bg: #064e3b;
    --success-text: #6ee7b7;
    --success-border: #10b981;

    --warning-bg: #422006;
    --warning-text: #fcd34d;
    --warning-border: #92400e;

    --error-bg: #7f1d1d;
    --error-text: #fecaca;
    --error-border: #dc2626;

    --info-bg: #1e3a8a;
    --info-text: #93c5fd;
    --info-border: #3b82f6;

    /* Misc */
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --focus-ring: 0 0 0 3px rgba(96, 165, 250, 0.3);
  }
}

/* Manual: fires when user toggles dark mode via UI */
html.theme-dark {
  /* Surfaces */
  --bg-page: #111827;
  --bg-card: #1f2937;
  --bg-nested: #374151;
  --bg-input: #374151;
  --bg-hover: #374151;

  /* Text */
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-heading: #f3f4f6;

  /* Borders */
  --border: #4b5563;
  --border-strong: #6b7280;
  --border-focus: #60a5fa;

  /* Primary Button */
  --btn-bg: #3b82f6;
  --btn-bg-hover: #60a5fa;
  --btn-text: #ffffff;

  /* Secondary Button */
  --btn-secondary-bg: #374151;
  --btn-secondary-bg-hover: #4b5563;
  --btn-secondary-text: #d1d5db;

  /* Status Colors */
  --success-bg: #064e3b;
  --success-text: #6ee7b7;
  --success-border: #10b981;

  --warning-bg: #422006;
  --warning-text: #fcd34d;
  --warning-border: #92400e;

  --error-bg: #7f1d1d;
  --error-text: #fecaca;
  --error-border: #dc2626;

  --info-bg: #1e3a8a;
  --info-text: #93c5fd;
  --info-border: #3b82f6;

  /* Misc */
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --focus-ring: 0 0 0 3px rgba(96, 165, 250, 0.3);
}

/* Manual: forces light mode (overrides OS dark preference) */
html.theme-light {
  --bg-page: #f3f4f6;
  --bg-card: #ffffff;
  --bg-nested: #f9fafb;
  --bg-input: #ffffff;
  --bg-hover: #f3f4f6;
  --text: #1f2937;
  --text-muted: #6b7280;
  --text-heading: #1f2937;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --border-focus: #3b82f6;
  --btn-bg: #3b82f6;
  --btn-bg-hover: #2563eb;
  --btn-text: #ffffff;
  --btn-secondary-bg: #e5e7eb;
  --btn-secondary-bg-hover: #d1d5db;
  --btn-secondary-text: #374151;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* ===== BASE COMPONENT STYLES ===== */
/* These use the variables, so dark mode works automatically */

.ds-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.ds-nested {
  background: var(--bg-nested);
  border-radius: var(--radius);
  padding: 1rem;
}

.ds-input {
  width: 100%;
  padding: 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
}

.ds-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
}

.ds-input:disabled,
.ds-input:read-only:not(select),
.ds-input[readonly],
input:disabled,
input:read-only,
input[readonly],
textarea:disabled,
textarea:read-only,
textarea[readonly],
select:disabled,
.form-input:disabled,
.form-input:read-only:not(select),
.form-input[readonly] {
  background: var(--bg-nested) !important;
  color: var(--text-muted) !important;
  cursor: not-allowed;
  opacity: 0.8;
  border-color: var(--border) !important;
}

.ds-btn {
  padding: 0.5rem 1rem;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.ds-btn:hover {
  background: var(--btn-bg-hover);
}

.ds-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ds-btn-secondary,
.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
}

.ds-btn-secondary:hover,
.btn-secondary:hover {
  background: var(--btn-secondary-bg-hover);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-success:hover {
  opacity: 0.9;
}

.ds-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.ds-text-muted {
  color: var(--text-muted);
}

.ds-heading {
  color: var(--text-heading);
  margin: 0;
}

/* Status messages */
.ds-status {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.ds-status-success {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.ds-status-error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

.ds-status-warning {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}

.ds-status-info {
  background: var(--info-bg);
  color: var(--info-text);
  border: 1px solid var(--info-border);
}

/* Badge for connected/disconnected status */
.ds-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.ds-badge-success {
  background: var(--success-bg);
  color: var(--success-text);
}

.ds-badge-error {
  background: var(--error-bg);
  color: var(--error-text);
}

/* ===== UTILITY CLASSES ===== */
/* Use these instead of inline styles */

/* Text */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.8rem; }
.text-center { text-align: center; }
.text-mono { font-family: monospace; }
.font-semibold { font-weight: 600; }
.font-normal { font-weight: normal; }

/* Spacing */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.ml-4 { margin-left: 1rem; }
.ml-5 { margin-left: 1.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }

/* Layout */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.grid { display: grid; }
.w-full { width: 100%; }
.hidden { display: none; }

/* Backgrounds & Borders */
.bg-nested { background: var(--bg-nested); }
.bg-card { background: var(--bg-card); }
.border { border: 1px solid var(--border); }
.border-t { border-top: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.rounded { border-radius: var(--radius); }
.rounded-lg { border-radius: var(--radius-lg); }

/* Status backgrounds - notice boxes */
.bg-warning {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}
.bg-info {
  background: var(--info-bg);
  color: var(--info-text);
  border: 1px solid var(--info-border);
}
.bg-success {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}
.bg-error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

/* Cursor */
.cursor-pointer { cursor: pointer; }

/* Checkbox wrapper - prevents flex expansion */
.checkbox-wrap {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

input[type="checkbox"] {
  cursor: pointer;
}

input[type="checkbox"]:disabled {
  cursor: not-allowed;
}

.checkbox-wrap input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

/* Toggle switch - reusable component */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle-switch input {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
}

.toggle-slider {
  width: 36px;
  height: 20px;
  background: var(--border-strong);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--success);
}

.toggle-switch input:checked + .toggle-slider::after {
  transform: translateX(16px);
}

/* Provider status dot */
.config-dot { font-size: 1rem; }
.config-dot.configured { color: var(--success); }
.config-dot.not-configured { color: var(--border-strong); }

/* ===== MODAL STYLES ===== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (prefers-color-scheme: dark) {
  .modal-backdrop {
    background: rgba(0, 0, 0, 0.7);
  }
}

.modal-content {
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-content.invoice-doc {
  max-height: 96vh;
  overflow-y: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-nested);
}

.modal-header h2 {
  margin: 0;
  color: var(--text-heading);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-nested);
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  line-height: 1;
}

.modal-close-btn:hover {
  color: var(--text);
}

@media (max-width: 768px) {
  .modal-close-btn {
    font-size: 2rem;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Invoice/Estimate Modal Specific */
.invoice-table {
  width: 100%;
  border-collapse: collapse;
}

.invoice-table th {
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  text-align: left;
}

.invoice-table th.text-right { text-align: right; }
.invoice-table th.text-center { text-align: center; }

.invoice-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.invoice-table tr:hover {
  background: var(--bg-hover);
}

.invoice-line-item-actions {
  padding: 4px 12px 8px;
  border-bottom: 1px solid var(--border);
}

.invoice-line-item-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  margin-right: 12px;
}

.invoice-line-item-actions .edit-btn { color: var(--info); }
.invoice-line-item-actions .remove-btn { color: var(--error); }

/* Quick picks / Product cards */
.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.product-card:hover {
  border-color: var(--info);
  background: var(--bg-hover);
}

.product-card-name {
  font-weight: 500;
  color: var(--text);
}

.product-card-price {
  color: var(--success);
  font-weight: 600;
}

.product-card-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* Search dropdown */
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
}

.search-dropdown-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.search-dropdown-item:hover {
  background: var(--bg-hover);
}

.search-dropdown-item:last-child {
  border-bottom: none;
}

/* Totals section */
.invoice-totals {
  background: var(--bg-nested);
  border-radius: var(--radius);
  padding: 1rem;
}

.invoice-totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
}

.invoice-totals-row.total {
  border-top: 2px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  font-weight: 600;
  font-size: 1.125rem;
}

/* Invoice Document Modal */
.invoice-doc { display: flex; flex-direction: column; max-height: 96vh; }
.invoice-doc .modal-header { flex-shrink: 0; position: sticky; top: 0; z-index: 10; position: relative; }
.invoice-doc .modal-header > .modal-close-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 11;
}
/* Desktop: show inline actions, hide hamburger */
.inv-header-actions-desktop { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.inv-header-actions-desktop .link-btn,
.inv-header-actions-desktop .btn-gray-solid { font-size: 11px; padding: 0.2rem 0.4rem; white-space: nowrap; }
.inv-header-actions-mobile { display: none; }

/* Mobile hamburger menu */
.inv-header-hamburger {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  font-size: 1.25rem; cursor: pointer; color: var(--text);
  min-width: 36px; min-height: 36px;
  display: flex; align-items: center; justify-content: center;
}
.inv-header-menu {
  position: absolute; top: 100%; right: 0; z-index: 20;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  flex-direction: column; min-width: 160px; padding: 4px 0;
}
.inv-header-menu button {
  background: none; border: none; cursor: pointer; color: var(--text);
  padding: 10px 16px; text-align: left; font-size: 14px; width: 100%;
}
.inv-header-menu button:hover { background: var(--bg-nested); }

@media (max-width: 768px) {
  .inv-header-actions-desktop { display: none; }
  .inv-header-actions-mobile { display: block; }
  .invoice-doc .modal-header > .modal-close-btn {
    right: 0.25rem;
    background: var(--bg-card);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }
  .invoice-modal-document.modal-content.invoice-doc {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0;
    margin: 0;
    min-height: 100vh;
  }
  .invoice-doc .modal-body { padding: 0.75rem; }
  .invoice-doc-header { grid-template-columns: 1fr; gap: 12px; }
  .invoice-bill-to { margin-bottom: 0.5rem; }
}
.invoice-doc .modal-body { flex: 1; overflow-y: auto; }
.invoice-doc .modal-footer { flex-shrink: 0; position: sticky; bottom: 0; }

.invoice-doc-header { display: grid; grid-template-columns: 1fr auto 1fr; gap: 24px; margin-bottom: 24px; }
.invoice-doc-company { font-weight: 600; font-size: 18px; color: var(--text); margin-bottom: 4px; }
.invoice-doc-address { color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.invoice-doc-meta { text-align: right; }
.invoice-doc-meta-row { margin-bottom: 8px; }
.invoice-doc-meta-label { color: var(--text-muted); font-size: 13px; }
.invoice-doc-meta-value { font-weight: 500; margin-left: 8px; }

.invoice-bill-to {
  padding: 0;
}
.invoice-bill-to-label {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.invoice-bill-to-name { font-weight: 500; color: var(--text); margin-bottom: 4px; }
.invoice-bill-to-contact { color: var(--text-muted); font-size: 13px; line-height: 1.5; }

/* Quick Add Drawer */
.invoice-quick-drawer-toggle {
  display: none; /* Hidden on desktop - drawer is always visible */
}
.invoice-quick-drawer {
  position: absolute;
  right: -210px;
  top: 0;
  bottom: 0;
  width: 210px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 8px rgba(0,0,0,0.08);
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 0 8px 8px 0;
}
.invoice-quick-drawer.open { /* No-op on desktop, always visible */ }

/* Mobile: Quick Add Drawer as slide-in panel */
@media (max-width: 1200px) {
  .invoice-quick-drawer {
    display: none; /* Hidden by default on mobile */
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 10001; /* Above invoice modal */
    border-radius: 8px 0 0 8px;
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
  }
  .invoice-quick-drawer.open {
    display: flex;
    transform: translateX(0);
  }
  /* Show toggle button on mobile (#1092 — labeled pill, not bare icon).
     Discoverability: paired ➕ + "Add" label so it reads at a glance.
     Auto-sizes to fit content; minimum 52px height for tap target. */
  .invoice-quick-drawer-toggle {
    display: flex;
    position: fixed;
    right: 12px;
    bottom: 80px;
    min-width: 52px;
    height: 52px;
    padding: 0 18px 0 14px;
    background: var(--btn-bg);
    color: white;
    border: none;
    border-radius: 26px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10002; /* Above modal close button + modal content */
    cursor: pointer;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2px;
  }
  .invoice-quick-drawer-toggle:hover {
    background: var(--btn-bg-hover);
  }
  .invoice-quick-drawer-toggle-icon {
    font-size: 22px;
    line-height: 1;
    font-weight: 400;
  }
  .invoice-quick-drawer-toggle-label {
    font-size: 14px;
  }
  /* Backdrop for mobile drawer */
  .invoice-quick-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 10000;
  }
  .invoice-quick-drawer-backdrop.open {
    display: block;
  }
  /* Close button visible on mobile */
  .invoice-quick-drawer-close {
    display: block !important;
  }
}
.invoice-quick-drawer-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-nested);
  border-radius: 0 8px 0 0;
}
.invoice-quick-drawer-title { font-size: 13px; font-weight: 600; color: var(--text); }
.invoice-quick-drawer-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); padding: 0 4px; }
.invoice-quick-drawer-close:hover { color: var(--text); }
.invoice-quick-drawer-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.invoice-quick-category {
  padding: 8px 12px 5px;
  margin-top: 8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-nested);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.invoice-quick-category:first-child { margin-top: 0; border-top: none; }
.invoice-quick-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border-light, rgba(128,128,128,0.1));
}
.invoice-quick-item:hover { background: var(--bg-hover); }
.invoice-quick-item-name { font-size: 11px; color: var(--text); flex: 1; padding-right: 6px; }
.invoice-quick-item-price { font-size: 11px; font-weight: 500; color: var(--success); white-space: nowrap; }

.invoice-status-badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.invoice-add-row { display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; align-items: center; }
.invoice-search-wrap { position: relative; flex: 1; max-width: 300px; min-width: 150px; }

@media (max-width: 768px) {
  .invoice-bottom-row { flex-wrap: wrap; }
  .invoice-bottom-row .invoice-add-row { width: 100%; flex-basis: 100%; }
  .invoice-bottom-row .invoice-totals { width: 100% !important; }
  .invoice-search-wrap { max-width: none; min-width: 0; width: 100%; flex-basis: 100%; }
}

.link-btn {
  background: none;
  border: none;
  color: var(--info);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.invoice-line-optional { opacity: 0.7; font-style: italic; }
.invoice-line-optional-tag { font-size: 13px; color: var(--warning-text); margin-top: 4px; }

/* Button variants for invoices */
.btn-success-solid {
  background: var(--success);
  color: white;
  border: none;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-success-solid:hover {
  opacity: 0.9;
}

.btn-danger-solid {
  background: var(--error);
  color: white;
  border: none;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-purple-solid {
  background: #8b5cf6;
  color: white;
  border: none;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-gray-solid {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border: none;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-gray-solid:hover {
  background: var(--btn-secondary-bg-hover);
}

/* ===== THEME IDEAS (for future theme customizer) =====
 *
 * Current: "Default" - Blue primary with gray neutrals
 *   --btn-bg: #3b82f6 (blue-500)
 *   --success: #10b981 (emerald-500)
 *   --warning: #f59e0b (amber-500)
 *   --error: #ef4444 (red-500)
 *
 * Theme 2: "Slate Terminal" - From phone system credential display
 *   Nice dark palette, good for a permanently dark or slate theme:
 *   - Backgrounds: #1f2937, #374151, #4b5563 (slate grays)
 *   - Text light: #f9fafb, #9ca3af
 *   - Accent: keep blue or shift to cyan #06b6d4
 *
 * Theme 3: "Forest" - Green primary
 *   --btn-bg: #22c55e (green-500)
 *   --btn-bg-hover: #16a34a (green-600)
 *
 * Theme 4: "Sunset" - Warm orange/amber primary
 *   --btn-bg: #f59e0b (amber-500)
 *   --btn-bg-hover: #d97706 (amber-600)
 *
 * Theme 5: "Purple" - Purple primary
 *   --btn-bg: #8b5cf6 (violet-500)
 *   --btn-bg-hover: #7c3aed (violet-600)
 *
 * Implementation: Add html.theme-xxx classes that override :root variables
 */

/* ===== INLINE SVG ICONS ===== */
/* Ensure inline SVGs scale properly and inherit text color via currentColor */
.inline-svg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.inline-svg svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

/* ===== USER DROPDOWN MENU ===== */
/* Shared styles for admin nav dropdown - wider to prevent text wrapping */
.user-dropdown {
  min-width: 260px !important;
}

.dropdown-item {
  white-space: nowrap;
}

/* ===== TOUCH COMPONENTS ===== */
/* Reusable components for touch-first interfaces (kiosk, mobile check-in, etc.) */
/* All use existing CSS variables — dark mode works automatically. */

/* --- Selection Card --- */
/* Replaces dropdowns in touch contexts. Large tap target, visual feedback, selected state. */
.ds-select-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  min-height: 80px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}

.ds-select-card:hover {
  border-color: var(--border-focus);
  background: var(--bg-hover);
}

.ds-select-card:active {
  transform: scale(0.97);
}

.ds-select-card.selected {
  border-color: var(--border-focus);
  background: var(--info-bg);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.ds-select-card .ds-select-card-icon {
  font-size: 1.75rem;
  line-height: 1;
}

.ds-select-card .ds-select-card-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.ds-select-card .ds-select-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* --- Card Grid --- */
/* Responsive grid for selection cards. Auto-fit columns by screen size. */
.ds-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  width: 100%;
}

.ds-card-grid-2 { grid-template-columns: repeat(2, 1fr); }
.ds-card-grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 480px) {
  .ds-card-grid { grid-template-columns: repeat(2, 1fr); }
  .ds-card-grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* --- Action Card --- */
/* Large clickable card for primary choices (e.g., "New Check-In" / "I Have a Ticket"). */
.ds-action-card {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 80px;
  width: 100%;
}

.ds-action-card:hover {
  border-color: var(--border-focus);
  background: var(--bg-hover);
  box-shadow: var(--shadow);
}

.ds-action-card:active {
  transform: scale(0.98);
}

.ds-action-card .ds-action-icon {
  font-size: 2rem;
  flex-shrink: 0;
  width: 3rem;
  text-align: center;
}

.ds-action-card .ds-action-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.ds-action-card .ds-action-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* --- Step Progress Indicator --- */
/* Horizontal dots/bar showing progress through a multi-step flow. */
.ds-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 0;
}

.ds-step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s, transform 0.2s;
}

.ds-step-dot.completed {
  background: var(--success);
}

.ds-step-dot.active {
  background: var(--border-focus);
  transform: scale(1.3);
}

.ds-step-connector {
  width: 24px;
  height: 2px;
  background: var(--border);
  transition: background 0.2s;
}

.ds-step-connector.completed {
  background: var(--success);
}

/* --- Numpad --- */
/* 3x4 grid of digit buttons for phone/code entry on kiosk/touch. */
.ds-numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  max-width: 320px;
  margin: 0 auto;
}

.ds-numpad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  font-size: 1.25rem;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  color: var(--text);
}

.ds-numpad-btn:hover {
  background: var(--bg-hover);
}

.ds-numpad-btn:active {
  background: var(--bg-nested);
}

.ds-numpad-btn.ds-numpad-backspace {
  font-size: 1.5rem;
  color: var(--text-muted);
}

.ds-numpad-btn.ds-numpad-empty {
  visibility: hidden;
}

/* --- Touch Input (Large) --- */
/* Bigger input fields for touch contexts. Min 48px per WCAG touch target guidelines. */
.ds-input-lg {
  width: 100%;
  padding: 0.75rem 1rem;
  min-height: 48px;
  background: var(--bg-input);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text);
  font-size: 1.125rem;
}

.ds-input-lg:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--focus-ring);
}

.ds-input-lg::placeholder {
  color: var(--text-muted);
}

/* Large phone number display */
.ds-phone-display {
  font-size: 1.75rem;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.05em;
  color: var(--text);
  padding: 0.75rem;
  min-height: 56px;
  background: var(--bg-input);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-lg);
}

/* --- Touch Button (Large) --- */
/* Larger buttons for touch contexts. Min 48px height. */
.ds-btn-lg {
  padding: 0.75rem 1.5rem;
  min-height: 48px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius-lg);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.ds-btn-lg:hover {
  background: var(--btn-bg-hover);
}

.ds-btn-lg:active {
  transform: scale(0.98);
}

.ds-btn-lg:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ds-btn-lg.ds-btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
}

.ds-btn-lg.ds-btn-secondary:hover {
  background: var(--btn-secondary-bg-hover);
}

.ds-btn-lg.ds-btn-success {
  background: var(--success);
  color: #ffffff;
}

.ds-btn-lg.ds-btn-block {
  width: 100%;
}

/* --- Summary List --- */
/* Label-value pairs for review/confirmation screens. */
.ds-summary {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.ds-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.ds-summary-row:last-child {
  border-bottom: none;
}

.ds-summary-label {
  font-size: 0.9375rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 1rem;
}

.ds-summary-value {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  text-align: right;
}

.ds-summary-row.ds-summary-total {
  background: var(--bg-nested);
  font-weight: 600;
}

.ds-summary-row.ds-summary-total .ds-summary-label,
.ds-summary-row.ds-summary-total .ds-summary-value {
  font-size: 1rem;
  color: var(--text);
}

/* --- Step Container --- */
/* For step-based flows. Only the active step is visible. */
.ds-step-section {
  display: none;
}

.ds-step-section.active {
  display: block;
  animation: ds-step-fade-in 0.2s ease-out;
}

@keyframes ds-step-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Touch Fullscreen Layout --- */
/* For kiosk/fullscreen pages. Centers content vertically and horizontally. */
.ds-touch-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  color: var(--text);
}

.ds-touch-header {
  padding: 1rem 1.5rem;
  text-align: center;
  flex-shrink: 0;
}

.ds-touch-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.ds-touch-footer {
  padding: 1rem 1.5rem;
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-shrink: 0;
}

/* --- Consent Checkbox --- */
/* Large checkbox with label text for agreements/consent. Touch-friendly. */
.ds-consent {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-nested);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
}

.ds-consent input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 0.125rem;
  cursor: pointer;
  accent-color: var(--border-focus);
}

.ds-consent-text {
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text);
}

.ds-consent-text a {
  color: var(--info);
  text-decoration: underline;
}

/* Merge ticket overlay — dark-mode-safe */
.merge-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); display: flex; align-items: center;
  justify-content: center; z-index: 10000;
}
.merge-modal {
  background: var(--bg-card); border-radius: 0.5rem;
  max-width: 550px; width: 90%; max-height: 70vh;
  display: flex; flex-direction: column;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  color: var(--text);
}
.merge-header {
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.merge-description {
  padding: 0.75rem 1.25rem; background: var(--bg-nested);
  border-bottom: 1px solid var(--border);
}
.merge-row {
  padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.15s;
}
.merge-row:hover { background: var(--bg-hover); }
.merge-footer {
  padding: 0.75rem 1.25rem; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}
