:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --sidebar-w: 250px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.boot-loader {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; gap: 16px; color: var(--muted);
}
.spinner {
  width: 38px; height: 38px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Layout ---------------- */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0;
  z-index: 50; overflow-y: auto; transition: transform .25s ease;
}
.sidebar-brand {
  padding: 18px 20px; font-size: 19px; font-weight: 700; color: #fff;
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 15px; flex: 0 0 auto;
}
.sidebar-nav { flex: 1; padding: 10px 0 24px; }
.nav-group-title {
  padding: 14px 20px 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .07em; color: #64748b; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 20px;
  color: var(--sidebar-text); text-decoration: none; font-size: 14px;
  border-left: 3px solid transparent; cursor: pointer; transition: background .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(37,99,235,.18); color: #fff; border-left-color: var(--primary); font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; flex: 0 0 auto; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff; font-size: 11px;
  padding: 1px 7px; border-radius: 10px; font-weight: 700;
}

.main-area { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 58px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-spacer { flex: 1; }
.hamburger {
  display: none; background: none; border: none; font-size: 21px; cursor: pointer;
  color: var(--text); padding: 6px 8px; border-radius: 8px;
}
.hamburger:hover { background: var(--bg); }

.content { padding: 20px; flex: 1; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5);
  z-index: 45;
}
.sidebar-overlay.show { display: block; }

/* ---------------- Cards ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { font-size: 15px; font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

.page-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-head h1 { font-size: 22px; font-weight: 700; }
.page-head .spacer { flex: 1; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------------- KPI ---------------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow); border-left: 4px solid var(--primary);
}
.kpi.success { border-left-color: var(--success); }
.kpi.danger  { border-left-color: var(--danger); }
.kpi.warning { border-left-color: var(--warning); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-size: 23px; font-weight: 700; margin-top: 6px; word-break: break-word; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: #334155; }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
  width: 100%; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.field textarea { resize: vertical; min-height: 72px; }
.field-hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; color: var(--danger); font-weight: 600; }
.checkbox-row { display: flex; align-items: center; gap: 9px; padding-top: 24px; }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--primary); }
.checkbox-row label { font-size: 13px; font-weight: 500; }

.form-actions {
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;
  padding-top: 16px; border-top: 1px solid var(--border); flex-wrap: wrap;
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.93); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-icon { padding: 6px 9px; }
.btn-block { width: 100%; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 11px 14px; background: #f8fafc; font-weight: 600;
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #475569;
  border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.clickable { cursor: pointer; }

/* ---------------- Badges ---------------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-muted   { background: #f1f5f9; color: #64748b; }

/* ---------------- States ---------------- */
.empty-state { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty-state .icon { font-size: 42px; margin-bottom: 10px; opacity: .35; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; font-weight: 600; }
.empty-state p { font-size: 13.5px; max-width: 420px; margin: 0 auto 14px; }

.loading { padding: 46px; text-align: center; color: var(--muted); }
.loading .spinner { margin: 0 auto 12px; }

.alert {
  padding: 11px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 14px;
  display: flex; gap: 9px; align-items: flex-start; font-weight: 500;
}
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------------- Notifications ---------------- */
.notif-list { display: flex; flex-direction: column; }
.notif {
  display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid #f1f5f9;
  align-items: flex-start;
}
.notif:last-child { border-bottom: none; }
.notif-bullet {
  width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: 0 0 auto;
  background: var(--muted);
}
.notif.danger .notif-bullet  { background: var(--danger); }
.notif.warning .notif-bullet { background: var(--warning); }
.notif.info .notif-bullet    { background: var(--primary); }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: 13.5px; font-weight: 600; }
.notif-desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 12px; width: 100%; max-width: 760px;
  max-height: 92vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 40px rgba(15,23,42,.25); animation: modalIn .18s ease;
}
.modal.narrow { max-width: 460px; }
.modal.wide { max-width: 1000px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.99); } }
.modal-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.modal-head h2 { font-size: 17px; font-weight: 700; }
.modal-head .spacer { flex: 1; }
.modal-close {
  background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted);
  line-height: 1; padding: 2px 7px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
}

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 15px; font-size: 14px; font-weight: 600; color: var(--muted);
  background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; white-space: nowrap; font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------------- Toolbar ---------------- */
.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px;
}
.toolbar .search-input { flex: 1; min-width: 200px; max-width: 380px; }
.toolbar input, .toolbar select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
  font-family: inherit; background: #fff;
}
.toolbar .spacer { flex: 1; }

/* ---------------- Pagination ---------------- */
.pagination {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 15px; font-size: 13.5px; color: var(--muted); flex-wrap: wrap;
}

/* ---------------- Login ---------------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
}
.login-card {
  background: #fff; border-radius: 14px; padding: 32px 28px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .logo {
  width: 54px; height: 54px; border-radius: 14px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 25px;
  margin: 0 auto 12px;
}
.login-brand h1 { font-size: 23px; font-weight: 700; }
.login-brand p { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.login-form { display: flex; flex-direction: column; gap: 15px; }

/* ---------------- Chart ---------------- */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding: 10px 0; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
.bar-chart .bar {
  width: 100%; background: var(--primary); border-radius: 4px 4px 0 0;
  min-height: 2px; transition: opacity .15s;
}
.bar-chart .bar:hover { opacity: .8; }
.bar-chart .bar-label { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.bar-stack { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; }

/* ---------------- Search results ---------------- */
.search-results { display: flex; flex-direction: column; gap: 18px; }
.search-group h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: 8px; font-weight: 700;
}
.search-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; cursor: pointer;
  background: #fff;
}
.search-item:hover { border-color: var(--primary); background: #f8fafc; }
.search-item .main { flex: 1; min-width: 0; }
.search-item .t { font-size: 14px; font-weight: 600; }
.search-item .s { font-size: 12.5px; color: var(--muted); }

/* ---------------- Statement ---------------- */
.statement-head {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px; padding: 16px; background: #f8fafc; border-radius: 8px; margin-bottom: 16px;
}
.statement-head .item .lbl { font-size: 11.5px; color: var(--muted); text-transform: uppercase; font-weight: 600; }
.statement-head .item .val { font-size: 17px; font-weight: 700; margin-top: 3px; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.detail-item { }
.detail-item .lbl { font-size: 11.5px; color: var(--muted); text-transform: uppercase; font-weight: 600; }
.detail-item .val { font-size: 14.5px; font-weight: 500; margin-top: 3px; word-break: break-word; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-success { color: var(--success); font-weight: 600; }
.text-warning { color: var(--warning); font-weight: 600; }
.text-muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.hidden { display: none !important; }

/* ---------------- Mobile ---------------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .hamburger { display: block; }
  .content { padding: 14px; }
  .page-head h1 { font-size: 19px; }
  .kpi-value { font-size: 20px; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
  .card-body { padding: 14px; }
}

@media (max-width: 560px) {
  body { font-size: 14px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 17px; }
  .toolbar .search-input { max-width: 100%; }
  .page-head .btn span.txt { display: none; }
  .modal { max-height: 100vh; border-radius: 0; }
  .modal-overlay { padding: 0; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
}

@media print {
  .sidebar, .topbar, .toolbar, .row-actions, .btn { display: none !important; }
  .main-area { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
