/* ═══════════════════════════════════════════════════════
   BITEL Commission Calculator — Premium Dark Theme
   ═══════════════════════════════════════════════════════ */

/* ─── CSS Variables ─── */
:root {
  --bg-primary: #f0f4f8;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #f4f7fb;
  --bg-tertiary: #eef2f8;
  --bg-header: #eef2f8;
  --bg-header-hover: #dce6f2;
  --bg-group-row: #e8eef6;
  --bg-frozen-even: #f8fbfc;
  --border: #dde4ee;
  --border-strong: #c8d4e4;
  --border-row: #eef2f7;
  --success-bg: #f0fdf4;
  --success-dark: #166534;
  --success-text: #15803d;
  --warning-dark: #d97706;
  --warning-darker: #92400e;
  --danger-dark: #C00000;
  --border-hover: #b0c4d8;
  --text-primary: #1a2942;
  --text-secondary: #4e6080;
  --text-muted: #8898aa;
  --accent: #0d6e6e;
  --accent-light: #0f8585;
  --accent-dark: #0a5555;
  --navy: #0D4A9A;
  --navy-light: #1A5CB0;
  --gold: #FFE600;
  --gradient: linear-gradient(135deg, #0D4A9A, #0d6e6e);
  --gradient-subtle: linear-gradient(135deg, rgba(27,54,96,0.07), rgba(13,110,110,0.07));
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 10px;
  --shadow: 0 2px 16px rgba(27,54,96,0.10);
  --shadow-glow: 0 4px 20px rgba(13,110,110,0.14);
  --transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* non-standard 15px root — intentional, all rem values calibrated to this */
html { font-size: 15px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(27,54,96,0.05) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(13,110,110,0.04) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ─── Layout ─── */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ─── Header ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--navy);
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: 0 4px 20px rgba(27,54,96,0.25);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo {
  width: 42px;
  height: 42px;
  background: var(--gold);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 16px rgba(232,181,0,0.4);
}

.header-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffffff;
}

.header-subtitle {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.6);
  font-weight: 400;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

.quarter-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.12);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.2);
}

.quarter-selector select,
.quarter-selector input {
  background: transparent;
  border: none;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

.quarter-selector select option {
  background: var(--navy);
  color: #ffffff;
}

.quarter-selector input[type="number"] {
  width: 60px;
  text-align: center;
}

/* ─── Tab Navigation ─── */
.tab-nav {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 4px;
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab-btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tab-btn:hover {
  color: var(--navy);
  background: rgba(27,54,96,0.07);
}

.tab-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tab-btn.active {
  background: var(--navy);
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 12px rgba(27,54,96,0.25);
}


/* ─── Tab Content ─── */
.tab-content {
  display: none;
  animation: fadeIn 0.15s ease;
}

.tab-content.active { display: block; }

/* ─── Cards ─── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  backdrop-filter: blur(12px);
  transition: var(--transition);
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-glow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-header);
  padding: 10px 16px;
  margin: -16px -16px 12px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title .icon {
  font-size: 1.2em;
}

/* ─── Status Cards Grid ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 6px rgba(27,54,96,0.07);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gradient);
  opacity: 0;
  transition: var(--transition);
}

.stat-card:hover::before { opacity: 1; }

.stat-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.stat-card.ready .stat-value { color: var(--navy) !important; -webkit-text-fill-color: var(--navy) !important; }

.stat-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.stat-card.warning .stat-value { color: var(--warning) !important; -webkit-text-fill-color: var(--warning) !important; }
.stat-card.danger .stat-value { color: var(--danger) !important; -webkit-text-fill-color: var(--danger) !important; }

/* ─── Upload Zone ─── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 30px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.upload-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gradient-subtle);
  opacity: 0;
  transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(13,110,110,0.04);
}

.upload-zone:hover::before,
.upload-zone.dragover::before { opacity: 1; }

.upload-zone .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: block;
}

.upload-zone .label {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
  position: relative;
  z-index: 1;
}

.upload-zone .sublabel {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 6px;
  position: relative;
  z-index: 1;
}

.upload-zone input[type="file"] {
  display: none;
}

.upload-status {
  margin-top: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  display: none;
}

.upload-status.success {
  display: block;
  background: rgba(16,185,129,0.1);
  border: 1px solid rgba(16,185,129,0.3);
  color: var(--success);
}

.upload-status.error {
  display: block;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger);
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 12px rgba(13,110,110,0.3);
}

.btn-primary:hover {
  background: var(--accent-light);
  box-shadow: 0 4px 20px rgba(13,110,110,0.4);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
}

.btn-danger:hover {
  background: rgba(239,68,68,0.25);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 14px 32px;
  font-size: 1rem;
}

.btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ─── Report scroll areas (enable sticky headers) ─── */
.report-scroll-area {
  max-height: 620px;
  overflow-y: auto;
  overflow-x: auto;
  border-radius: var(--radius);
}

.report-scroll-wide {
  overflow-x: auto;
}

/* ─── Tables ─── */
.table-container {
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  padding: 11px 16px;
  text-align: left;
  font-weight: 700;
  color: var(--navy);
  background: var(--bg-header);
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.7px;
}

tbody td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-row);
  color: var(--text-primary);
}

