/* ═══════════════════════════════════════════════════════════ DESIGN TOKENS */
:root {
  --blue:       #115198;
  --blue-light: #116ACA;
  --blue-dark:  #0d3d73;
  --yellow:     #FFDE26;
  --black:      #000000;
  --gray-light: #EDEDED;
  --white:      #ffffff;

  --text-primary:   #1e293b;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;

  --bg:         #f1f5f9;
  --bg-card:    #ffffff;
  --border:     #e2e8f0;
  --border-md:  #cbd5e1;

  --green:  #16a34a;
  --red:    #dc2626;
  --amber:  #d97706;

  --sidebar-w: 240px;
  --topbar-h:  60px;

  --radius:   8px;
  --radius-lg:12px;
  --shadow:   0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);
  --shadow-md:0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);
  --shadow-lg:0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
}

/* ═══════════════════════════════════════════════════════════════ RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; color: var(--text-primary); background: var(--bg); line-height: 1.5; overflow-x: hidden; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--blue); text-decoration: none; }

/* ═══════════════════════════════════════════════════════════════ LAYOUT */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--blue);
  display: flex; flex-direction: column;
  z-index: 100;
}

.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* ═══════════════════════════════════════════════════════════════ SIDEBAR */
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.brand-name  { font-size: 15px; font-weight: 700; color: #fff; }
.brand-sub   { font-size: 10px; color: rgba(255,255,255,.55); text-transform: uppercase; letter-spacing: .8px; }

.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  color: rgba(255,255,255,.7); font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
  text-align: left; width: 100%;
}
.nav-item:hover  { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 10px; color: rgba(255,255,255,.35);
  text-transform: uppercase; letter-spacing: .8px;
}

/* ═══════════════════════════════════════════════════════════════ TOPBAR */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.topbar-actions { display: flex; gap: 8px; }

/* ═══════════════════════════════════════════════════════════════ PAGES */
.page-section { display: none; padding: 24px 28px; flex: 1; }
.page-section.active { display: block; }

/* ═══════════════════════════════════════════════════════════════ STAT GRID */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}
.stat-card--accent { background: var(--blue); border-color: var(--blue); }
.stat-card--accent .stat-value { color: var(--yellow); }
.stat-card--accent .stat-label { color: rgba(255,255,255,.7); }
.stat-value { font-size: 36px; font-weight: 800; color: var(--blue); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 6px; text-transform: uppercase; letter-spacing: .6px; }

/* ═══════════════════════════════════════════════════════════════ CARDS */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  font-size: 13px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .7px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 20px; }

/* ═══════════════════════════════════════════════════════════════ TOOLBAR */
.toolbar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap;
}
.search-input {
  border: 1px solid var(--border-md); border-radius: var(--radius);
  padding: 8px 12px; font-size: 13px; background: var(--bg-card);
  outline: none; min-width: 240px; flex: 1;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--blue); }
.filter-select {
  border: 1px solid var(--border-md); border-radius: var(--radius);
  padding: 8px 12px; font-size: 13px; background: var(--bg-card);
  outline: none; cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════ TABLES */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 11px 16px;
  font-size: 11px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .7px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text-primary); vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }

.table-email    { color: var(--text-secondary); font-size: 12px; }
.table-actions  { display: flex; gap: 6px; justify-content: flex-end; }

/* ═══════════════════════════════════════════════════════════════ BADGES */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 9999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-gray   { background: #f1f5f9; color: var(--text-secondary); }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-red    { background: #fee2e2; color: #b91c1c; }

/* ═══════════════════════════════════════════════════════════════ BUTTONS */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  transition: opacity .15s, background .15s, box-shadow .15s;
  white-space: nowrap; cursor: pointer;
}
.btn:hover { opacity: .88; }
.btn:active { opacity: .75; }

.btn-primary   { background: var(--blue); color: #fff; }
.btn-secondary { background: var(--blue-light); color: #fff; }
.btn-danger    { background: var(--red); color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-md); }
.btn-ghost:hover { background: var(--bg); opacity: 1; }
.btn-sm  { padding: 5px 10px; font-size: 12px; }
.btn-lg  { padding: 11px 24px; font-size: 14px; }
.btn-icon { padding: 6px; border-radius: 6px; }
.btn-icon:hover { background: var(--bg); opacity: 1; }

.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* ═══════════════════════════════════════════════════════════════ FORMS */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group--full { grid-column: 1 / -1; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
.form-input {
  border: 1px solid var(--border-md); border-radius: var(--radius);
  padding: 9px 12px; font-size: 13px; background: var(--bg-card);
  outline: none; transition: border-color .15s;
}
.form-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgb(17 81 152 / .1); }
textarea.form-input { resize: vertical; }
.form-hint { font-size: 11px; color: var(--text-muted); }
.form-check-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-primary); cursor: pointer; }
.form-check-label input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--blue); }
.form-actions { display: flex; gap: 10px; justify-content: flex-start; }
.required { color: var(--red); }

