/* =============================================================
   Draft Salary Slip — app.css
   Design language taken from "Master Gropup Budget" (Cairo/Outfit, light theme,
   glass cards, fin-table). Page width 1440px.
   ============================================================= */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0b0f19; --bg-secondary: #111827;
  --bg-card: rgba(22, 28, 45, 0.7); --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(59, 130, 246, 0.25);
  --color-primary: #3b82f6; --color-primary-glow: rgba(59, 130, 246, 0.15);
  --color-success: #10b981; --color-success-glow: rgba(16, 185, 129, 0.15);
  --color-warning: #f59e0b; --color-warning-glow: rgba(245, 158, 11, 0.15);
  --color-danger: #ef4444; --color-danger-glow: rgba(239, 68, 68, 0.15);
  --text-main: #f3f4f6; --text-muted: #9ca3af; --text-active: #ffffff;
  --line-red: #f87171; --line-blue: #93c5fd; --line-green: #4ade80; --line-purple: #c4b5fd;
  --line-tax-bg: rgba(250, 204, 21, 0.10); --net-bg: rgba(255, 255, 255, 0.06);
  --font-family: 'Outfit', 'Cairo', system-ui, -apple-system, sans-serif;
  --radius-lg: 16px; --radius-md: 10px; --radius-sm: 6px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
body.light-theme {
  --bg-primary: #f8fafc; --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9); --border-color: rgba(15, 23, 42, 0.10);
  --border-glow: rgba(59, 130, 246, 0.15);
  --color-primary: #1d4ed8; --color-primary-glow: rgba(29, 78, 216, 0.08);
  --color-success: #059669; --color-success-glow: rgba(5, 150, 105, 0.08);
  --color-warning: #d97706; --color-warning-glow: rgba(217, 119, 6, 0.08);
  --color-danger: #dc2626; --color-danger-glow: rgba(220, 38, 38, 0.08);
  --text-main: #334155; --text-muted: #64748b; --text-active: #0f172a;
  --line-red: #dc2626; --line-blue: #1d4ed8; --line-green: #15803d; --line-purple: #7030a0;
  --line-tax-bg: #fff8db; --net-bg: #eef2f7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-family); background-color: var(--bg-primary); color: var(--text-main);
  min-height: 100vh; direction: rtl; transition: background-color .3s ease, color .3s ease;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

.app-container { max-width: 1440px; margin: 30px auto; padding: 0 24px 60px; width: 100%; animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- cards ---------- */
.glass-card {
  background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius-lg);
  padding: 26px 28px; margin-bottom: 24px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}
.card-title-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 14px; flex-wrap: wrap;
}
.card-title-bar h4 { font-size: 1.1rem; font-weight: 700; color: var(--text-active); }
.card-title-bar p { color: var(--text-muted); font-size: .84rem; margin-top: 4px; }

/* ---------- header ---------- */
.dep-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 20px 28px; flex-wrap: wrap; }
.dep-title-wrap { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 13px; background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff; font-weight: 700; font-size: 15px; display: flex; align-items: center; justify-content: center;
}
.dep-title { font-size: 1.5rem; font-weight: 700; color: var(--text-active); }
.dep-subtitle { color: var(--text-muted); font-size: .86rem; margin-top: 3px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: none; border: 1px solid var(--border-color); color: var(--text-muted);
  width: 40px; height: 40px; border-radius: var(--radius-md); display: flex; align-items: center;
  justify-content: center; cursor: pointer; transition: var(--transition);
}
.icon-btn:hover { color: var(--color-primary); border-color: var(--color-primary); }
.icon-btn svg { width: 19px; height: 19px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 50px;
  border: 1px solid var(--border-color); font-size: .82rem; font-weight: 600; color: var(--text-main);
  background: var(--bg-secondary);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; flex: 0 0 auto; }
.dot.on { background: var(--color-success); box-shadow: 0 0 0 3px var(--color-success-glow); }
.dot.warn { background: var(--color-warning); }

