:root {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --navy: #1b365d;
  --text-main: #0f172a;
  --text-sub: #475569;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success-bg: #dcfce7;
  --success-tx: #15803d;
  --warn-bg: #fef3c7;
  --warn-tx: #b45309;
  --danger-bg: #fee2e2;
  --danger-tx: #b91c1c;
  --info-bg: #dbeafe;
  --info-tx: #1d4ed8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 13.5px;
  line-height: 1.45;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: 264px;
  min-width: 264px;
  background: var(--sidebar-bg);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-logo {
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.5px;
  padding: 9px 11px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.brand-title {
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.3px;
  color: #ffffff;
}

.brand-sub {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}

.role-badge-card {
  margin-top: 14px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 9px;
  padding: 10px 12px;
}

.role-badge-card.sales-role {
  background: rgba(20, 83, 45, 0.45);
  border-color: rgba(74, 222, 128, 0.35);
}

.role-badge-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: #93c5fd;
}

.role-badge-card.sales-role .role-badge-label {
  color: #86efac;
}

.role-badge-value {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-top: 3px;
}

.role-badge-desc {
  font-size: 11px;
  color: #cbd5e1;
  margin-top: 3px;
}

.nav-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.nav-group-title {
  font-size: 10px;
  font-weight: 700;
  color: #64748b;
  letter-spacing: 0.7px;
  padding: 10px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: transparent;
  border: none;
  color: #cbd5e1;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background: #2563eb;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.nav-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 10.5px;
  font-weight: 700;
  flex-shrink: 0;
}

.nav-text {
  flex: 1;
}

.nav-pill {
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
}

.nav-pill.danger {
  background: #ef4444;
  color: #fff;
}

.nav-pill.warn {
  background: #f59e0b;
  color: #fff;
}

.nav-pill.info {
  background: #38bdf8;
  color: #0f172a;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 12px;
  margin-top: 12px;
}

.sys-stat {
  font-size: 11.5px;
  font-weight: 600;
  color: #e2e8f0;
}

.sys-sub {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}

/* MAIN AREA */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 13px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-menu-btn {
  display: none;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
}

.page-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--navy);
}

.page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.role-switcher {
  display: inline-flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
}

.role-btn {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.role-btn.active {
  background: var(--navy);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
}

#btnRoleSales.active {
  background: #15803d;
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.security-strip {
  padding: 8px 24px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.security-strip.admin-mode {
  background: #eff6ff;
  color: #1e3a8a;
}

.security-strip.sales-mode {
  background: #f0fdf4;
  color: #14532d;
}

.sec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2563eb;
  flex-shrink: 0;
}

.security-strip.sales-mode .sec-dot {
  background: #16a34a;
}

.content-body {
  padding: 20px 24px 36px;
  max-width: 1560px;
  width: 100%;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-success {
  background: #15803d;
  color: #fff;
}

.btn-success:hover {
  background: #166534;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
}

.btn-outline {
  background: #fff;
  border-color: #cbd5e1;
  color: #1e293b;
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-ghost {
  background: #f1f5f9;
  color: #475569;
}

.btn-ghost:hover {
  background: #e2e8f0;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 11.5px;
  border-radius: 5px;
}

/* KPI GRID */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.1);
}

.kpi-card.danger {
  border-left-color: #dc2626;
}

.kpi-card.warn {
  border-left-color: #d97706;
}

.kpi-card.success {
  border-left-color: #16a34a;
}

.kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.kpi-link {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  text-transform: none;
}

.kpi-val {
  font-size: 21px;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 7px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 5px;
}

/* CARDS & TABLES */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.section-hdr {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: #f8fafc;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
}

.section-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.input-ctrl, .select-ctrl {
  padding: 7px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-main);
  background: #fff;
}

.input-ctrl:focus, .select-ctrl:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data-table th {
  background: #1e3a5f;
  color: #ffffff;
  font-weight: 600;
  padding: 10px 11px;
  text-align: left;
  white-space: nowrap;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

table.data-table td {
  padding: 9px 11px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}

table.data-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

table.data-table tbody tr:hover {
  background: #eff6ff;
}

.num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.center {
  text-align: center !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
  font-size: 12px;
  color: var(--navy);
}

.snapshot-cell {
  background: #fffbeb !important;
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success-tx);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn-tx);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger-tx);
}

.badge-info {
  background: var(--info-bg);
  color: var(--info-tx);
}

.badge-neutral {
  background: #e2e8f0;
  color: #334155;
}

/* CREDIT PROGRESS BAR */
.progress-track {
  width: 120px;
  height: 8px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}

.progress-fill {
  height: 100%;
  background: #16a34a;
  border-radius: 99px;
}

.progress-fill.warn {
  background: #d97706;
}

.progress-fill.danger {
  background: #dc2626;
}

/* QUOTE CALCULATOR GRID */
.calc-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 18px;
  padding: 18px;
}

.calc-result-panel {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #64748b;
}

.modal-body {
  padding: 18px 20px;
}

.modal-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* TOAST */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  border-left: 4px solid #38bdf8;
}

.toast.error {
  border-left-color: #ef4444;
  background: #7f1d1d;
}

.toast.success {
  border-left-color: #22c55e;
}

.two-col-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.loading-box {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  font-weight: 600;
}

@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    left: -280px;
    transition: left 0.2s ease;
  }
  .sidebar.open {
    left: 0;
  }
  .mobile-menu-btn {
    display: inline-block;
  }
  .calc-grid, .two-col-split, .form-grid {
    grid-template-columns: 1fr;
  }
}
