:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-dark: #233f67;
  --surface-dark-2: #1b3558;
  --text: #22324a;
  --muted: #6f7f95;
  --line: #e3e9f2;
  --primary: #2b4f7e;
  --primary-strong: #1f3e67;
  --secondary: #eef3f9;
  --success: #1f8d58;
  --warning: #c58c1e;
  --danger: #c24f46;
  --shadow: 0 14px 40px rgba(28, 45, 74, 0.08);
  font-family: "Heebo", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-frame {
  width: 100%;
  min-height: 100vh;
}

.auth-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 0;
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.auth-card {
  padding: 24px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-helper {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--text);
  display: grid;
  gap: 6px;
}

.shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--surface-dark) 0%, var(--surface-dark-2) 100%);
  color: #fff;
  padding: 0 0 24px;
  display: grid;
  align-content: start;
  align-items: start;
  gap: 14px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.brand-card {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 800;
}

.brand-card h1,
.topbar h2,
.view-header h2 {
  margin: 0;
}

.brand-card h1 {
  font-size: 1.2rem;
  color: #fff;
}

.brand-copy,
.session-card p,
.auth-card p,
.section-head p,
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.brand-copy,
.session-card p {
  color: rgba(255, 255, 255, 0.72);
}

.side-nav {
  display: grid;
  gap: 4px;
  padding: 0 10px;
}

.nav-item {
  justify-content: flex-start;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
  font-weight: 500;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 700;
}

