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

:root {
  --bg:        #0b0f1a;
  --surface:   #111827;
  --surface2:  #1a2236;
  --surface3:  #222d45;
  --border:    #2a3a55;
  --accent:    #3b82f6;
  --accent2:   #6366f1;
  --green:     #10b981;
  --red:       #ef4444;
  --orange:    #f59e0b;
  --purple:    #8b5cf6;
  --text:      #e2e8f0;
  --text-dim:  #94a3b8;
  --text-muted:#475569;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --radius:    12px;
}

html, body { height: 100%; font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── LOGIN ───────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 40% 20%, rgba(59,130,246,0.12) 0%, transparent 60%), var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 44px 36px; width: 380px; box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .icon { width: 60px; height: 60px; background: linear-gradient(135deg, var(--accent), var(--accent2)); border-radius: 16px; margin: 0 auto 14px; display: flex; align-items: center; justify-content: center; font-size: 26px; }
.login-logo h1 { font-size: 22px; font-weight: 700; }
.login-logo p { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; letter-spacing: 0.5px; text-transform: uppercase; }
.form-group input { width: 100%; padding: 11px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; outline: none; transition: border-color .2s, box-shadow .2s; }
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.form-group input::placeholder { color: var(--text-muted); }
.btn-login { width: 100%; padding: 12px; background: var(--accent); border: none; border-radius: 8px; color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; transition: all .2s; margin-top: 4px; }
.btn-login:hover { background: #2563eb; transform: translateY(-1px); }
.btn-login:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.error-msg { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; display: none; }

/* ─── APP LAYOUT ─────────────────────────────────── */
.app { display: grid; grid-template-rows: 56px 1fr; min-height: 100vh; }

/* ─── TOPBAR ──────────────────────────────────────── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50; }
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; margin-right: auto; }
.brand-icon { width: 32px; height: 32px; background: linear-gradient(135deg, var(--accent), var(--accent2)); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.topbar-badge { font-size: 11px; background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); padding: 2px 8px; border-radius: 20px; }
.btn-refresh, .btn-logout { padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); transition: all .15s; }
.btn-refresh { background: var(--surface2); color: var(--text-dim); }
.btn-refresh:hover { color: var(--text); border-color: var(--accent); }
.btn-refresh.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-logout { background: transparent; color: var(--text-muted); }
.btn-logout:hover { color: var(--red); border-color: var(--red); }
.last-updated { font-size: 11px; color: var(--text-muted); }

/* ─── MAIN ────────────────────────────────────────── */
.main { padding: 24px; overflow-y: auto; }
.section-title { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 12px; }

/* ─── CARDS GRID ─────────────────────────────────── */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; position: relative; overflow: hidden; transition: border-color .2s; }
.card:hover { border-color: var(--accent); }
.card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
.card.blue::before  { background: var(--accent); }
.card.green::before { background: var(--green); }
.card.red::before   { background: var(--red); }
.card.orange::before{ background: var(--orange); }
.card.purple::before{ background: var(--purple); }
.card-label { font-size: 11px; color: var(--text-muted); font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 8px; }
.card-value { font-size: 22px; font-weight: 700; line-height: 1.1; margin-bottom: 4px; }
.card-value.rp { font-size: 16px; }
.card-sub { font-size: 11px; color: var(--text-dim); }
.card-icon { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 28px; opacity: .15; }

/* ─── GRID LAYOUTS ───────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; margin-bottom: 22px; }
.grid-ai { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 800px) { .grid-2, .grid-3, .grid-ai { grid-template-columns: 1fr; } }

/* ─── PANEL ───────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-title { font-size: 13px; font-weight: 600; }
.panel-sub { font-size: 11px; color: var(--text-muted); }

/* ─── CHART CONTAINER ────────────────────────────── */
.chart-wrap { position: relative; }
.chart-wrap canvas { max-height: 240px; }

/* ─── TABLE ───────────────────────────────────────── */
.table-wrap { overflow-x: auto; max-height: 360px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { position: sticky; top: 0; z-index: 1; }
thead th { background: var(--surface2); padding: 10px 12px; text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted); letter-spacing: .5px; text-transform: uppercase; white-space: nowrap; border-bottom: 1px solid var(--border); }
tbody tr { border-bottom: 1px solid rgba(42,58,85,.5); transition: background .1s; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 10px 12px; color: var(--text); vertical-align: middle; }
.td-desc { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }

