/* ─── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --sidebar-width: 240px;
  --sidebar-bg: #1a1f2e;
  --sidebar-text: #a8b2c8;
  --sidebar-active: #4f8ef7;
  --header-height: 56px;
  --primary: #4f8ef7;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --card-radius: 12px;
}

/* ─── Base ───────────────────────────────────────────────────────────────────── */
body {
  background: #f0f2f7;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  color: #fff;
  font-size: 1rem;
}

.sidebar .nav-link {
  color: var(--sidebar-text);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  margin: 2px 8px;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.sidebar .nav-link i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar .nav-link:hover {
  background: rgba(255,255,255,0.07);
  color: #fff;
}

.sidebar .nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.sidebar button.nav-link {
  width: calc(100% - 16px);
  border: 0;
  background: transparent;
  text-align: left;
}

.sidebar button.nav-link.active {
  background: rgba(255,255,255,0.07);
}

.nav-group-caret {
  margin-left: auto;
  font-size: 0.85rem !important;
  transition: transform 0.2s;
}

.nav-group-toggle[aria-expanded="true"] .nav-group-caret {
  transform: rotate(180deg);
}

.nav-submenu {
  display: none;
  padding: 0.1rem 0 0.25rem;
}

.nav-submenu.show {
  display: block;
}

.sidebar .nav-sub-link {
  margin-left: 1.9rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.84rem;
  width: auto;
}

.sidebar .nav-sub-link i {
  font-size: 1rem;
  width: 18px;
}

.nav-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: rgba(168, 178, 200, 0.5);
  padding: 0.75rem 1.25rem 0.25rem;
  text-transform: uppercase;
}

.sidebar-footer {
  padding: 0.5rem 0;
  border-top: 1px solid rgba(255,255,255,0.07);
  margin-top: auto;
  flex-shrink: 0;
}

/* ─── Main Content ───────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.page-header {
  background: #fff;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e8ecf0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.page-body {
  padding: 1.5rem;
}

/* ─── Mobile ─────────────────────────────────────────────────────────────────── */
.mobile-nav {
  background: var(--sidebar-bg);
  height: var(--header-height);
  position: sticky;
  top: 0;
  z-index: 1050;
}

@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
    height: calc(100vh - var(--header-height));
    z-index: 1040;
    padding-bottom: 1rem;
  }
  .sidebar.show {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .page-body {
    padding: 1rem;
  }
}

/* ─── KPI Cards ─────────────────────────────────────────────────────────────── */
.kpi-card {
  background: #fff;
  border-radius: var(--card-radius);
  padding: 1.1rem;
  height: 100%;
  border-left: 4px solid #ccc;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: transform 0.2s, box-shadow 0.2s;
}

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

.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6c757d;
  margin-bottom: 0.4rem;
}