tbody tr:hover {
  background: rgba(13,110,110,0.05);
}

tbody tr:nth-child(even) {
  background: rgba(27,54,96,0.03);
}

tbody tr.subtotal {
  background: rgba(27,54,96,0.07) !important;
  font-weight: 600;
}

tbody tr.grand-total {
  background: rgba(27,54,96,0.11) !important;
  font-weight: 700;
  font-size: 0.95rem;
}

thead tr.totals-row td {
  background: var(--bg-group-row) !important;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 8px 16px;
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--border);
  color: var(--text-primary);
  position: sticky;
  top: 39px;
  z-index: 1;
}

td.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ─── Policy Editor ─── */
.policy-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.policy-tab {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.policy-tab:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.policy-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.rate-input {
  width: 72px;
  padding: 4px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  text-align: center;
  transition: var(--transition);
}

.rate-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(13,110,110,0.18);
}

.rate-input.invalid {
  border-color: var(--danger);
  background: rgba(239,68,68,0.1);
}

.rate-sum {
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 4px;
}

.rate-sum.valid { color: var(--success); background: rgba(16,185,129,0.1); }
.rate-sum.invalid { color: var(--danger); background: rgba(239,68,68,0.1); }

/* ─── Forms ─── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.92rem;
  transition: var(--transition);
}

.form-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(13,110,110,0.18);
}

/* ─── Toasts / Notifications ─── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  animation: slideInRight 0.4s ease;
  backdrop-filter: blur(12px);
  max-width: 400px;
  box-shadow: var(--shadow);
}

.toast.success {
  background: rgba(16,185,129,0.15);
  border: 1px solid rgba(16,185,129,0.3);
  color: var(--success);
}

.toast.error {
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger);
}

.toast.info {
  background: rgba(13,110,110,0.12);
  border: 1px solid rgba(13,110,110,0.28);
  color: var(--accent);
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(100px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Loading ─── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,8,13,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  backdrop-filter: blur(4px);
}

.loading-overlay.hidden { display: none; }

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Insight Panel (Dashboard Charts) ─── */
.insight-panel {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 14px;
  align-items: stretch;
  margin-bottom: 0;
}
.insight-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 14px 16px 14px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
}
.insight-card-title { font-size: 12.5px; font-weight: 700; color: var(--navy); }
.insight-card-sub   { font-size: 11px; color: var(--text-muted); margin-top: 2px; margin-bottom: 12px; }
.insight-area-wrap  { position: relative; flex: 1; min-height: 60px; }
.insight-bar-wrap   { position: relative; flex: 1; min-height: 60px; }
.insight-bar-legend {
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  margin-top: 6px; padding-top: 5px;
  border-top: 1px solid var(--border);
  min-height: 32px; align-content: flex-start;
}
.insight-bar-legend span {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px; color: var(--text-muted); white-space: nowrap;
}
.insight-bar-legend i {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 2px; flex-shrink: 0; box-sizing: border-box;
}
.insight-donut-body {
  display: flex; flex-direction: column; align-items: center; flex: 1;
  justify-content: center; gap: 12px;
}
.insight-donut-wrap { position: relative; width: 145px; height: 145px; flex-shrink: 0; }
.insight-dc {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  text-align: center; pointer-events: none; width: 80px;
}
.insight-dc-val { font-size: 15px; font-weight: 800; color: var(--text-primary); line-height: 1.2; }
.insight-dc-lbl { font-size: 9px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.insight-donut-legend {
  display: flex; flex-direction: row; gap: 6px;
  width: 100%; justify-content: space-between; align-self: flex-end;
}
.dl-row {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 5px 8px; border-radius: 6px; flex: 1;
  background: var(--bg-card-hover); border: 1px solid #f1f5f9; text-align: center;
}
.dl-top { display: flex; align-items: center; gap: 5px; }
.dl-dot { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.dl-lbl { color: var(--text-secondary); font-size: 10px; font-weight: 500; }
.dl-pct { font-weight: 800; font-size: 13px; line-height: 1.2; }
.dl-val { color: var(--text-muted); font-size: 10.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
.insight-year-sel {
  appearance: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 22px 3px 8px; font-size: 11.5px; font-weight: 700;
  color: var(--navy); background: var(--bg-input);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center; cursor: pointer;
}
.insight-ann-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.insight-ann-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5.5px 0; border-bottom: 1px solid var(--border);
}
.insight-ann-row:last-child { border-bottom: none; }
.insight-ann-metric { color: var(--text-secondary); font-size: 11.5px; }
.insight-ann-value  { font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.insight-ann-row.red   .insight-ann-value { color: var(--danger-dark); }
.insight-ann-row.amber .insight-ann-value { color: var(--warning-dark); }
.insight-ann-row.highlight {
  background: var(--success-bg); border-radius: 7px;
  padding: 7px 8px; margin: 5px -6px 0; border: none;
}
.insight-ann-row.highlight .insight-ann-metric { color: var(--success-dark); font-weight: 600; font-size: 12px; }
.insight-ann-row.highlight .insight-ann-value  { color: var(--success-text); font-size: 13px; font-weight: 800; }
.insight-ann-divider { border: none; border-top: 2px solid var(--border); margin: 6px 0; }
.insight-q-badges { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.insight-q-badge  { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 4px; }
.insight-q-done    { background: #dcfce7; color: #166634; }
.insight-q-pending { background: #fef3c7; color: #92400e; }

/* ─── Dashboard Specific ─── */
.action-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.action-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.action-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow), var(--shadow-glow);
}

.action-card .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.action-card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.action-card p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ─── Results Preview ─── */
.result-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.result-tab {
  padding: 8px 18px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: var(--transition);
}

.result-tab:hover { border-color: var(--accent); color: var(--text-primary); }
.result-tab.active { background: var(--accent); border-color: var(--accent); color: white; }

.result-panel { display: none; }
.result-panel.active { display: block; }

/* ─── Import Section Grid ─── */
.import-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

/* ─── Misc ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-info { background: rgba(13,110,110,0.12); color: var(--accent); }

.flex { display: flex; }
.flex-center { align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }

/* ─── History + Audit Log side-by-side ─── */
.history-audit-row  { display: flex; gap: 20px; align-items: flex-start; }
.history-card-left  { flex: 0 0 505px; min-width: 0; }
.history-card-right { flex: 1; min-width: 0; }
@media (max-width: 960px) {
  .history-audit-row { flex-direction: column; }
  .history-card-left, .history-card-right { flex: none; width: 100%; }
}
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── Frozen columns in By Project table ─── */
.table-frozen thead th.col-freeze,
.table-frozen tbody td.col-freeze {
  position: sticky;
  background: #ffffff;
  z-index: 2;
  border-right: 1px solid var(--border);
}
.table-frozen thead th.col-freeze {
  z-index: 3;
  background: var(--bg-header);
}
.table-frozen tbody tr:nth-child(even) td.col-freeze {
  background: var(--bg-frozen-even);
}
.table-frozen tbody tr:hover td.col-freeze {
  background: #f0f8f7;
}
.table-frozen .col-f1 { left: 0; min-width: 44px; max-width: 44px; }
.table-frozen .col-f2 { left: 44px; min-width: 70px; max-width: 70px; }
.table-frozen .col-f3 { left: 114px; min-width: 170px; }

/* Frozen columns for Discount Detail table (different widths from By Project) */
.table-disc-frozen thead th.col-freeze,
.table-disc-frozen tbody td.col-freeze {
  position: sticky; background: var(--bg-secondary); z-index: 2; border-right: 1px solid var(--border);
}
.table-disc-frozen thead th.col-freeze { z-index: 3; background: var(--bg-header); }
.table-disc-frozen tbody tr:nth-child(even) td.col-freeze { background: var(--bg-frozen-even); }
.table-disc-frozen tbody tr:hover td.col-freeze { background: #f0f8f7; }
.table-disc-frozen .disc-f1 { left: 0; min-width: 36px; max-width: 36px; }
.table-disc-frozen .disc-f2 { left: 36px; min-width: 96px; max-width: 96px; }
.table-disc-frozen .disc-f3 { left: 132px; min-width: 140px; border-right: 2px solid var(--border-strong); }

/* Discount search bar */
.disc-search-bar { display:flex; align-items:center; gap:8px; padding:8px 12px; border-bottom:1px solid var(--border); background:var(--bg-header); flex-wrap:nowrap; overflow-x:auto; }
.disc-search-group { display:flex; align-items:center; gap:5px; background:var(--bg-secondary); border:1px solid var(--border); border-radius:6px; padding:4px 9px; font-size:0.78rem; color:var(--text-secondary); white-space:nowrap; flex-shrink:0; }
.disc-search-group label { white-space:nowrap; flex-shrink:0; font-size:0.7rem; color:var(--text-muted); }
.disc-search-group input { border:none; outline:none; font-size:0.78rem; color:var(--text-primary); background:transparent; width:110px; }
.disc-search-group select { border:none; outline:none; font-size:0.78rem; color:var(--text-primary); background:transparent; }
.disc-search-group:focus-within { border-color:var(--accent); background:#fff; }

/* Department group header row in By Dept */
tr.dept-header td {
  background: var(--bg-group-row) !important;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--navy);
  padding: 9px 12px;
  letter-spacing: 0.3px;
  border-top: 2px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  text-align: right;
}
tr.dept-header td.dept-name {
  text-align: left;
  padding-left: 16px;
  user-select: none;
}
tr.dept-header:hover td {
  background: var(--bg-header-hover) !important;
}
.dh-arrow {
  display: inline-block;
  width: 14px;
  font-size: 0.75rem;
  color: var(--accent);
  transition: transform 0.15s;
}

/* ─── Policy section nav (distinct from report tabs) ─── */
.policy-section-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 20px;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.policy-section-btn {
  padding: 9px 22px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.2px;
}

.policy-section-btn:hover { color: var(--navy); background: rgba(27,54,96,0.07); }
.policy-section-btn.active { background: var(--navy); color: white; box-shadow: 0 2px 12px rgba(27,54,96,0.25); }

/* ─── Policy Lock ─── */
.policy-lock-btn {
  margin-left: auto;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  background: var(--navy);
  color: white;
  transition: background 0.15s;
  white-space: nowrap;
}
.policy-lock-btn:hover { background: var(--navy-light); }
.policy-lock-btn.unlocked {
  background: #e2f8f4;
  color: var(--accent-dark);
  border: 1px solid rgba(13,110,110,0.3);
}
.policy-lock-btn.unlocked:hover { background: #c7f2ea; }

/* When locked: disable all inputs/buttons inside the content wrapper */
#policyContentWrapper.policy-locked input,
#policyContentWrapper.policy-locked select,
#policyContentWrapper.policy-locked textarea {
  pointer-events: none;
  background: var(--bg-input) !important;
  color: var(--text-muted) !important;
  border-color: var(--border) !important;
  cursor: default;
}
#policyContentWrapper.policy-locked button {
  pointer-events: none;
  opacity: 0.35;
  cursor: default;
}
/* Navigation and lock button remain fully clickable even when locked */
#policyContentWrapper.policy-locked .policy-section-btn,
#policyContentWrapper.policy-locked .policy-tab,
#policyContentWrapper.policy-locked .policy-lock-btn {
  pointer-events: auto;
  opacity: 1;
}

/* ─── Report tab row + inline search ─── */
.report-tabs-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: nowrap;
}
.report-tabs-row .report-tabs {
  margin-bottom: 0;
  flex: 1;
  flex-wrap: wrap;
}
.report-search-shared {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  background: var(--bg-input);
  min-width: 160px;
  flex-shrink: 0;
  transition: border-color 0.2s, background 0.2s;
}
.report-search-shared:focus-within {
  border-color: var(--accent);
  background: #fff;
}
.report-search-shared .search-input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 12.5px;
  color: var(--text-secondary);
  width: 100px;
}
.report-search-shared .search-icon { color: var(--text-muted); font-size: 13px; }
.report-search-shared .search-clear {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px;
}
.report-search-shared .search-clear:hover { color: var(--text-primary); }
.report-search-shared .search-counter {
  font-size: 11px; color: var(--text-muted); white-space: nowrap;
}
.quota-actions-bar {
  display: flex; gap: 8px; align-items: center;
  padding-bottom: 10px;
}

/* ─── Report sub-tabs ─── */
.report-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.report-tab {
  padding: 8px 20px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.report-tab:hover { border-color: var(--accent); color: var(--text-primary); }
.report-tab.active { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }

/* ─── Success Button ─── */
.btn-success {
  background: rgba(16,185,129,0.15);
  color: var(--success);
  border: 1px solid rgba(16,185,129,0.4);
}
.btn-success:hover { background: rgba(16,185,129,0.25); }
.btn-success:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Warning Button ─── */
.btn-warning {
  background: rgba(245,158,11,0.15);
  color: var(--warning);
  border: 1px solid rgba(245,158,11,0.4);
}
.btn-warning:hover { background: rgba(245,158,11,0.25); }

/* ─── Stat meta ─── */
.stat-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,8,13,0.88);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease;
  overflow-y: auto;
  padding: 24px 16px;
}