/* ─── BADGE ───────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-paid    { background: rgba(16,185,129,.15); color: #34d399; }
.badge-unpaid  { background: rgba(239,68,68,.12); color: #f87171; }
.badge-partial { background: rgba(245,158,11,.12); color: #fbbf24; }
.badge-pending { background: rgba(148,163,184,.1); color: var(--text-dim); }
.badge-approved { background: rgba(59,130,246,.12); color: #93c5fd; }

/* ─── BUDGET BAR ─────────────────────────────────── */
.budget-item { margin-bottom: 14px; }
.budget-item:last-child { margin-bottom: 0; }
.budget-row { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 12px; }
.budget-name { font-weight: 500; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.budget-pct { color: var(--text-muted); }
.budget-bar-bg { background: var(--surface2); border-radius: 3px; height: 5px; overflow: hidden; }
.budget-bar-fill { height: 100%; border-radius: 3px; transition: width .5s; }

/* ─── MONTH FILTER BAR ───────────────────────────── */
.mf-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 18px; }
.mf-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-right: 4px; white-space: nowrap; }
.mf-pill { padding: 4px 12px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface2); color: var(--text-dim); font-size: 12px; font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap; }
.mf-pill:hover { border-color: var(--accent); color: var(--accent); }
.mf-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mf-all { font-weight: 600; }
.mf-all.active { background: var(--surface3); border-color: var(--text-muted); color: var(--text); }
.mf-count { font-size: 11px; color: var(--text-muted); margin-left: 6px; }

