/* ===== SHARED COMPONENTS ===== */
/* Reusable component library organized by atomic design level:
   Atoms → Molecules → Organisms
   Extracted from base.css and deduplicated from page-specific files. */

/* ────────────── ATOMS: keyframes ────────────── */

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ────────────── ATOMS: buttons ────────────── */

.primary-action-btn {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-strong));
  color: white;
  padding: 0.65rem 1.9rem;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: var(--transition-base);
  border: none;
  box-shadow: 0 4px 12px rgba(81, 157, 144, 0.25);
  text-decoration: none;
  display: inline-block;
  cursor: pointer;
}

.primary-action-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(81, 157, 144, 0.35);
  filter: brightness(1.05);
}

.primary-action-btn:active {
  transform: translateY(0);
}

.secondary-btn {
  background: #f1f5f9;
  color: var(--brand-text-muted);
  padding: 0.65rem 1.6rem;
  border-radius: 10px;
  font-weight: 500;
  border: 1px solid rgba(15, 23, 42, 0.08);
  transition: var(--transition-base);
  text-decoration: none;
  display: inline-block;
  cursor: pointer;
}

.secondary-btn:hover {
  background: #e2e8f0;
  color: var(--brand-primary-strong);
  border-color: rgba(81, 157, 144, 0.25);
}

.secondary-btn:active {
  transform: translateY(0);
}

.destructive-btn {
  background: rgba(220, 38, 38, 0.08);
  color: #b91c1c;
  border: 1px solid rgba(220, 38, 38, 0.3);
  padding: 0.65rem 1.6rem;
  border-radius: 999px;
  font-weight: 600;
  transition: var(--transition-slow);
  text-decoration: none;
  display: inline-block;
  cursor: pointer;
  box-shadow: none;
}

.destructive-btn:hover {
  background: rgba(220, 38, 38, 0.15);
  border-color: rgba(220, 38, 38, 0.5);
  color: #991b1b;
}

.destructive-btn:active {
  background: rgba(220, 38, 38, 0.2);
}

.destructive-btn-sm {
  padding: 0.4rem 0.8rem;
  font-weight: 500;
  font-size: 0.875rem;
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: #b91c1c;
  border-radius: 0.5rem;
  transition: var(--transition-base);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: none;
}

.destructive-btn-sm:hover {
  background: rgba(220, 38, 38, 0.15);
  border-color: rgba(220, 38, 38, 0.5);
  color: #991b1b;
}

.ui-pager-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #334155;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 0.25rem;
  transition: var(--transition-base);
}

.ui-pager-btn:hover {
  background: #f1f5f9;
}

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

.ui-btn-primary-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #ffffff;
  background: var(--brand-primary);
  border-radius: 0.5rem;
  transition: var(--transition-base);
}

.ui-btn-primary-sm:hover {
  background: var(--brand-primary-strong);
}

.ui-btn-secondary-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
  background: #f1f5f9;
  border-radius: 0.5rem;
  transition: var(--transition-base);
}

.ui-btn-secondary-sm:hover {
  background: #e2e8f0;
}

.ui-btn-danger-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #ffffff;
  background: #dc2626;
  border-radius: 0.5rem;
  transition: var(--transition-base);
}

.ui-btn-danger-sm:hover {
  background: #b91c1c;
}

.add-rule-btn {
  padding: 0.4rem 0.9rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fbbf24;
  border-radius: 0.5rem;
  transition: var(--transition-base);
  cursor: pointer;
}

.add-rule-btn:hover {
  background: #fde68a;
  border-color: #f59e0b;
  color: #78350f;
}

/* ────────────── ATOMS: preset bar ────────────── */

.preset-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(241, 245, 249, 0.6);
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 0.75rem;
}

.preset-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  transition: all 0.2s ease;
  text-decoration: none;
  cursor: pointer;
}

.preset-btn:hover {
  color: #0f172a;
  border-color: #94a3b8;
  background: #f8fafc;
}

.preset-btn--active {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-strong));
  color: #ffffff;
  border-color: var(--brand-primary-strong);
}

.preset-btn--active:hover {
  background: linear-gradient(135deg, var(--brand-primary-strong), var(--brand-primary));
  color: #ffffff;
  border-color: var(--brand-primary-strong);
}

/* ────────────── ORGANISMS: unified filter panel ────────────── */

.filter-panel {
  padding: 1.25rem 1.5rem;
}

.filter-panel__presets {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-panel__label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  white-space: nowrap;
}