/* ═══════════════════════════════════════════════════════════════ FILE DROP */
.file-drop {
  border: 2px dashed var(--border-md); border-radius: var(--radius-lg);
  padding: 40px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--bg);
}
.file-drop:hover, .file-drop.drag-over { border-color: var(--blue); background: #eff6ff; }
.file-drop-text  { font-size: 14px; font-weight: 600; color: var(--blue); margin-top: 12px; }
.file-drop-sub   { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.file-drop-name  { font-size: 13px; font-weight: 600; color: var(--green); margin-top: 8px; }

/* ═══════════════════════════════════════════════════════════════ REPORTS UI */
.report-summary-bar {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
  padding: 12px 16px; background: #f0fdf4; border: 1px solid #bbf7d0;
  border-radius: var(--radius); margin-bottom: 16px; font-size: 13px;
}
.report-summary-bar strong { color: var(--green); }

.unmatched-warning {
  padding: 12px 16px; background: #fffbeb; border: 1px solid #fde68a;
  border-radius: var(--radius); margin-bottom: 16px; font-size: 13px;
  color: #92400e;
}

.report-org-card {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  margin-bottom: 12px; overflow: hidden;
}
.report-org-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--bg); cursor: pointer;
  transition: background .15s;
}
.report-org-header:hover { background: #f0f4f8; }
.report-org-name  { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.report-org-meta  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.report-org-body  { padding: 16px 20px; border-top: 1px solid var(--border); }
.report-org-body.hidden { display: none; }

.report-stats-mini {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  margin-bottom: 16px;
}
.rstat { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px; text-align: center; }
.rstat-val { font-size: 20px; font-weight: 700; color: var(--blue); }
.rstat-lbl { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

.recipients-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.recipient-chip {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 10px; background: #dbeafe; color: #1d4ed8;
  border-radius: 9999px; font-size: 11px; font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════ QUICK ACTIONS */
.quick-actions { padding: 16px 20px; display: flex; gap: 10px; flex-wrap: wrap; }

/* ═══════════════════════════════════════════════════════════════ DASHBOARD ORG LIST */
.dash-org-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.dash-org-row:last-child { border-bottom: none; }
.dash-org-row-name  { font-weight: 600; }
.dash-org-row-meta  { font-size: 12px; color: var(--text-muted); }
.dash-org-row-right { display: flex; align-items: center; gap: 12px; }

/* ═══════════════════════════════════════════════════════════════ STATES */
.loading-state { padding: 40px; text-align: center; color: var(--text-muted); font-size: 14px; }
.empty-state   { padding: 48px; text-align: center; color: var(--text-muted); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; font-weight: 600; color: var(--text-secondary); }
.empty-state-sub  { font-size: 13px; margin-top: 4px; }

/* ═══════════════════════════════════════════════════════════════ MODALS */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgb(0 0 0 / .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-card); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  max-height: 90vh;
}
.modal--sm { max-width: 420px; }
.modal--xl { max-width: 900px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; border-bottom: 1px solid var(--border);
}
.modal-title  { font-size: 16px; font-weight: 700; }
.modal-close  { color: var(--text-muted); font-size: 18px; line-height: 1; padding: 4px; }
.modal-close:hover { color: var(--text-primary); }
.modal-body   { padding: 24px; overflow-y: auto; }
.modal-body--scroll { overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px; border-top: 1px solid var(--border);
}

/* pa241 row hidden by default */
#pa241-row { display: none; }

/* ═══════════════════════════════════════════════════════════════ TOAST */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; color: #fff;
  box-shadow: var(--shadow-md); min-width: 240px;
  animation: slideIn .2s ease;
}
.toast--success { background: var(--green); }
.toast--error   { background: var(--red); }
.toast--info    { background: var(--blue); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(100%); } }

/* ═══════════════════════════════════════════════════════════════ SPINNER */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════════ RESPONSIVE */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-240px); transition: transform .2s; }
  .form-grid { grid-template-columns: 1fr; }
  .report-stats-mini { grid-template-columns: repeat(2, 1fr); }
}