.modal-overlay.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  max-width: 520px;
  width: 90%;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s ease;
  margin: auto;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-body {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.7;
  margin-bottom: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* ─── Finalized row ─── */
.finalized-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.finalized-row:last-child { border-bottom: none; }

.finalized-row .quarter-label {
  font-weight: 700;
  font-size: 1rem;
  color: var(--warning);
}

.finalized-row .meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ─── Discount Matrix ─── */
.dm-type-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}

.dm-type-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.dm-type-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.dm-type-num {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.dm-type-name {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 2px 4px;
  min-width: 0;
  width: 100%;
}
.dm-type-name:focus { outline: none; border-bottom-color: var(--accent); }

.dm-type-desc { margin-bottom: 10px; }

.dm-matrix-wrap { overflow-x: auto; }

.dm-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.dm-matrix th, .dm-matrix td {
  border: 1px solid var(--border);
  padding: 5px 7px;
  text-align: center;
  vertical-align: middle;
}

.dm-matrix thead th {
  background: rgba(27,54,96,0.06);
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.dm-dept-cell {
  text-align: left !important;
  min-width: 160px;
  background: #f0f4f8;
}

.dm-dept-name {
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--border);
  color: var(--text-primary);
  font-size: 0.83rem;
  width: 120px;
  padding: 1px 2px;
}
.dm-dept-name:focus { outline: none; border-bottom-color: var(--accent); }

.dm-dept-id {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 4px;
}

.dm-lv-th { min-width: 88px; }

.dm-lv-header {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
}

.dm-lv-input {
  width: 76px;
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--border);
  color: var(--text-primary);
  font-size: 0.8rem;
  text-align: center;
  padding: 1px 2px;
}
.dm-lv-input:focus { outline: none; border-bottom-color: var(--accent); }