.filter-panel__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 0.85rem;
  min-height: 2.25rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  text-decoration: none;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.preset-chip:hover {
  color: #0f172a;
  border-color: #94a3b8;
  background: #e2e8f0;
}

.preset-chip--active {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-strong));
  color: #ffffff;
  border-color: var(--brand-primary-strong);
}

.preset-chip--active:hover {
  background: linear-gradient(135deg, var(--brand-primary-strong), var(--brand-primary));
  color: #ffffff;
}

.filter-panel__separator {
  border-top: 1px solid #e2e8f0;
  margin: 0.75rem 0;
}

.filter-panel__form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.filter-panel__dropdowns {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.filter-panel__field {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.filter-panel__field label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
  margin-bottom: 0.35rem;
}

.filter-panel__field .modern-select {
  width: 100%;
}

.filter-panel__actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: center;
}

@media (max-width: 768px) {
  .filter-panel {
    padding: 1rem;
  }

  .filter-panel__dropdowns {
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }

  .filter-panel__form {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-panel__actions {
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  .filter-panel {
    padding: 0.75rem;
  }

  .filter-panel__presets {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .filter-panel__dropdowns {
    grid-template-columns: 1fr;
    width: 100%;
    overflow: hidden;
  }

  .filter-panel__separator {
    margin: 0.5rem 0;
  }

  .preset-chip {
    font-size: 0.72rem;
    padding: 0.4rem 0.7rem;
  }
}

/* ────────────── ATOMS: form fields ────────────── */

.form-field label {
  display: block;
  font-weight: 600;
  color: var(--brand-text-muted);
  margin-bottom: 0.35rem;
  font-size: 0.95rem;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--brand-border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.92);
  transition: var(--transition-base);
  font-size: 0.875rem;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: rgba(81, 157, 144, 0.5);
  box-shadow: 0 0 0 4px rgba(81, 157, 144, 0.1);
}

.form-field ul.errorlist {
  list-style: none;
  padding: 0.55rem 0.75rem;
  margin: 0.35rem 0 0 0;
  background: rgba(248, 113, 113, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #7f1d1d;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

.form-field ul.errorlist li {
  color: #7f1d1d;
  font-size: 0.85rem;
  margin: 0;
}

.modern-select {
  border-radius: 0.5rem;
  border: 2px solid #e5e7eb;
  transition: all 0.2s ease;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #0f172a;
  background-color: #ffffff;
  box-sizing: border-box;
  max-width: 100%;
  min-width: 0;
}

.modern-select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(81, 157, 144, 0.1);
}

.form-control {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #0f172a;
  background-color: #ffffff;
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 2px rgba(81, 157, 144, 0.2);
}

.form-control[readonly] {
  background-color: #f8fafc;
  color: #64748b;
}

@media (max-width: 768px) {
  .form-control {
    font-size: 1rem;
  }
}

/* ────────────── ATOMS: help text ────────────── */

.help-text {
  font-size: 0.875rem;
  color: #6b7280;
  margin-top: 0.5rem;
  line-height: 1.5;
}

.help-text ul {
  list-style: disc;
  margin-left: 1.25rem;
  margin-top: 0.5rem;
}

/* ────────────── ATOMS: spinner / loading ────────────── */

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--brand-secondary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loading-overlay-gradient {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(34, 166, 153, 0.85));
  backdrop-filter: blur(10px);
}

/* ────────────── MOLECULES: gradient-bg (auth / standalone pages) ────────────── */

.gradient-bg {
  background: linear-gradient(135deg, #0f766e 0%, #0d9488 25%, #14b8a6 50%, #2dd4bf 75%, #5eead4 100%);
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.gradient-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 50%, rgba(45, 212, 191, 0.25) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(13, 148, 136, 0.2) 0%, transparent 50%),
    radial-gradient(circle at 40% 20%, rgba(20, 184, 166, 0.15) 0%, transparent 50%);
  pointer-events: none;
}

.gradient-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 15% 30%, rgba(255, 255, 255, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 70%, rgba(255, 255, 255, 0.05) 0%, transparent 40%);
  pointer-events: none;
}

/* ────────────── MOLECULES: glass-card (login, logout, db_waking_up) ────────────── */

.glass-card {
  backdrop-filter: blur(25px);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.25);
  animation: slide-up 0.6s ease-out;
}

/* ────────────── MOLECULES: alert-banner ────────────── */

.alert-banner {
  background: #fee2e2;
  border-left: 4px solid #dc2626;
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1.5rem;
  color: #991b1b;
}