/* ─── AI EXECUTIVE SUMMARY ───────────────────────── */
.ai-summary-content { font-size: 13px; line-height: 1.7; color: var(--text-dim); white-space: pre-wrap; max-height: 340px; overflow-y: auto; }
.ai-summary-content.loading { color: var(--text-muted); font-style: italic; }
.summary-controls { display: flex; align-items: center; gap: 8px; }
.summary-month-select { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 12px; padding: 6px 10px; outline: none; cursor: pointer; max-width: 160px; }
.summary-month-select:focus { border-color: var(--accent2); }
.btn-gen-ai { padding: 6px 12px; background: var(--accent2); border: none; border-radius: 6px; color: #fff; font-size: 12px; font-weight: 600; cursor: pointer; transition: all .15s; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn-gen-ai:hover { background: #5254c8; }
.btn-gen-ai:disabled { opacity: .5; cursor: not-allowed; }

/* ─── CHAT ────────────────────────────────────────── */
.chat-messages { height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; padding-right: 4px; }
.chat-msg { max-width: 88%; }
.chat-msg.user { align-self: flex-end; }
.chat-msg.bot  { align-self: flex-start; }
.chat-bubble { padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.5; }
.chat-msg.user .chat-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg.bot .chat-bubble  { background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 3px; }
.chat-empty { align-self: center; color: var(--text-muted); font-size: 12px; margin-top: 40px; text-align: center; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input { flex: 1; padding: 10px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; font-family: inherit; outline: none; transition: border-color .2s; }
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }
.btn-chat-send { padding: 10px 16px; background: var(--accent); border: none; border-radius: 8px; color: #fff; font-size: 16px; cursor: pointer; transition: background .15s; }
.btn-chat-send:hover { background: #2563eb; }
.btn-chat-send:disabled { opacity: .4; cursor: not-allowed; }
.chat-disclaimer { font-size: 11px; color: var(--text-muted); text-align: center; margin-top: 8px; }

.chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.suggestion-chip { padding: 5px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; color: var(--text-dim); font-size: 11px; cursor: pointer; transition: all .15s; white-space: nowrap; }
.suggestion-chip:hover { border-color: var(--accent); color: var(--accent); background: rgba(59,130,246,.08); }

.btn-clear-chat { padding: 5px 10px; background: transparent; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font-size: 13px; cursor: pointer; transition: all .15s; }
.btn-clear-chat:hover { border-color: var(--red); color: var(--red); }
.btn-export-xlsx { padding: 6px 12px; background: #1a7a4a; border: none; border-radius: 6px; color: #fff; font-size: 12px; font-weight: 600; cursor: pointer; transition: all .15s; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn-export-xlsx:hover { background: #15a05e; }
.btn-export-xlsx:disabled { opacity: .5; cursor: not-allowed; }

/* Markdown dalam chat */
.chat-bubble strong { color: var(--text); font-weight: 600; }
.chat-bubble em { color: var(--text-dim); }
.chat-bubble code { background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 3px; font-family: monospace; font-size: 12px; }
.chat-bubble ul, .chat-bubble ol { padding-left: 16px; margin: 4px 0; }
.chat-bubble li { margin: 2px 0; }
.chat-bubble .chat-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12px; border-radius: 6px; overflow: hidden; }
.chat-bubble .chat-table th { background: rgba(59,130,246,.15); padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); font-weight: 600; color: var(--text); white-space: nowrap; }
.chat-bubble .chat-table td { padding: 6px 10px; border-bottom: 1px solid rgba(42,58,85,.5); color: var(--text-dim); }
.chat-bubble .chat-table tr:last-child td { border-bottom: none; }
.chat-bubble .chat-table tr:hover td { background: rgba(255,255,255,.03); }
.chat-bubble ul { margin: 6px 0; padding-left: 18px; }
.chat-bubble ol { margin: 6px 0; padding-left: 18px; }
.chat-bubble li { margin: 3px 0; line-height: 1.5; }

/* ─── PIVOT TABLE ────────────────────────────────── */
.pivot-panel { margin-bottom: 22px; }
.pivot-wrap  { }  /* no overflow here — scroll is on .pivot-scroll-container */
.pivot-scroll-container { overflow-x: auto; max-height: 460px; overflow-y: auto; }

/* ── filter bar ── */
.pf-bar   { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; margin-bottom: 14px; padding: 10px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; }
.pf-group { display: flex; align-items: center; gap: 8px; }
.pf-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
.pf-select { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 12px; padding: 5px 10px; outline: none; cursor: pointer; }
.pf-select:focus { border-color: var(--accent); }
.pf-btns  { display: flex; gap: 5px; }
.pf-btn   { padding: 4px 11px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface); color: var(--text-dim); font-size: 12px; font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap; }
.pf-btn:hover                 { border-color: var(--accent); color: var(--accent); }
.pf-btn.active                { background: var(--accent); border-color: var(--accent); color: #fff; }
.pf-btn.ind-naik.active       { background: #10b981; border-color: #10b981; }
.pf-btn.ind-naik:not(.active):hover { border-color: #10b981; color: #10b981; }
.pf-btn.ind-turun.active      { background: #ef4444; border-color: #ef4444; }
.pf-btn.ind-turun:not(.active):hover { border-color: #ef4444; color: #ef4444; }
.pf-btn.ind-sama.active       { background: #64748b; border-color: #64748b; }
.pf-count { font-size: 11px; color: var(--text-muted); margin-left: auto; }

/* ── indicator badges ── */
.piv-ind      { display: inline-block; font-size: 11px; font-weight: 700; margin-left: 4px; vertical-align: middle; }
.piv-ind.naik  { color: #34d399; }
.piv-ind.turun { color: #f87171; }
.piv-ind.sama  { color: #64748b; }

/* ── active column highlight ── */
.pt-col-active { background: rgba(59,130,246,.07) !important; }

.pivot-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 12px;
}

.pivot-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1a2236;
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .4px;
  text-transform: uppercase;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.pivot-table thead th.pt-month,
.pivot-table thead th.pt-grand { text-align: right; }

/* frozen column widths — must match exactly for left offsets */
.pt-divisi  { width: 60px; min-width: 60px; }
.pt-acc     { width: 70px; min-width: 70px; }
.pt-budget  { width: 160px; min-width: 160px; }
.pt-month   { min-width: 115px; }
.pt-grand   { min-width: 125px; }

/* freeze header: divisi, acc, budget */
.pivot-table thead th.pt-divisi { position: sticky; left: 0;    z-index: 3; }
.pivot-table thead th.pt-acc    { position: sticky; left: 60px; z-index: 3; }
.pivot-table thead th.pt-budget { position: sticky; left: 130px; z-index: 3; box-shadow: 2px 0 6px rgba(0,0,0,.35); }

.pt-td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(42,58,85,.45);
  color: var(--text);
  vertical-align: middle;
}

/* freeze body cells: divisi, acc, budget */
.pt-td-divisi {
  position: sticky;
  left: 0;
  z-index: 1;
  font-weight: 600;
  color: var(--accent);
  background: #111827;
  border-right: 1px solid var(--border);
  vertical-align: top;
}
.pt-td-acc {
  position: sticky;
  left: 60px;
  z-index: 1;
  background: #111827;
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
}
.pt-td-budget {
  position: sticky;
  left: 130px;
  z-index: 1;
  background: #111827;
  color: var(--text-dim);
  box-shadow: 2px 0 6px rgba(0,0,0,.35);
}

.pt-td-num    { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pt-empty     { color: var(--text-muted); }
.pt-row-total {
  font-weight: 600;
  color: var(--text);
  border-left: 1px solid var(--border);
  background: rgba(255,255,255,.02);
}

.pivot-table tbody tr:hover .pt-td { background: rgba(255,255,255,.025); }
.pivot-table tbody tr:hover .pt-td-divisi { background: rgba(26,34,54,.95); }
.pivot-table tbody tr:hover .pt-td-acc    { background: rgba(26,34,54,.95); }
.pivot-table tbody tr:hover .pt-td-budget { background: rgba(26,34,54,.95); }

.pt-grand-row .pt-td {
  background: #1a2032;
  font-weight: 700;
  color: var(--text);
  border-top: 2px solid var(--border);
  border-bottom: none;
}
.pt-grand-row .pt-td-divisi,
.pt-grand-row .pt-td-acc,
.pt-grand-row .pt-td-budget { background: #1a2032; }
.pt-grand-label { letter-spacing: .5px; text-transform: uppercase; font-size: 11px; }

/* ─── LOADING SKELETON ───────────────────────────── */
.skeleton { animation: shimmer 1.5s infinite; background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%); background-size: 200% 100%; border-radius: 4px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ─── TOAST ───────────────────────────────────────── */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 11px 16px; font-size: 13px; box-shadow: var(--shadow); z-index: 200; opacity: 0; transform: translateY(8px); transition: all .2s; max-width: 300px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(239,68,68,.4); color: #fca5a5; }
.toast.success { border-color: rgba(16,185,129,.4); color: #6ee7b7; }