.kpi-value {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.kpi-sub {
  font-size: 0.72rem;
  color: #9ca3af;
}

.kpi-positive { border-left-color: #28a745; }
.kpi-positive .kpi-value { color: #28a745; }

.kpi-negative { border-left-color: #dc3545; }
.kpi-negative .kpi-value { color: #dc3545; }

.kpi-info { border-left-color: #0d6efd; }
.kpi-info .kpi-value { color: #0d6efd; }

.kpi-success { border-left-color: #20c997; }
.kpi-success .kpi-value { color: #20c997; }

.kpi-warning { border-left-color: #ffc107; }
.kpi-warning .kpi-value { color: #fd7e14; }

.kpi-danger { border-left-color: #dc3545; }
.kpi-danger .kpi-value { color: #dc3545; }

.kpi-income { border-left-color: #198754; }
.kpi-income .kpi-value { color: #198754; }

.kpi-income-light { border-left-color: #20c997; }
.kpi-income-light .kpi-value { color: #20c997; }

.kpi-expense { border-left-color: #fd7e14; }
.kpi-expense .kpi-value { color: #fd7e14; }

.kpi-expense-dark { border-left-color: #dc3545; }
.kpi-expense-dark .kpi-value { color: #dc3545; }

/* ─── Mini KPI ───────────────────────────────────────────────────────────────── */
.mini-kpi {
  border-radius: 8px;
}

/* ─── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  border: none;
  border-radius: var(--card-radius);
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #f0f2f7;
  padding: 0.85rem 1rem;
  border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
}

/* ─── Tables ─────────────────────────────────────────────────────────────────── */
.table th {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6c757d;
  white-space: nowrap;
}

.table td {
  font-size: 0.88rem;
  vertical-align: middle;
}

.table-danger-light {
  background-color: rgba(220, 53, 69, 0.05) !important;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn-xs {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  line-height: 1.5;
  border-radius: 6px;
}

/* ─── Login ──────────────────────────────────────────────────────────────────── */
.login-bg {
  background: linear-gradient(135deg, #1a1f2e 0%, #2d3a5a 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  border: none;
}

.login-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--primary), #6366f1);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 2rem;
}

/* ─── Badges ─────────────────────────────────────────────────────────────────── */
.bg-purple-subtle {
  background-color: rgba(111, 66, 193, 0.1) !important;
}
.text-purple {
  color: #6f42c1 !important;
}

/* ─── Instructions ─────────────────────────────────────────────────────────── */
.instruction-anchor {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 56px;
  padding: 0.85rem 1rem;
  background: #fff;
  border: 1px solid #e8ecf0;
  border-radius: 8px;
  color: #1f2937;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.instruction-anchor:hover {
  color: var(--primary);
  border-color: rgba(79, 142, 247, 0.35);
}

.instruction-anchor i {
  color: var(--primary);
  font-size: 1.15rem;
}

.instruction-section {
  margin-bottom: 1.5rem;
}

.instruction-heading {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

.instruction-heading i {
  font-size: 1.35rem;
  margin-top: 0.1rem;
}

.instruction-heading h5 {
  margin: 0;
  font-weight: 700;
}

.instruction-heading p {
  margin: 0.15rem 0 0;
  color: #6c757d;
}

.instruction-card {
  height: 100%;
  background: #fff;
  border: 1px solid #e8ecf0;
  border-left: 4px solid #cfd6df;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.instruction-title {
  font-weight: 700;
  margin-bottom: 0.45rem;
  color: #1f2937;
}

.instruction-card p {
  margin: 0;
  color: #4b5563;
  line-height: 1.45;
}

.instruction-list {
  margin: 0;
  padding-left: 1.1rem;
  color: #4b5563;
}

.instruction-list li + li {
  margin-top: 0.35rem;
}

.instruction-note {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  background: #f8fafc;
  border: 1px solid #e8ecf0;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  color: #374151;
}

.instruction-note i {
  color: #198754;
  font-size: 1.1rem;
}

/* ─── Support ──────────────────────────────────────────────────────────────── */
.support-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.support-actions .btn {
  min-height: 38px;
}

/* ─── Sidebar overlay on mobile ──────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1030;
  top: var(--header-height);
}

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

/* ─── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c9d4; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0aab4; }

/* ─── Responsive table ───────────────────────────────────────────────────────── */
@media (max-width: 576px) {
  .kpi-value { font-size: 1.1rem; }
  .kpi-label { font-size: 0.65rem; }
  .page-header { padding: 0.75rem 1rem; }
}

/* ─── Mobile content fix ─────────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  /* Prevent page from overflowing horizontally */
  .main-content {
    min-width: 0;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Filter form wraps instead of overflowing */
  .card-body form.d-flex {
    flex-wrap: wrap !important;
  }
  .card-body form.d-flex select,
  .card-body form.d-flex input[type="text"] {
    flex: 1 1 120px;
    min-width: 100px;
    max-width: 100%;
  }

  /* Tables scroll horizontally inside their container */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
  }

  /* Action buttons stack tighter on small screens */
  .table td .d-flex.gap-1 {
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Modal full-width on mobile */
  .modal-dialog {
    margin: 0.5rem;
  }

  .support-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .support-actions .btn {
    width: 100%;
  }
}