.alert-banner h3 {
  color: #991b1b;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

/* ────────────── MOLECULES: modern-card ────────────── */

.modern-card {
  background: var(--brand-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--brand-border);
  padding: 1.5rem;
}

.modern-card--flush {
  padding: 0;
  overflow: hidden;
}

.modern-card--soft {
  background: #f8fafc;
  border-color: rgba(148, 163, 184, 0.35);
}

.modern-card-head {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

.modern-card-head--plain {
  background: #ffffff;
}

.modern-card-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.modern-card-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
  color: #0f172a;
}

.modern-card-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: #64748b;
}

.modern-card-body {
  padding: 1.5rem;
}

/* ────────────── ORGANISMS: page-header ────────────── */

.page-header {
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-left: 4px solid var(--header-accent, var(--brand-primary));
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.page-header-content {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.page-header-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--header-accent-soft, rgba(81, 157, 144, 0.18));
  border: 1px solid var(--header-accent-border, rgba(15, 23, 42, 0.1));
  color: var(--header-accent, var(--brand-primary));
}

.page-header-icon svg {
  width: 20px;
  height: 20px;
}

.page-header-text h1 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
  color: var(--header-title, var(--brand-text));
}

.page-header-text p {
  font-size: 0.8125rem;
  margin: 0.125rem 0 0 0;
  color: var(--header-subtitle, var(--brand-text-muted));
}

/* Sales section - Teal */
.page-header--sales {
  --header-accent: var(--brand-primary);
  --header-accent-soft: rgba(81, 157, 144, 0.14);
  --header-accent-border: rgba(81, 157, 144, 0.25);
  --header-title: #0f3d35;
  --header-subtitle: #3b8f82;
}

/* Team section - Blue */
.page-header--team {
  --header-accent: #2563eb;
  --header-accent-soft: rgba(37, 99, 235, 0.14);
  --header-accent-border: rgba(37, 99, 235, 0.25);
  --header-title: #1e3a8a;
  --header-subtitle: #3b82f6;
}

/* Settings section - Gray */
.page-header--settings {
  --header-accent: #475569;
  --header-accent-soft: rgba(71, 85, 105, 0.14);
  --header-accent-border: rgba(71, 85, 105, 0.22);
  --header-title: #1e293b;
  --header-subtitle: #64748b;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .modern-card-head {
    padding: 0.9rem 1rem;
  }

  .modern-card-title {
    font-size: 1rem;
  }

  .modern-card-subtitle {
    font-size: 0.75rem;
  }

  .modern-card-body {
    padding: 1rem;
  }

  .page-header {
    padding: 1rem 1.25rem;
    flex-direction: column;
    align-items: flex-start;
  }
  .page-header-icon {
    width: 38px;
    height: 38px;
  }
  .page-header-icon svg {
    width: 18px;
    height: 18px;
  }
  .page-header-text h1 {
    font-size: 1rem;
  }
  .page-header-text p {
    font-size: 0.75rem;
  }
  .page-header-actions {
    width: 100%;
    justify-content: flex-start;
    margin-top: 0.5rem;
  }
  .page-header-actions .primary-action-btn,
  .page-header-actions .secondary-btn {
    padding: 0.45rem 0.85rem;
    font-size: 0.8rem;
  }
}

/* ────────────── ORGANISMS: section-header ────────────── */

.section-header {
  margin-bottom: 1.5rem;
  padding: 0.85rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-left: 3px solid var(--brand-primary);
  background: #ffffff;
  display: grid;
  gap: 0.35rem;
}

.section-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
  letter-spacing: -0.01em;
}

.section-header p {
  font-size: 0.85rem;
  color: #64748b;
  margin: 0;
}

/* Analytics Section */
.analytics-section {
  background: rgba(59, 130, 246, 0.02);
  padding: 1.5rem;
  border-radius: 0.75rem;
  margin-bottom: 2rem;
  border: 1px solid rgba(59, 130, 246, 0.1);
}

.charts-container {
  display: grid;
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .analytics-section {
    padding: 1rem;
    border-radius: 0.5rem;
  }

  .section-header h2 {
    font-size: 1.05rem;
  }

  .section-header p {
    font-size: 0.78rem;
  }
}

/* ────────────── ORGANISMS: modernized table system ────────────── */

