:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #283548;
  --fg: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --teal: #14b8a6;
  --teal-soft: rgba(20, 184, 166, 0.16);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, 0.16);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.16);
  --err: #ef4444;
  --err-soft: rgba(239, 68, 68, 0.16);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --fg: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --teal: #0d9488;
  --teal-soft: rgba(13, 148, 136, 0.1);
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, 0.12);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.12);
  --err: #dc2626;
  --err-soft: rgba(220, 38, 38, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: 72px;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}
.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 42px; height: 42px; border-radius: 50%; background: #fff; object-fit: contain; box-shadow: 0 2px 8px rgba(0,0,0,0.22); }
.brand h1 { font-size: 16px; font-weight: 700; line-height: 1.2; }
.brand p { font-size: 11.5px; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Navigation */
.nav-bar {
  max-width: 1120px;
  margin: 12px auto 0;
  padding: 0 16px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-bar::-webkit-scrollbar { display: none; }
.nav-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.nav-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.nav-btn.locked { display: none; }

/* Main */
.main {
  max-width: 1120px;
  margin: 14px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.view { display: none; flex-direction: column; gap: 14px; }
.view.active { display: flex; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.card-title { font-size: 15px; font-weight: 700; }
.sub { font-size: 12px; color: var(--muted); }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.two-col { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

@media (max-width: 820px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .form-grid, .form-grid-2 { grid-template-columns: 1fr; }
}

.kpi-label { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.kpi-val { font-size: 20px; font-weight: 700; font-family: var(--mono); letter-spacing: -0.4px; }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* Pills & Badges */
.pill-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.b-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid rgba(34,197,94,0.3); }
.b-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid rgba(245,158,11,0.3); }
.b-err { background: var(--err-soft); color: var(--err); border: 1px solid rgba(239,68,68,0.3); }
.b-info { background: var(--primary-soft); color: var(--primary); border: 1px solid rgba(59,130,246,0.3); }

/* Buttons & Inputs */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-teal { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-danger { background: var(--err-soft); border-color: var(--err); color: var(--err); }
.btn-sm { padding: 4px 9px; font-size: 11.5px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 13px;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Tables */
.tbl-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--muted);
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 8px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.mono { font-family: var(--mono); }
.strike { text-decoration: line-through; opacity: 0.6; }

/* Chart */
.chart-box { width: 100%; height: 210px; }
.chart-info {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12.5px;
}
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; }

/* Calc summary box */
.calc-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

/* Progress bar */
.bar-track {
  width: 100%; height: 11px; background: var(--surface-2);
  border-radius: 999px; overflow: hidden; display: flex; margin: 8px 0;
}
.bar-a { background: var(--primary); height: 100%; }
.bar-b { background: var(--teal); height: 100%; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(2, 6, 23, 0.78);
  display: none; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-wide { max-width: 780px; max-height: 90vh; overflow-y: auto; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  background: var(--surface); border: 1px solid var(--primary);
  color: var(--fg); padding: 10px 14px; border-radius: 10px;
  font-size: 12.5px; font-weight: 600; display: none;
  max-width: 340px;
}
.toast.show { display: block; }

/* Upload dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
}
.dropzone:hover { border-color: var(--primary); }
.row-list { display: flex; flex-direction: column; gap: 8px; }
.row-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border); gap: 8px;
}
.row-item:last-child { border-bottom: none; padding-bottom: 0; }
.section-div { font-size: 12px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: 0.4px; margin: 10px 0 6px; }

/* Full-screen Cloud Login Gate */
.cloud-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.cloud-gate.open { display: flex; }
.cloud-gate-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.cloud-gate-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cloud-gate-brand img { width: 56px; height: 56px; border-radius: 50%; background: #fff; object-fit: contain; box-shadow: 0 3px 10px rgba(0,0,0,0.25); }
.cloud-gate-brand h2 { font-size: 17px; font-weight: 700; line-height: 1.25; }
.cloud-gate-brand p { font-size: 12px; color: var(--muted); }