.session-card {
  margin: 10px 12px 0;
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.session-card h2 {
  margin: 0;
  color: #fff;
  font-size: 1rem;
}

.side-actions,
.inline-tools,
.form-actions,
.row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.content-shell {
  padding: 18px;
  display: grid;
  align-content: start;
  align-items: start;
  gap: 16px;
}

.topbar {
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.topbar h2 {
  font-size: 1.4rem;
}

.view {
  display: none;
  align-content: start;
  align-items: start;
  gap: 16px;
}

.view.active {
  display: grid;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.view-header.simple {
  padding-bottom: 14px;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.hero-stats article,
.card {
  padding: 18px 20px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero-stats article {
  background: linear-gradient(180deg, #fff 0%, #f8fbff 100%);
}

.hero-stats span {
  display: block;
  margin-bottom: 4px;
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--primary);
}

.representatives-stats article {
  background: linear-gradient(180deg, #fff 0%, #f4f8fd 100%);
}

.panel-grid {
  display: grid;
  align-items: start;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-grid,
.reports-page-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.split-main {
  grid-template-columns: 380px minmax(0, 1fr);
}

.users-layout {
  grid-template-columns: minmax(0, 1fr) 380px;
}

.card-wide {
  grid-column: 1 / -1;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-head h3,
.auth-card h2,
.session-card h2 {
  margin: 0;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 8px;
  font-weight: 500;
}

.full {
  grid-column: 1 / -1;
}

input,
textarea,
select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid #d7e0eb;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(43, 79, 126, 0.12);
  border-color: var(--primary);
}

button,
.import-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  transition: background 160ms ease, transform 160ms ease;
}

button:hover,
.import-button:hover {
  background: var(--primary-strong);
  transform: translateY(-1px);
}

button.secondary {
  background: var(--secondary);
  color: var(--text);
}

button.secondary:hover {
  background: #dce6f1;
}

.import-button input {
  display: none;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 10px;
  text-align: right;
  border-bottom: 1px solid #edf1f6;
  vertical-align: top;
  white-space: nowrap;
}

thead th {
  color: var(--muted);
  font-size: 0.93rem;
  font-weight: 700;
  background: #fbfdff;
}

.subline {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  white-space: normal;
}

.report-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.report-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eef2f7;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--secondary);
  font-size: 0.9rem;
  font-weight: 700;
}

.pill.success {
  background: rgba(31, 141, 88, 0.12);
  color: var(--success);
}

.pill.warning {
  background: rgba(197, 140, 30, 0.12);
  color: var(--warning);
}

.pill.danger {
  background: rgba(194, 79, 70, 0.12);
  color: var(--danger);
}

.message {
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(31, 141, 88, 0.1);
  color: var(--success);
}

.message.error {
  background: rgba(194, 79, 70, 0.12);
  color: var(--danger);
}

#inlineMessageHost:empty {
  display: none;
}

.empty-state {
  padding: 30px 12px;
  color: var(--muted);
  text-align: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 0 4px;
  color: var(--muted);
  font-size: 0.93rem;
}

.pagination button:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.import-button input[type="file"] {
  display: none;
}

th[data-sort] {
  cursor: pointer;
  user-select: none;
}

th[data-sort]:hover {
  color: var(--primary);
}

.sort-asc::after {
  content: " ▲";
  color: var(--primary);
}

.sort-desc::after {
  content: " ▼";
  color: var(--primary);
}

.hidden {
  display: none !important;
}

/* ─── CSV import progress ────────────────────────────────────────────────────── */

.dialog-box.csv-import-progress-dialog {
  width: min(440px, 92vw);
  height: auto;
  min-height: 0;
  max-height: 85vh;
}

.csv-import-progress-body {
  padding: 16px 22px 8px;
  flex: 0 1 auto;
  overflow-y: auto;
}

.csv-import-progress-body progress {
  width: 100%;
  height: 10px;
  border-radius: 6px;
  accent-color: var(--primary);
}

.csv-import-progress-status {
  margin: 12px 0 0;
  font-size: 0.9rem;
  line-height: 1.45;
}

.csv-import-progress-errors {
  margin-top: 12px;
  max-height: 140px;
  overflow-y: auto;
  font-size: 0.8rem;
  line-height: 1.4;
  background: var(--surface-soft);
  padding: 10px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  direction: rtl;
  text-align: right;
}

/* ─── Label Print Dialog ─────────────────────────────────────────────────────── */

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.dialog-box {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 90vh;
}

.label-dialog-box {
  width: min(1040px, 96vw);
}

.dialog-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.dialog-header h3 { margin: 0; font-size: 1.1rem; }

.label-dialog-body {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.label-settings-col {
  padding: 16px;
  border-left: 1px solid var(--line);
  overflow-y: auto;
  background: var(--surface-soft);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.label-checks {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.83rem;
  cursor: pointer;
  font-weight: 400;
}

.check-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
}

.label-settings-col h4 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.label-inputs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.label-inputs-grid label {
  gap: 4px;
  font-size: 0.82rem;
}

.label-inputs-grid input {
  padding: 7px 10px;
  font-size: 0.9rem;
}

.label-preview-stat {
  padding: 10px 12px;
  background: var(--secondary);
  border-radius: 10px;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.7;
}

.label-preview-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 16px 20px;
  background: #c0c9d6;
  overflow: hidden;
  min-height: 0;
}

.label-preview-col > small {
  font-size: 0.72rem;
  color: #4a5a6a;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  align-self: flex-start;
  flex-shrink: 0;
}

.preview-a4-host {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 4px 0 12px;
}

.preview-a4-sheet {
  transform-origin: top center;
  flex-shrink: 0;
}

.preview-paper-mm {
  background: #fff;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
}

.prev-cell {
  border: 1px dashed #9aa5b5;
  border-radius: 2px;
  background: #eceff2;
  overflow: hidden;
  padding: 3mm 4mm;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1mm;
  direction: rtl;
  text-align: right;
  min-height: 0;
  min-width: 0;
}

.prev-cell-empty {
  border: 1px dashed rgba(154, 165, 181, 0.35);
  background: rgba(255, 255, 255, 0.45);
}

.prev-label-name { font-weight: 500; overflow: hidden; line-height: 1.35; color: #1a1a1a; font-size: 9.5pt; }
.prev-label-sub  { color: #333; overflow: hidden; line-height: 1.35; font-size: 9.5pt; }

.dialog-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.dialog-footer .spacer { flex: 1; }

.dialog-header h2 { margin: 0; font-size: 1.1rem; }

.family-dialog-box {
  width: min(760px, 96vw);
  height: auto;
  max-height: 90vh;
}

.family-dialog-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
}

.families-full-grid {
  grid-template-columns: 1fr;
}

.families-wide-table {
  font-size: 0.82rem;
}

.families-wide-table th,
.families-wide-table td {
  white-space: nowrap;
  padding: 6px 10px;
}

.families-wide-table .family-select-col {
  width: 2.25rem;
  text-align: center;
  vertical-align: middle;
  padding-inline: 6px;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-soft); color: var(--text); }

/* ── Representative detail panel ────────────────────────────────────────── */
.rep-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 300;
}

.rep-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(460px, 100vw);
  background: var(--surface);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.18);
  z-index: 301;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.rep-panel.hidden {
  display: flex;
  transform: translateX(110%);
  pointer-events: none;
}
.rep-panel-overlay.hidden { display: none; }

.rep-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.rep-panel-header h2 { margin: 0; font-size: 1.15rem; }
.rep-panel-meta { margin: 3px 0 0; font-size: 0.82rem; color: var(--muted); }

.rep-panel-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.rep-stat {
  padding: 14px 10px;
  text-align: center;
  border-left: 1px solid var(--line);
}
.rep-stat:last-child { border-left: none; }
.rep-stat-value { display: block; font-size: 1.3rem; font-weight: 800; color: var(--primary); }
.rep-stat-label { display: block; font-size: 0.72rem; color: var(--muted); margin-top: 2px; }

.rep-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.rep-family-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.rep-family-row:last-child { border-bottom: none; }
.rep-family-info { flex: 1; min-width: 0; }
.rep-family-name { font-weight: 700; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rep-family-sub  { font-size: 0.78rem; color: var(--muted); margin-top: 1px; }
.rep-family-amount { font-weight: 800; font-size: 0.95rem; color: var(--primary); white-space: nowrap; }
.rep-no-families { text-align: center; color: var(--muted); font-size: 0.88rem; padding: 40px 0; }

#repPanelEditBtn.active { background: var(--primary); color: #fff; }
.rep-family-remove-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  background: #fee2e2;
  color: #dc2626;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.rep-family-remove-btn:hover:not(:disabled) { background: #fecaca; }
.rep-family-remove-btn:disabled { opacity: 0.5; cursor: default; }

.super-admin-subsection-head {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.super-admin-card .super-admin-hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 6px;
}
.super-admin-card code {
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
}
td.muted {
  color: var(--muted);
  font-size: 0.82rem;
  word-break: break-all;
}
button.secondary.danger-btn {
  border-color: var(--danger);
  color: var(--danger);
}

.pill.muted-pill {
  background: rgba(111, 127, 149, 0.15);
  color: var(--muted);
}

.rep-row-clickable { cursor: pointer; }
.rep-row-clickable:hover td { background: color-mix(in srgb, var(--primary) 5%, transparent); }

@media (max-width: 700px) {
  .rep-panel { width: 100vw; }
}

@media (max-width: 700px) {
  .label-dialog-body { grid-template-columns: 1fr; overflow-y: auto; }
  .label-settings-col { border-left: none; border-bottom: 1px solid var(--line); }
}

.mobile-menu-button {
  display: none;
  min-height: 38px;
  padding: 0 14px;
  font-size: 1.2rem;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 10px;
  flex-shrink: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 199;
}

.sidebar-overlay.visible {
  display: block;
}

@media (max-width: 1180px) {
  .shell,
  .dashboard-grid,
  .reports-page-grid,
  .split-main,
  .auth-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 82%;
    max-width: 300px;
    z-index: 200;
    transform: translateX(110%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .mobile-menu-button {
    display: inline-flex;
  }

  .topbar {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface-dark);
    border-color: transparent;
    border-radius: 0;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .topbar > div {
    flex: 1;
  }

  .topbar h2 {
    font-size: 1.05rem;
    color: #fff;
  }

  .topbar p {
    display: none;
  }

  .view-header.simple {
    display: none;
  }

  .content-shell {
    padding: 0 10px 10px;
    gap: 12px;
  }

  .hero-stats {
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hero-stats article {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .hero-stats span {
    font-size: 1.5rem;
    margin-bottom: 0;
  }

  .hero-stats small {
    font-size: 0.85rem;
    color: var(--muted);
  }

  .view-header {
    padding: 14px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .view-header p {
    display: none;
  }

  .inline-tools {
    flex-wrap: wrap;
    gap: 8px;
  }

  .inline-tools input[type="search"] {
    width: 100%;
  }

  .section-head {
    flex-direction: column;
    gap: 8px;
  }

  th, td {
    padding: 10px 8px;
    font-size: 0.88rem;
  }

  .card {
    padding: 14px 16px;
  }

  .nav-item {
    min-height: 50px;
    font-size: 1rem;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions button {
    width: 100%;
  }

  .pagination {
    font-size: 0.85rem;
    gap: 8px;
  }

  .auth-card {
    padding: 20px 16px;
  }
}

@media (max-width: 860px) {
  .content-shell {
    padding: 12px;
  }

  .form-grid,
  .panel-grid,
  .hero-stats {
    grid-template-columns: 1fr;
  }

  .view-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