/* The Shell: provides rounding, border, and scroll handling */
.table-shell {
  position: relative;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.table-shell--scrollable {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* The Table Base */
.base-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  font-size: 0.8125rem;
}

/* UX Modifier: Do not stretch small tables to full width */
.base-table--fit {
  width: auto;
  min-width: min-content;
}

/* Headers */
.base-table thead th {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
  transition: background-color 0.2s ease;
}

/* Sticky Header Modifier */
.base-table--sticky-header thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: inset 0 -1px 0 #e2e8f0;
}

/* Body Cells */
.base-table tbody td {
  padding: 0.875rem 1rem;
  color: #334155;
  vertical-align: middle;
}

/* Alignment Helpers (Forced for consistency) */
.base-table th.text-right,
.base-table td.text-right {
  text-align: right !important;
}

.base-table th.text-center,
.base-table td.text-center {
  text-align: center !important;
}

/* Hover Effect */
.base-table tbody tr {
  transition: background-color 0.15s ease;
}

.base-table tbody tr:hover {
  background-color: #f0f4f8;
}

/* Footer / Subtotals */
.base-table tfoot td {
  padding: 0.875rem 1rem;
  background-color: #f8fafc;
  font-weight: 700;
  color: #0f172a;
  border-top: 2px solid #e2e8f0;
}

/* ────────────── ATOMS: table pills & indicators ────────────── */

.table-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid #dbe2ea;
  background: #f8fafc;
  color: #475569;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.16rem 0.52rem;
  white-space: nowrap;
}

.table-pill--success {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.1);
  color: #15803d;
}