.dm-f-input {
  width: 52px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 0.85rem;
  text-align: center;
  padding: 3px 4px;
}
.dm-f-input:focus { outline: none; border-color: var(--accent); }

.dm-f-input.f-full { background: rgba(16,185,129,0.10); color: #047857; border-color: rgba(16,185,129,0.35); }
.dm-f-input.f-zero { background: rgba(239,68,68,0.08);  color: #b91c1c; border-color: rgba(239,68,68,0.3); }
.dm-f-input.f-mid  { background: rgba(245,158,11,0.10); color: #92400e; border-color: rgba(245,158,11,0.35); }

.dm-x-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 2px;
  line-height: 1;
}
.dm-x-btn:hover { color: var(--danger); }

.dm-add-dept-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}

.dm-lv-range {
  display: flex;
  align-items: center;
  gap: 3px;
  justify-content: center;
  margin-top: 4px;
}

.dm-range-input {
  width: 46px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-align: center;
  padding: 2px 3px;
}
.dm-range-input:focus { outline: none; border-color: var(--accent); color: var(--text-primary); }

.dm-range-sep { color: var(--text-muted); font-size: 0.75rem; }

/* Highlighted stat card for total-to-pay */
.stat-card.stat-card-highlight {
  background: linear-gradient(135deg, rgba(27,54,96,0.07), rgba(13,110,110,0.07));
  border-color: rgba(13,110,110,0.3);
}
.stat-card.stat-card-highlight .stat-value { color: var(--accent) !important; -webkit-text-fill-color: var(--accent) !important; }

/* ─── Stat card color coding by category ─── */
/* Operational: gray */
#statStaff, #statContracts {
  border-left-color: #94a3b8;
}
/* Financial result: navy */
#statCommission {
  border-left-color: #0D4A9A;
}
/* Due This Q: amber */
#statPrevQuota {
  border-left-color: #d97706;
}
#statPrevQuota.ready .stat-value {
  color: #d97706 !important;
  -webkit-text-fill-color: #d97706 !important;
}
/* Total to Pay: green — override highlight class */
#statTotalPay {
  border-left-color: #15803d !important;
  background: linear-gradient(135deg, rgba(21,128,61,0.07), rgba(21,128,61,0.03)) !important;
}
#statTotalPay .stat-value,
#statTotalPay.ready .stat-value {
  color: #15803d !important;
  -webkit-text-fill-color: #15803d !important;
}

