:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #e2e8e4;
  --text: #13221c;
  --muted: #5c7067;
  --primary: #059669;
  --primary-dark: #065f46;
  --primary-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(6, 78, 59, 0.06);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.text-muted { color: var(--muted); }
.text-green { color: var(--primary); }
.text-red { color: var(--danger); }
.text-warn { color: var(--warn); }
.text-blue { color: var(--blue); }
.text-right { text-align: right; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

/* App Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 244px; flex-shrink: 0;
  background: linear-gradient(180deg, #064e3b 0%, #04372a 100%);
  color: #ecfdf5; padding: 18px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: rgba(255,255,255,0.14); display: grid; place-items: center; font-size: 20px;
}
.brand-title { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: #a7f3d0; }
.nav-list { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; flex: 1; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: 0; color: #d1fae5;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  font-family: inherit; font-size: 13.5px; font-weight: 500; text-align: left;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-btn.active { background: #10b981; color: #fff; font-weight: 700; box-shadow: 0 4px 12px rgba(16,185,129,0.3); }
.sidebar-footer { padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.12); display: flex; flex-direction: column; gap: 8px; }
.user-pill { font-size: 12px; color: #a7f3d0; background: rgba(255,255,255,0.08); padding: 7px 10px; border-radius: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .btn-outline { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid rgba(255,255,255,0.22); }
.sidebar .btn-outline:hover { background: rgba(255,255,255,0.18); }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.mobile-brand { display: none; font-weight: 800; font-size: 15px; color: var(--primary-dark); }
.month-picker { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); padding: 3px 6px; border-radius: 10px; }
.month-picker input[type=month] { border: 0; background: transparent; font-family: inherit; font-weight: 600; font-size: 13px; color: var(--text); outline: none; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.content { padding: 20px; max-width: 1320px; width: 100%; margin: 0 auto; }
.loading-box { padding: 60px; text-align: center; color: var(--muted); }

/* Buttons */
button { font-family: inherit; }
.btn-primary {
  background: var(--primary); color: #fff; border: 0; border-radius: 10px;
  padding: 8px 14px; font-weight: 600; font-size: 13px; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-ai {
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; border: 0;
  border-radius: 10px; padding: 8px 13px; font-weight: 600; font-size: 13px; cursor: pointer;
}
.btn-ai:hover { filter: brightness(1.06); }
.btn-ghost {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-weight: 600; font-size: 13px; cursor: pointer;
}
.btn-ghost:hover { background: #e9f1ed; }
.btn-outline {
  background: #fff; color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 12px; font-weight: 600; font-size: 12.5px; cursor: pointer;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary-dark); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca; border-radius: 9px; padding: 6px 11px; font-weight: 600; font-size: 12px; cursor: pointer; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; cursor: pointer; display: inline-grid; place-items: center; font-size: 14px;
}
.icon-btn:hover { background: #eaf2ee; }

/* Cards & Grids */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--primary)); }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; }
.kpi-value { font-size: 22px; font-weight: 800; margin-top: 6px; letter-spacing: -0.02em; }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; }
.grid-eq-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Badges & Pills */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.b-red { background: var(--danger-soft); color: var(--danger); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-green { background: var(--primary-soft); color: var(--primary-dark); }
.b-blue { background: var(--blue-soft); color: var(--blue); }
.b-gray { background: #eef2f0; color: #475569; }

/* Filter Bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.inp, select.inp, textarea.inp {
  background: #fff; border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 10px; font-family: inherit; font-size: 13px; color: var(--text); outline: none;
}
.inp:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(5,150,105,0.12); }
.inp-xs { padding: 4px 8px; border-radius: 7px; border: 1px solid var(--border); font-size: 12px; font-family: inherit; }

/* Tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: #f2f6f4; color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; padding: 9px 9px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 9px; border-bottom: 1px solid #eef2f0; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafdfb; }

/* Progress Bars */
.pbar { height: 9px; background: #e8eeeb; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.pbar-fill { height: 100%; border-radius: 99px; transition: width .3s ease; }

/* Tabs Switcher */
.seg-tabs { display: inline-flex; background: #e9f0ec; padding: 3px; border-radius: 10px; gap: 2px; }
.seg-btn { border: 0; background: transparent; padding: 6px 13px; border-radius: 8px; font-weight: 600; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.seg-btn.active { background: #fff; color: var(--primary-dark); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

/* Charts */
.chart-box { width: 100%; overflow-x: auto; }
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.legend-list { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 7px; }
.legend-item { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; gap: 8px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 26, 20, 0.48); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 16px;
}
.modal-box {
  background: #fff; border-radius: 16px; width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto; padding: 20px 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.22);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-title { font-size: 16px; font-weight: 800; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }

/* AI Drawer */
.drawer-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(10, 26, 20, 0.4); display: flex; justify-content: flex-end; }
.ai-drawer { width: 460px; max-width: 100vw; background: #fff; height: 100%; display: flex; flex-direction: column; box-shadow: -8px 0 32px rgba(0,0,0,0.16); }
.drawer-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.drawer-title { font-size: 15px; font-weight: 800; }
.drawer-sub { font-size: 11.5px; color: var(--muted); }
.ai-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #f8faf9; }
.ai-msg { max-width: 92%; padding: 10px 13px; border-radius: 13px; font-size: 13px; white-space: pre-wrap; }
.ai-msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.ai-msg.model { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.ai-prop { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: 6px; }
.ai-op { background: var(--primary-soft); border: 1px solid #bbf7d0; padding: 6px 9px; border-radius: 8px; font-size: 12px; }
.ai-foot { padding: 10px 12px; border-top: 1px solid var(--border); background: #fff; }
.ai-input-row { display: flex; gap: 6px; align-items: flex-end; }
.ai-input-row textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-family: inherit; font-size: 13px; outline: none; }
.ai-file-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.file-chip { background: var(--blue-soft); color: var(--blue); padding: 3px 8px; border-radius: 8px; font-size: 11.5px; display: inline-flex; align-items: center; gap: 5px; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90;
  background: #064e3b; color: #fff; padding: 10px 18px; border-radius: 12px;
  font-weight: 600; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,0.22);
}

/* Bottom Nav (Mobile) */
.bottom-nav { display: none; }

@media (max-width: 960px) {
  .sidebar { display: none; }
  .mobile-brand { display: flex; align-items: center; gap: 6px; }
  .hide-sm { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-2, .grid-eq-2, .grid-3 { grid-template-columns: 1fr; }
  .content { padding: 14px 12px 84px; }
  .topbar { padding: 8px 12px; }
  .kpi-value { font-size: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: #fff; border-top: 1px solid var(--border);
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
  }
  .bnav-btn {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    border: 0; background: transparent; color: var(--muted); font-size: 18px; padding: 4px 0; cursor: pointer;
  }
  .bnav-btn small { font-size: 10.5px; font-weight: 600; }
  .bnav-btn.active { color: var(--primary); }
}