.table-pill--danger {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

.table-pill--icon {
  min-width: 1.55rem;
  height: 1.55rem;
  padding: 0;
  font-size: 0.74rem;
  font-weight: 700;
}

.table-note {
  display: inline-block;
  border-radius: 0.42rem;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  font-size: 0.68rem;
  font-weight: 500;
  line-height: 1.3;
  padding: 0.22rem 0.48rem;
}

/* ────────────── SCHEMA OVERRIDES ────────────── */
/* Design: Option 2 "Header spectrum" — color in headers, tinted subtotals, clean body */

/* Tours — #7186a5 blue-grey */
.base-table th.col-tours       { background-color: rgba(113, 134, 165, 0.09); color: #3f5571; border-bottom: none; }
.base-table th.col-tours-total { background-color: rgba(113, 134, 165, 0.18); color: #3f5571; border-bottom: none; }
.base-table td.col-tours-total { background-color: rgba(113, 134, 165, 0.18); color: #3f5571; font-weight: 700; }

/* Sales — #ffa17a coral */
.base-table th.col-sales       { background-color: rgba(255, 161, 122, 0.09); color: #7a3e1c; border-bottom: none; }
.base-table th.col-sales-total { background-color: rgba(255, 161, 122, 0.18); color: #7a3e1c; border-bottom: none; }
.base-table td.col-sales-total { background-color: rgba(255, 161, 122, 0.18); color: #7a3e1c; font-weight: 700; }

/* Commission — #344b46 dark-green */
.base-table th.col-comm        { background-color: rgba(52, 75, 70, 0.09); color: #1e3630; border-bottom: none; }
.base-table th.col-comm-total  { background-color: rgba(52, 75, 70, 0.18); color: #1e3630; border-bottom: none; }
.base-table td.col-comm-total  { background-color: rgba(52, 75, 70, 0.18); color: #1e3630; font-weight: 700; }

/* Tfoot — slightly stronger tint */
.base-table tfoot td.col-tours-total { background-color: rgba(113, 134, 165, 0.24); }
.base-table tfoot td.col-sales-total { background-color: rgba(255, 161, 122, 0.24); }
.base-table tfoot td.col-comm-total  { background-color: rgba(52, 75, 70, 0.24); }

/* Hover — total cols hold their tint */
.base-table tbody tr:hover td.col-tours-total { background-color: rgba(113, 134, 165, 0.22); }
.base-table tbody tr:hover td.col-sales-total { background-color: rgba(255, 161, 122, 0.22); }
.base-table tbody tr:hover td.col-comm-total  { background-color: rgba(52, 75, 70, 0.22); }

/* Compact Modifier */
.base-table--dense thead th { padding: 0.5rem 0.75rem; }
.base-table--dense tbody td { padding: 0.5rem 0.75rem; font-size: 0.75rem; }
.base-table--dense tfoot td { padding: 0.5rem 0.75rem; font-size: 0.75rem; }

/* ────────────── ORGANISMS: ui-modal ────────────── */

.ui-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.5);
  overflow-y: auto;
}

.ui-modal-panel {
  width: 100%;
  max-width: 28rem;
  max-height: calc(100svh - 2rem);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
  border-radius: 0.5rem;
  box-shadow: 0 20px 25px -5px rgba(15, 23, 42, 0.2), 0 8px 10px -6px rgba(15, 23, 42, 0.15);
  flex-shrink: 0;
  margin-top: auto;
  margin-bottom: auto;
}

.ui-modal-panel-lg {
  max-width: 32rem;
}

.ui-modal-panel-xl {
  max-width: 42rem;
}

@media (max-width: 480px) {
  .ui-modal {
    padding: 0.75rem;
    align-items: flex-start;
  }

  .ui-modal-panel,
  .ui-modal-panel-lg,
  .ui-modal-panel-xl {
    max-width: calc(100vw - 1.5rem);
    max-height: calc(100vh - 1.5rem);
    max-height: calc(100svh - 1.5rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
  }

  .ui-modal-body {
    overflow-y: auto;
    flex: 1;
  }

  .ui-modal-header,
  .ui-modal-body,
  .ui-modal-footer {
    padding: 0.75rem 1rem;
  }
}

.ui-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.ui-modal-body {
  padding: 1rem 1.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.ui-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.ui-modal-close {
  color: #94a3b8;
  transition: var(--transition-base);
}

.ui-modal-close:hover {
  color: #475569;
}

.role-toggle-btn {
  flex: 1;
  padding: 0.4rem 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  background: #ffffff;
  color: #475569;
  line-height: 1.4;
}
.role-toggle-btn:not(:first-child) {
  border-left: 1px solid #e2e8f0;
}
.role-toggle-btn[data-active="true"] {
  background: var(--brand-primary);
  color: #ffffff;
}
.role-toggle-btn[data-active="false"]:hover {
  background: #f8fafc;
}

.modal-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: #64748b;
  margin-bottom: 0.25rem;
  letter-spacing: 0.01em;
}

/* ────────────── RESPONSIVE: global component overrides ────────────── */

@media (max-width: 768px) {
  .modern-card {
    padding: 1.5rem !important;
  }

  .base-table {
    font-size: 0.85rem;
  }

  .base-table thead th,
  .base-table tbody td,
  .base-table tfoot td {
    padding: 0.62rem 0.74rem;
    font-size: 0.8rem;
  }

  .base-table--dense thead th,
  .base-table--dense tbody td,
  .base-table--dense tfoot td {
    padding: 0.42rem 0.52rem;
    font-size: 0.68rem;
  }

  .modern-select {
    font-size: 0.85rem;
  }

  .primary-action-btn,
  .destructive-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) {
  .modern-card {
    padding: 1rem !important;
  }

  .base-table thead th,
  .base-table tbody td,
  .base-table tfoot td {
    padding: 0.5rem 0.58rem;
    font-size: 0.7rem;
  }

  .base-table--dense thead th,
  .base-table--dense tbody td,
  .base-table--dense tfoot td {
    padding: 0.36rem 0.45rem;
    font-size: 0.65rem;
  }

  h2 {
    font-size: 1.3rem !important;
  }

  .primary-action-btn {
    /* Keep intrinsic width on mobile — no full-width stretch */
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .modern-card {
    padding: 2rem;
  }

  h2 {
    font-size: 1.3rem;
  }
}

@media (max-width: 768px) {
  .modern-card.p-6 {
    padding: 1.5rem !important;
  }
}

/* Hide date columns on mobile for user table */
@media (max-width: 640px) {
  .user-table-date-col { display: none; }

  .settings-user-table .table-pill {
    font-size: 0.65rem;
    padding: 0.125rem 0.375rem;
  }
}

/* ────────────── RESPONSIVE: Plotly charts on all pages ────────────── */
@media (max-width: 768px) {
  .charts-container {
    gap: 1rem;
  }

  .analytics-section {
    padding: 0.75rem;
  }
}

@media (max-width: 480px) {
  .page-header-content {
    gap: 0.5rem;
  }

  .page-header-text p {
    display: none;
  }

  .analytics-section {
    padding: 0.5rem;
    margin-bottom: 1rem;
  }

  .section-header {
    padding: 0.6rem 0.75rem;
    margin-bottom: 1rem;
  }

  .section-header h2 {
    font-size: 0.95rem;
  }
}

/* ────────────── ORGANISMS: records table (shared) ────────────── */

.records-card {
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 20px 55px -35px rgba(15, 23, 42, 0.4);
}

.records-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.records-tools {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.records-pagination-info {
  display: inline-flex;
  align-items: center;
  border: 1px solid #dbeafe;
  background: #f8fafc;
  color: #334155;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.records-page-size-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
}

.records-page-size-select {
  min-width: 4rem;
  border-radius: 0.55rem;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1e293b;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.55rem;
  transition: all 0.2s ease;
}

.records-page-size-select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(81, 157, 144, 0.15);
}

/* Table visuals are defined in the shared table system above. */

/* Sortable headers */
.base-table th[data-sort] {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}

.base-table th[data-sort]:hover {
  color: #344b46;
}

.base-table th[data-sort]::after {
  content: " ↕";
  opacity: 0.25;
  font-size: 0.55rem;
}

.base-table th[data-sort].sort-asc::after {
  content: " ▲";
  opacity: 0.7;
  color: #5c8e84;
}

.base-table th[data-sort].sort-desc::after {
  content: " ▼";
  opacity: 0.7;
  color: #5c8e84;
}

.table-icon-btn {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  border: 1px solid #dbe2ea;
  background: #ffffff;
  color: #94a3b8;
  transition: all 0.2s ease;
}

.table-icon-btn:hover {
  color: #334155;
  border-color: #cbd5e1;
  background: #f8fafc;
}

.table-icon-btn-danger:hover {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}

.records-pagination-wrap {
  margin-top: 1rem;
  padding: 0.85rem 0.9rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.85rem;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.records-pagination {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.records-page-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  font-size: 0.74rem;
  font-weight: 600;
  border-radius: 0.55rem;
  padding: 0.34rem 0.7rem;
  transition: all 0.2s ease;
}

.records-page-btn:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #94a3b8;
}

.records-page-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.records-page-list {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.records-page-number {
  min-width: 1.85rem;
  height: 1.85rem;
  border-radius: 0.55rem;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  font-size: 0.74rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.records-page-number:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.records-page-number.is-active {
  background: linear-gradient(
    135deg,
    var(--brand-primary),
    var(--brand-primary-strong)
  );
  border-color: var(--brand-primary-strong);
  color: #ffffff;
}

.records-page-ellipsis {
  color: #64748b;
  font-size: 0.78rem;
  padding: 0 0.2rem;
}

.records-page-info {
  color: #475569;
  font-size: 0.78rem;
  font-weight: 600;
}

/* Records table responsive */
@media (max-width: 768px) {
  .records-top {
    align-items: stretch;
  }

  .records-tools {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .records-pagination-wrap {
    flex-direction: column;
    align-items: stretch;
  }

  .records-pagination {
    justify-content: space-between;
  }

  .records-table {
    min-width: 400px;
  }

  .records-card {
    padding: 1rem !important;
  }
}

@media (max-width: 480px) {
  .records-table {
    min-width: 320px;
  }

  .table-icon-btn {
    width: 1.875rem;
    height: 1.875rem;
  }

  .records-page-btn {
    padding: 0.38rem 0.62rem;
  }

  .records-page-list {
    justify-content: center;
    width: 100%;
  }

  .records-pagination {
    width: 100%;
  }

  .records-page-info {
    text-align: center;
    width: 100%;
  }
}

/* ────────────── ATOMS: commission column accents (palette sage) ────────────── */

.comm-text { color: #5c8e84; }
.comm-text-dark { color: #344b46; }
.comm-bg { background-color: rgba(92, 142, 132, 0.08); }
.comm-bg-light { background-color: rgba(92, 142, 132, 0.04); }
.comm-header { background-color: #5c8e84; color: #ffffff; }
.comm-header-soft { background-color: rgba(92, 142, 132, 0.85); color: #ffffff; }
.comm-muted { color: rgba(92, 142, 132, 0.5); }
.comm-muted-light { color: rgba(92, 142, 132, 0.35); }

/* ────────────── MOLECULES: kpi-card ────────────── */

.kpi-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--kpi-accent, var(--brand-primary));
}

.kpi-card__label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  margin: 0;
}

.kpi-card__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--kpi-accent, var(--brand-primary));
  margin: 0.25rem 0 0;
  line-height: 1.2;
}

.kpi-card__unit {
  font-size: 0.68rem;
  color: #94a3b8;
  margin: 0.125rem 0 0;
}

@media (max-width: 640px) {
  .kpi-card {
    padding: 0.75rem 1rem;
  }

  .kpi-card__value {
    font-size: 1.25rem;
  }
}