/* ---------- company tiles ---------- */
.company-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.company-tile {
  background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md);
  padding: 16px 18px; cursor: pointer; transition: var(--transition); text-align: start;
  font-family: var(--font-family); color: inherit;
}
.company-tile:hover { border-color: var(--color-primary); }
.company-tile.active { border-color: var(--color-primary); background: var(--color-primary-glow); }
.company-tile .ct-name { font-weight: 700; color: var(--text-active); font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.company-tile.active .ct-name { color: var(--color-primary); }
.company-tile .ct-url { font-size: .74rem; color: var(--text-muted); margin-top: 6px; direction: ltr; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-tile .ct-state { font-size: .76rem; color: var(--text-muted); margin-top: 6px; }

/* ---------- tabs ---------- */
.company-tabs { display: flex; border-bottom: 1px solid var(--border-color); gap: 6px; margin-bottom: 22px; overflow-x: auto; }
.tab-btn {
  background: none; border: none; color: var(--text-muted); padding: 12px 22px; font-weight: 600;
  font-family: var(--font-family); font-size: .94rem; cursor: pointer; border-radius: var(--radius-md) var(--radius-md) 0 0;
  transition: var(--transition); position: relative; white-space: nowrap; display: inline-flex; gap: 8px; align-items: center;
}
.tab-btn:hover:not([disabled]) { color: var(--text-active); background-color: rgba(0,0,0,.02); }
.tab-btn.active { color: var(--color-primary); background-color: var(--color-primary-glow); }
.tab-btn.active::after { content: ''; position: absolute; bottom: 0; right: 0; left: 0; height: 3px; background: var(--color-primary); }
.tab-btn[disabled] { cursor: not-allowed; opacity: .55; }

/* ---------- forms ---------- */
.add-form {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; padding: 18px;
  background: rgba(0,0,0,.02); border: 1px solid var(--border-color); border-radius: var(--radius-md);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field .lbl { font-size: .76rem; color: var(--text-muted); font-weight: 600; }
.form-control {
  background: #fff; border: 1px solid rgba(15,23,42,.15); color: var(--text-active); padding: 9px 14px;
  border-radius: var(--radius-md); font-family: var(--font-family); font-size: .9rem; outline: none;
  transition: var(--transition); min-width: 160px;
}
body:not(.light-theme) .form-control { background: var(--bg-secondary); color: var(--text-main); }
.form-control:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--border-glow); }
.form-control.wide { width: 100%; min-width: 0; }
.quick-links { display: flex; gap: 6px; }
.segmented { display: inline-flex; border: 1px solid var(--border-color); border-radius: var(--radius-md); overflow: hidden; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  padding: 9px 16px; font-size: .86rem; font-weight: 600; color: var(--text-muted); cursor: pointer;
  transition: var(--transition); background: #fff;
}
body:not(.light-theme) .segmented label { background: var(--bg-secondary); }
.segmented label + input + label { border-inline-start: 1px solid var(--border-color); }
.segmented input:checked + label { background: var(--color-primary); color: #fff; }
.segmented input.no:checked + label { background: var(--color-danger); }
.spacer { flex: 1 1 auto; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 10px 18px;
  border-radius: var(--radius-md); font-family: var(--font-family); font-size: .88rem; font-weight: 600;
  cursor: pointer; border: 1px solid transparent; transition: var(--transition); white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 6px 16px var(--color-primary-glow); }
.btn-secondary { background: rgba(0,0,0,.03); border-color: var(--border-color); color: var(--text-main); }
.btn-secondary:hover { border-color: var(--color-primary); color: var(--color-primary); }
.btn-sm { padding: 7px 13px; font-size: .82rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: none; box-shadow: none; }

/* ---------- badges / alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 50px; font-size: .72rem; font-weight: 700; }
.badge-muted { background: rgba(100,116,139,.10); color: var(--text-muted); border: 1px dashed var(--border-color); }
.badge-info { background: var(--color-primary-glow); color: var(--color-primary); border: 1px solid rgba(59,130,246,.25); }
.badge-warning { background: var(--color-warning-glow); color: var(--color-warning); border: 1px solid rgba(245,158,11,.25); }
.custom-alert { padding: 14px 18px; border-radius: var(--radius-md); font-size: .86rem; line-height: 1.7; margin-bottom: 18px; }
.alert-info { background: var(--color-primary-glow); border: 1px solid rgba(59,130,246,.2); color: #1e3a8a; }
.alert-warn { background: var(--color-warning-glow); border: 1px solid rgba(245,158,11,.3); color: #92400e; }
.alert-error { background: var(--color-danger-glow); border: 1px solid rgba(220,38,38,.3); color: #991b1b; }
body:not(.light-theme) .alert-info { color: #93c5fd; }
body:not(.light-theme) .alert-warn { color: #fcd34d; }
body:not(.light-theme) .alert-error { color: #fca5a5; }

/* ---------- progress ---------- */
.steps { list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.steps li {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--border-color);
  border-radius: var(--radius-md); font-size: .84rem; background: var(--bg-secondary);
}
.steps li.done { color: var(--color-success); border-color: rgba(5,150,105,.3); }
.steps li.current { color: var(--color-primary); border-color: var(--color-primary); }
.spinner { width: 15px; height: 15px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.timer { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: .84rem; }

/* ---------- tiles ---------- */
.tile-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.tile { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 16px 18px; }
.tile-label { font-size: .8rem; font-weight: 600; color: var(--text-muted); }
.tile-value { font-size: 1.35rem; font-weight: 700; color: var(--text-active); margin-top: 6px; letter-spacing: -.3px; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.tile-note { font-size: .72rem; color: var(--text-muted); margin-top: 3px; }
.tile--red .tile-value { color: var(--line-red); }
.tile--blue .tile-value { color: var(--color-primary); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .form-control { min-width: 220px; }
.chip {
  border: 1px solid var(--border-color); background: var(--bg-secondary); color: var(--text-muted);
  padding: 7px 14px; border-radius: 50px; font-family: var(--font-family); font-size: .8rem; font-weight: 600; cursor: pointer;
}
.chip.on { background: var(--color-primary-glow); color: var(--color-primary); border-color: var(--color-primary); }
.count-note { font-size: .82rem; color: var(--text-muted); }

/* ---------- summary table ---------- */
.table-responsive { width: 100%; overflow-x: auto; border: 1px solid var(--border-color); border-radius: var(--radius-md); }
.fin-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.fin-table th {
  background: #f1f5f9; color: var(--text-muted); font-weight: 600; padding: 12px 14px;
  border-bottom: 2px solid var(--border-color); text-align: start; white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
body:not(.light-theme) .fin-table th { background: var(--bg-secondary); }
.fin-table td { padding: 12px 14px; border-bottom: 1px solid var(--border-color); vertical-align: top; color: var(--text-main); }
.emp-id { font-weight: 700; color: var(--color-primary); direction: ltr; white-space: nowrap; text-decoration: none; }
.emp-id:hover { text-decoration: underline; }
.emp-name { font-weight: 700; color: var(--text-active); }
.emp-branch { font-size: .76rem; color: var(--text-muted); margin-top: 4px; }
.lines { direction: ltr; display: flex; flex-direction: column; gap: 2px; min-width: 430px; }
.line { display: flex; justify-content: space-between; gap: 16px; padding: 3px 8px; border-radius: var(--radius-sm); }
.line .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.line .note { font-size: .72rem; opacity: .85; margin-inline-start: 6px; }
.line--salary { color: var(--text-active); }
.line--tax { color: var(--line-red); background: var(--line-tax-bg); }
.line--deduction { color: var(--line-red); font-weight: 700; }
.line--addition { color: var(--line-blue); font-weight: 700; }
.line--pending_add { color: var(--line-green); font-weight: 700; }
.line--pending_ded { color: var(--line-purple); font-weight: 700; }
.mini-list { list-style: none; direction: ltr; font-size: .8rem; display: flex; flex-direction: column; gap: 3px; min-width: 150px; }
.mini-list li { background: rgba(0,0,0,.025); border-radius: var(--radius-sm); padding: 3px 8px; }
.cell-muted { font-size: .8rem; color: var(--text-muted); }
.cell-ltr { direction: ltr; text-align: right; font-size: .8rem; word-break: break-all; }
.net-row td { background: var(--net-bg); font-weight: 700; color: var(--text-active); border-bottom: 2px solid rgba(15,23,42,.14); }
.net-row .net-val { direction: ltr; display: inline-block; font-variant-numeric: tabular-nums; font-size: .95rem; }
.empty-state { text-align: center; padding: 40px; color: var(--text-muted); }

/* ---------- modal / toast ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center;
  padding: 50px 20px; z-index: 100; overflow-y: auto; animation: fadeIn .2s ease;
}
.modal-content { background: var(--bg-secondary); border-radius: var(--radius-lg); width: 100%; max-width: 640px; box-shadow: 0 24px 60px rgba(15,23,42,.25); }
.modal-content.modal-wide { max-width: min(1360px, 96vw); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border-color); }
.modal-header h3 { font-size: 1.15rem; font-weight: 700; color: var(--text-active); }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.5rem; line-height: 1; }
.modal-body { padding: 20px 24px; line-height: 1.8; font-size: .9rem; }
.modal-body ol { padding-inline-start: 22px; }
.modal-footer { display: flex; gap: 10px; padding: 14px 24px 22px; }
.modal-footer { justify-content: flex-end; }
/* login */
.login-card .field { margin-bottom: 18px; }
.login-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.login-form .field { margin: 0; flex: 1 1 260px; }
.login-form .form-control { width: 100%; }
.ltr-input { direction: ltr; text-align: left; }

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px); background: #0f172a; color: #fff;
  padding: 12px 22px; border-radius: var(--radius-md); font-size: .88rem; opacity: 0; pointer-events: none; transition: var(--transition); z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--color-danger); }

@media print {
  body { background: #fff; }
  .no-print, .dep-header .header-actions, .company-tabs { display: none !important; }
  .glass-card { box-shadow: none; border: none; padding: 0; }
  .app-container { margin: 0; max-width: none; }
  .fin-table th { position: static; }
}


/* ---------- punch analysis ---------- */
.az-table td, .az-table th { padding: 10px 12px; }
.az-table .num, .az-days .num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.az-row { cursor: pointer; }
.az-row:hover td { background: rgba(29, 78, 216, .03); }
.az-ded { color: var(--line-red); font-weight: 700; }
.az-detail > td { background: #f8fafc; padding: 12px; }
body:not(.light-theme) .az-detail > td { background: var(--bg-primary); }
.az-days { font-size: .78rem; }
.az-days td, .az-days th { padding: 7px 9px; }
.az-clar { min-width: 260px; line-height: 1.5; }
.day--off td { color: var(--text-muted); background: rgba(100, 116, 139, .05); }
.day--absent td { background: var(--color-danger-glow); }
.day--missing td { background: var(--color-warning-glow); }
.day--excused td { background: var(--color-success-glow); }
.day--multi td { background: #ffd58055; }
.emp-field { flex: 1 1 300px; }
.emp-field .form-control { width: 100%; }
.td-ltr { direction: ltr; text-align: right; }

/* ---------- audits ---------- */
.con-table td, .con-table th { padding: 9px 11px; font-size: .82rem; }
.con-table tbody { border-bottom: 2px solid var(--border-color); }
.con-ext td { background: #fff2cc; }
body:not(.light-theme) .con-ext td { background: rgba(245, 158, 11, .12); }
.con-passed { background: #e6b8af !important; color: #980000; font-weight: 700; }
.con-dec { max-width: 220px; font-size: .76rem; }
.con-note { font-weight: 700; min-width: 180px; }
.con-renew, .con-watch { color: var(--line-red); }
.con-probation { color: var(--color-primary); }
.con-extended { color: var(--color-warning); }

.sub-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.sub-nav-btn { background: rgba(0,0,0,.03); border: 1px solid var(--border-color); color: var(--text-muted); padding: 8px 18px;
  border-radius: var(--radius-md); font-family: var(--font-family); font-weight: 600; font-size: .86rem; cursor: pointer; }
.sub-nav-btn.active { background: var(--color-primary-glow); color: var(--color-primary); border-color: var(--color-primary); }
.bad-cell { color: var(--line-red) !important; font-weight: 700; background: rgba(220, 38, 38, .08); }
.az-row-open td { background: #dbeafe !important; border-top: 2px solid var(--color-primary); }
.az-row-open td:first-child { box-shadow: inset -4px 0 0 var(--color-primary); }
body:not(.light-theme) .az-row-open td { background: rgba(59,130,246,.18) !important; }
.az-detail > td { border-inline-start: 4px solid var(--color-primary); border-bottom: 2px solid var(--color-primary); }
.az-detail-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: .88rem; color: var(--color-primary); }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--color-primary); }
th.sorted { color: var(--color-primary); }
.sort-hint { opacity: .35; font-size: .8em; }

.day--future td { color: var(--text-muted); background: rgba(100, 116, 139, .08); font-style: italic; }
.day--today td { background: rgba(29, 78, 216, .06); }

/* late / early tiers — calm tones */
.tier1 { background: #fef9c3 !important; color: #854d0e !important; }
.tier2 { background: #ffedd5 !important; color: #9a3412 !important; font-weight: 600; }
.tier3 { background: #fee2e2 !important; color: #b91c1c !important; font-weight: 700; }
.tier4 { background: #fbcfe8 !important; color: #831843 !important; font-weight: 700; }
body:not(.light-theme) .tier1 { background: rgba(250, 204, 21, .15) !important; color: #fde68a !important; }
body:not(.light-theme) .tier2 { background: rgba(249, 115, 22, .15) !important; color: #fdba74 !important; }
body:not(.light-theme) .tier3 { background: rgba(239, 68, 68, .15) !important; color: #fca5a5 !important; }
body:not(.light-theme) .tier4 { background: rgba(236, 72, 153, .18) !important; color: #f9a8d4 !important; }
.tier-legend { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .74rem; color: var(--text-muted); margin-inline-start: auto; margin-inline-end: 12px; }
.tier-legend > span { padding: 2px 8px; border-radius: 6px; }

/* company logos */
.brand-logo { background: #fff; border: 1px solid var(--border-color); padding: 5px; width: 56px; height: 56px; }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ct-logo { width: 26px; height: 26px; object-fit: contain; flex: 0 0 auto; }

/* email dialog */
.mail-split { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; }
.mail-list { max-height: 460px; overflow-y: auto; }
.mail-list td, .mail-list th { padding: 7px 9px; font-size: .8rem; }
.mail-row-on td { background: #dbeafe; }
.mail-preview { border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 10px; background: #fff; min-height: 300px; }
.mail-preview iframe { width: 100%; height: 440px; border: 0; margin-top: 8px; background: #fff; }
.mail-ok { background: var(--color-success-glow); color: var(--color-success); border: 1px solid rgba(5,150,105,.25); }
.modal-footer .spacer { flex: 1 1 auto; }
.mail-q { width: 100%; min-width: 0; }

/* ---------- employee statistics window (validated 8-colour palette, stepped per mode) ---------- */
:root { --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
        --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948; }
body:not(.light-theme) { --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
        --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767; }
.stats-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 120; display: flex; align-items: center; justify-content: center; }
.stats-dialog { width: calc(100vw - 48px); height: calc(100vh - 48px); background: var(--bg-secondary); color: var(--text-main);
  border-radius: var(--radius-lg); box-shadow: 0 24px 60px rgba(15,23,42,.3); display: flex; flex-direction: column; overflow: hidden; }
.stats-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 18px 28px; border-bottom: 1px solid var(--border-color); }
.stats-head h2 { font-size: 1.25rem; color: var(--text-active); }
.stats-head-actions { display: flex; gap: 8px; }
.stats-body { flex: 1; overflow-y: auto; padding: 20px 28px 32px; }
.stats-lede { margin: 0 0 16px; color: var(--text-main); line-height: 1.8; }
.stats-table tfoot th { background: transparent !important; }
.stats-total { margin: 0 0 16px; font-size: 18px; color: var(--text-active); }
.stats-total strong { font-size: 40px; line-height: 1.1; margin-inline-start: 6px; font-weight: 700; }
.stats-table tfoot th, .stats-table tfoot td { border-top: 2px solid var(--text-active); font-weight: 700; color: var(--text-active); }
.stats-table tr.hot td { background: var(--color-primary-glow); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.stats-layout { display: grid; grid-template-columns: minmax(300px, 480px) minmax(0, 1fr); gap: 32px; align-items: center; }
@media (max-width: 1100px) { .stats-layout { grid-template-columns: 1fr; } }
.pie-wrap { position: relative; width: 100%; max-width: 1000px; margin: 0 auto; }
.pie { display: block; width: 100%; height: auto; overflow: visible; }
.slice { stroke: var(--bg-secondary); stroke-width: 2; cursor: default; }
.slice:hover { stroke: var(--text-active); }
.slice-label { fill: var(--text-active); font: 600 17px var(--font-family); }
.slice-count { fill: var(--text-muted); font: 15px var(--font-family); }
.leader { fill: none; stroke: var(--text-muted); stroke-width: 1; }
.pie-tooltip { position: absolute; display: grid; gap: 2px; padding: 8px 12px; background: var(--bg-secondary); color: var(--text-active);
  border: 1px solid var(--border-color); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.18); pointer-events: none; white-space: nowrap; direction: rtl; }
.pie-tooltip[hidden] { display: none; }
.stats-form { max-width: 900px; display: flex; flex-direction: column; gap: 14px; }
.stats-form .form-control { width: 100%; }
.stats-sites { display: flex; flex-direction: column; gap: 8px; }
.stats-sites.hidden-pw input { display: none; }
.stats-site { display: grid; grid-template-columns: 28px 140px 260px 130px auto; gap: 10px; align-items: center; min-height: 40px; }
.stats-site input[hidden] { display: block !important; visibility: hidden; }
.stats-site-name { font-weight: 700; color: var(--text-active); }
.stats-link { color: var(--color-primary); font-size: .85rem; }
.stats-form-actions { display: flex; gap: 12px; align-items: center; }
.stats-site .badge { justify-self: start; }

.stats-section { margin-top: 34px; padding-top: 22px; border-top: 1px solid var(--border-color); }
.stats-section h3 { font-size: 1.1rem; color: var(--text-active); margin-bottom: 14px; }
.gender-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 220px)); gap: 14px; margin-bottom: 12px; }
.gender-tile .tile-value { font-size: 1.6rem; }
.gender-pct { font-size: .95rem; color: var(--text-muted); font-weight: 600; }
.g-male-card { border-inline-start: 4px solid var(--series-1); }
.g-female-card { border-inline-start: 4px solid var(--series-5); }
.g-missing-card { border-inline-start: 4px solid var(--color-warning); }
.gender-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; max-width: 920px; background: var(--border-color); }
.gender-bar .g-male { background: var(--series-1); } .gender-bar .g-female { background: var(--series-5); }
.gender-bar .g-other { background: var(--series-7); } .gender-bar .g-missing { background: var(--color-warning); }
.terr-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 32px; align-items: start; }
@media (max-width: 1100px) { .terr-layout { grid-template-columns: 1fr; } }
.terr-table tr.hot td, .terr-row.hot { background: var(--color-primary-glow); }
.terr-spell { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.terr-chip { font-size: .72rem; color: var(--text-muted); border: 1px solid var(--border-color); border-radius: 10px; padding: 0 7px; line-height: 1.6; }
.terr-chart { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.terr-legend { display: flex; gap: 16px; font-size: .85rem; color: var(--text-main); margin-bottom: 6px; }
.terr-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }
.terr-legend i.g-male { background: var(--series-1); } .terr-legend i.g-female { background: var(--series-5); }
.terr-legend i.g-missing { background: var(--color-warning); }
.terr-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 110px; gap: 10px; align-items: center; min-height: 30px; border-radius: 6px; padding: 0 6px; }
.terr-name { font-weight: 700; color: var(--text-active); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.terr-row-empty .terr-name { color: var(--color-warning); }
.terr-track { height: 18px; }
.terr-bar { display: flex; height: 100%; min-width: 3px; border-radius: 4px; overflow: hidden; }
.terr-bar span { display: block; min-width: 2px; }
.terr-bar .g-male { background: var(--series-1); } .terr-bar .g-female { background: var(--series-5); }
.terr-bar .g-other { background: var(--series-7); } .terr-bar .g-missing { background: var(--color-warning); }
.terr-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.terr-empty td { background: var(--color-warning-glow); color: var(--color-warning); font-weight: 700; }
.lack { margin-inline-end: 6px; }