.stat-card.stat-card-link {
  cursor: pointer;
  user-select: none;
}
.stat-card.stat-card-link:hover {
  border-color: rgba(13,110,110,0.4);
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(27,54,96,0.15);
}
.stat-card.stat-card-link::after {
  content: '↗';
  position: absolute;
  top: 8px; right: 10px;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s;
}
.stat-card.stat-card-link:hover::after { opacity: 0.6; }

/* ─── Accessibility: disable animations for users with reduced-motion preference ─── */
@media (prefers-reduced-motion: reduce) {
  .stat-card { transition: none; }
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .header { flex-direction: column; gap: 12px; text-align: center; }
  .tab-nav { flex-wrap: wrap; }
  .tab-btn { flex: unset; padding: 10px 14px; font-size: 0.82rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .import-grid { grid-template-columns: 1fr; }
}

/* ─── Report Search Bar ─── */
.report-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.search-icon { font-size: 0.9rem; opacity: 0.6; flex-shrink: 0; }
.search-input {
  flex: 1;
  max-width: 420px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 6px 12px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }
.search-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  display: none;
}
.search-clear:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.search-clear.visible { display: block; }
.search-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 80px;
}
.search-counter.has-filter { color: var(--accent-light); font-weight: 600; }
mark.sh {
  background: rgba(245,158,11,0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
