:root {
  --bg: #08090b;
  --panel: #111318;
  --panel-2: #171a20;
  --panel-3: #1d2027;
  --line: #2b2f37;
  --line-soft: rgba(255,255,255,.08);
  --text: #f4f5f7;
  --muted: #9da3ad;
  --brand: #b11218;
  --brand-bright: #e5202c;
  --brand-rgb: 177, 18, 24;
  --red: var(--brand);
  --red-deep: #8f0e13;
  --green: #3bc27a;
  --amber: #f1b34b;
  --blue: #58a6ff;
  --radius: 18px;
  --shadow: 0 24px 70px rgba(0,0,0,.36);
}
.admin-only { display: none; }
body.is-admin .admin-only { display: flex; }
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { display: block; font-size: .68rem; letter-spacing: .18em; font-weight: 800; color: var(--red); text-transform: uppercase; }

.login-view { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 1.15fr) minmax(380px, .85fr); }
.login-visual { position: relative; overflow: hidden; padding: clamp(40px, 7vw, 96px); display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(145deg, #050506 0%, #0d0f13 62%, #15181d 100%); border-right: 1px solid var(--line-soft); }
.login-visual::before { content: ""; position: absolute; inset: auto -8% -34% auto; width: 72%; aspect-ratio: 1; border: 2px solid rgba(var(--brand-rgb),.32); transform: rotate(18deg); box-shadow: 0 0 0 42px rgba(var(--brand-rgb),.035), 0 0 0 100px rgba(var(--brand-rgb),.018); }
.login-logo { width: min(480px, 78%); height: auto; object-fit: contain; mix-blend-mode: screen; position: relative; z-index: 2; }
.login-copy { position: relative; z-index: 2; max-width: 650px; }
.login-copy h1 { margin: .15em 0 0; font-size: clamp(5rem, 12vw, 10rem); letter-spacing: -.08em; line-height: .83; }
.login-copy p { max-width: 560px; margin: 24px 0 0; color: #c1c5cc; font-size: clamp(1.05rem, 1.8vw, 1.35rem); line-height: 1.55; }
.login-grid { position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px); background-size: 64px 64px; mask-image: linear-gradient(to bottom, transparent, #000 70%); }
.login-panel { display: grid; place-items: center; padding: 32px; background: #0b0c0f; }
.auth-card { width: min(440px, 100%); padding: clamp(28px, 5vw, 48px); border: 1px solid var(--line); border-radius: 26px; background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.012)); box-shadow: var(--shadow); }
.auth-card h2 { margin: 8px 0 8px; font-size: 2rem; letter-spacing: -.04em; }
.auth-card p { color: var(--muted); margin: 0 0 26px; line-height: 1.5; }
.auth-mark { width: 62px; height: 62px; border-radius: 16px; overflow: hidden; margin-bottom: 24px; border: 1px solid var(--line); background: #000; }
.auth-mark img { width: 100%; height: 100%; object-fit: cover; }
label { display: grid; gap: 8px; color: #d7d9de; font-size: .88rem; font-weight: 650; }
input, textarea, select { width: 100%; color: var(--text); border: 1px solid var(--line); background: #0c0e12; border-radius: 12px; padding: 12px 14px; outline: none; transition: border-color .2s, box-shadow .2s; }
input:focus, textarea:focus, select:focus { border-color: rgba(var(--brand-rgb),.75); box-shadow: 0 0 0 3px rgba(var(--brand-rgb),.12); }
textarea { min-height: 92px; resize: vertical; }
.auth-card label + label { margin-top: 16px; }
.security-note { display: block; margin-top: 16px; color: #747b86; text-align: center; }

.btn { min-height: 42px; border-radius: 11px; border: 1px solid transparent; padding: 10px 15px; font-weight: 800; color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .18s ease, background .18s ease, border-color .18s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 8px 24px rgba(var(--brand-rgb),.28); }
.btn-primary:hover { background: var(--brand-bright); }
.btn-secondary { background: #171a20; border-color: var(--line); }
.btn-secondary:hover { border-color: #474d58; }
.btn-ghost { background: transparent; border-color: var(--line); color: #d8dbe1; }
.btn-danger { background: rgba(var(--brand-rgb),.12); border-color: rgba(var(--brand-rgb),.25); color: #ff7078; }
.btn-block { width: 100%; margin-top: 24px; }
.btn-small { min-height: 34px; padding: 7px 10px; border-radius: 9px; font-size: .8rem; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; background: transparent; border: 1px solid var(--line); color: #c8cbd1; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line-soft); background: linear-gradient(180deg, #0b0d10, #090a0c); padding: 22px 16px; display: flex; flex-direction: column; z-index: 20; }
.brand-lockup { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; border-bottom: 1px solid var(--line-soft); }
.brand-lockup img { width: 78px; height: 26px; object-fit: cover; object-position: left; mix-blend-mode: screen; }
.brand-lockup div { min-width: 0; }
.brand-lockup strong { display: block; font-size: 1.25rem; letter-spacing: -.04em; }
.brand-lockup span { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.nav-list { display: grid; gap: 7px; margin-top: 22px; }
.nav-item { border: 1px solid transparent; color: #aeb3bc; background: transparent; min-height: 45px; border-radius: 12px; padding: 0 13px; display: flex; align-items: center; gap: 12px; text-align: left; font-weight: 700; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.035); }
.nav-item.active { color: #fff; background: linear-gradient(90deg, rgba(var(--brand-rgb),.18), rgba(var(--brand-rgb),.035)); border-color: rgba(var(--brand-rgb),.2); }
.nav-icon { width: 22px; color: var(--red); font-size: 1.2rem; text-align: center; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line-soft); padding: 18px 4px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-pill { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--red); color: #fff; font-size: .76rem; font-weight: 900; }
.user-pill strong, .user-pill small { display: block; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-pill strong { font-size: .84rem; }
.user-pill small { color: var(--muted); font-size: .65rem; margin-top: 2px; }

.workspace { min-width: 0; background: radial-gradient(circle at 94% 0%, rgba(var(--brand-rgb),.055), transparent 27%), var(--bg); }
.topbar { min-height: 88px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px clamp(20px, 3.2vw, 46px); position: sticky; top: 0; z-index: 15; background: rgba(8,9,11,.88); backdrop-filter: blur(18px); }
.topbar h1 { margin: 4px 0 0; font-size: clamp(1.35rem, 2.2vw, 1.85rem); letter-spacing: -.04em; }
.topbar-actions { display: flex; gap: 10px; align-items: end; }
.month-control { min-width: 170px; gap: 4px; }
.month-control span { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; }
.month-control input { padding: 9px 11px; height: 42px; }
.content { padding: clamp(20px, 3vw, 44px); max-width: 1700px; margin: 0 auto; }

.page-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-head h2 { margin: 0; font-size: 1.25rem; letter-spacing: -.03em; }
.page-head p { margin: 6px 0 0; color: var(--muted); line-height: 1.45; }
.action-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi-card { position: relative; overflow: hidden; min-height: 142px; background: linear-gradient(145deg, rgba(255,255,255,.038), rgba(255,255,255,.015)); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.kpi-card::after { content: ""; position: absolute; width: 100px; height: 100px; border-radius: 50%; background: rgba(var(--brand-rgb),.07); right: -42px; top: -42px; }
.kpi-card .label { color: var(--muted); font-size: .78rem; font-weight: 700; }
.kpi-card strong { display: block; font-size: clamp(1.35rem, 2.5vw, 2rem); letter-spacing: -.055em; margin-top: 18px; }
.kpi-card small { display: block; color: #7f8690; margin-top: 8px; }
.kpi-card.danger strong { color: #ff737b; }
.kpi-card.success strong { color: #65d99a; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, .75fr); gap: 14px; margin-top: 14px; }
.panel { background: linear-gradient(145deg, rgba(255,255,255,.032), rgba(255,255,255,.012)); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.panel-header { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 18px; }
.panel-header h3 { margin: 0; font-size: 1rem; }
.panel-header p { color: var(--muted); margin: 5px 0 0; font-size: .82rem; }
.chart-wrap { height: 286px; position: relative; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.donut-wrap { display: grid; place-items: center; min-height: 210px; }
.donut { width: 166px; height: 166px; border-radius: 50%; display: grid; place-items: center; position: relative; }
.donut::after { content: ""; width: 110px; height: 110px; border-radius: 50%; background: #12151a; position: absolute; }
.donut-center { z-index: 1; text-align: center; }
.donut-center strong { display: block; font-size: 1.8rem; }
.donut-center small { color: var(--muted); }
.legend { display: grid; gap: 9px; margin-top: 12px; }
.legend-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; font-size: .78rem; color: #c9ccd2; }
.legend-row i { width: 8px; height: 8px; border-radius: 50%; }
.legend-row b { color: #fff; }

.table-panel { margin-top: 14px; padding: 0; overflow: hidden; }
.table-toolbar { padding: 17px 18px; border-bottom: 1px solid var(--line-soft); display: flex; gap: 10px; justify-content: space-between; align-items: center; }
.search-box { position: relative; width: min(340px, 100%); }
.search-box input { padding-left: 38px; }
.search-box::before { content: "⌕"; position: absolute; left: 13px; top: 10px; color: var(--muted); z-index: 1; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th { text-align: left; padding: 12px 16px; color: #7f8690; font-size: .67rem; letter-spacing: .08em; text-transform: uppercase; border-bottom: 1px solid var(--line-soft); background: rgba(255,255,255,.018); }
td { padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.055); color: #d9dce1; font-size: .84rem; vertical-align: middle; }
tr:hover td { background: rgba(255,255,255,.018); }
.cell-main strong { display: block; color: #fff; }
.cell-main small { display: block; color: var(--muted); margin-top: 3px; }
.money { white-space: nowrap; font-variant-numeric: tabular-nums; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.table-actions button { min-width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: #15181d; color: #d8dbe1; }
.table-actions button:hover { border-color: #555c68; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; font-weight: 800; font-size: .68rem; letter-spacing: .02em; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { background: rgba(59,194,122,.12); color: #69dc9d; }
.badge-red { background: rgba(var(--brand-rgb),.13); color: #ff7179; }
.badge-amber { background: rgba(241,179,75,.12); color: #f5c36f; }
.badge-blue { background: rgba(88,166,255,.12); color: #7cbbff; }
.badge-gray { background: rgba(166,172,183,.1); color: #b6bbc4; }

.empty-state { min-height: 260px; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 40px; }
.empty-state strong { color: #fff; display: block; font-size: 1.05rem; margin-bottom: 6px; }

.modal { width: min(820px, calc(100vw - 28px)); padding: 0; background: transparent; border: none; color: var(--text); }
.modal::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(8px); }
.modal-shell { background: #111318; border: 1px solid #30343d; border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.modal-shell header, .modal-shell footer { padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-shell header { border-bottom: 1px solid var(--line-soft); }
.modal-shell footer { border-top: 1px solid var(--line-soft); justify-content: flex-end; }
.modal-shell h2 { margin: 4px 0 0; font-size: 1.2rem; }
.modal-close { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #171a20; color: #fff; font-size: 1.3rem; }
.modal-body { padding: 22px; max-height: min(70vh, 720px); overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 46px; }
.check-row input { width: 18px; height: 18px; }

.report-hero { display: grid; grid-template-columns: 1.3fr .7fr; gap: 14px; margin-bottom: 14px; }
.report-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.summary-box { padding: 15px; background: rgba(255,255,255,.025); border: 1px solid var(--line-soft); border-radius: 13px; }
.summary-box span { color: var(--muted); font-size: .72rem; }
.summary-box strong { display: block; margin-top: 8px; font-size: 1.2rem; }
.settings-card { max-width: 900px; }

.chart-legend { display: flex; gap: 18px; margin-top: 12px; flex-wrap: wrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .78rem; }
.chart-legend i { width: 12px; height: 12px; border-radius: 4px; }

.aging-list { display: grid; gap: 10px; margin-top: 4px; }
.aging-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.aging-row .aging-head { display: flex; justify-content: space-between; grid-column: 1 / -1; font-size: .82rem; }
.aging-row .aging-head span { color: #cdd0d6; }
.aging-row .aging-head b { color: #fff; font-variant-numeric: tabular-nums; }
.aging-track { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: rgba(255,255,255,.06); overflow: hidden; }
.aging-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--brand-bright)); }
.aging-empty { color: var(--muted); font-size: .85rem; padding: 8px 0; }

.btn-wa { background: rgba(37,211,102,.14); border-color: rgba(37,211,102,.3); color: #4ee08a; }
.btn-wa:hover { border-color: rgba(37,211,102,.55); }
.table-actions .wa { color: #4ee08a; border-color: rgba(37,211,102,.28); background: rgba(37,211,102,.1); font-weight: 900; }
.table-actions .wa:hover { border-color: rgba(37,211,102,.55); }

.mini-note { color: var(--muted); font-size: .8rem; margin: 2px 0 0; }
.pill-role { display: inline-flex; padding: 4px 9px; border-radius: 999px; font-size: .68rem; font-weight: 800; letter-spacing: .04em; background: rgba(255,255,255,.06); color: #cdd0d6; }
.pill-role.admin { background: rgba(var(--brand-rgb),.16); color: #ff8188; }
.account-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.account-grid .panel { padding: 22px; }
@media (max-width: 850px) { .account-grid { grid-template-columns: 1fr; } }

.toast { position: fixed; top: 22px; right: 22px; max-width: min(380px, calc(100vw - 44px)); padding: 13px 16px; border-radius: 12px; background: #1b1f25; color: #fff; border: 1px solid #343943; box-shadow: var(--shadow); opacity: 0; transform: translateY(-10px); pointer-events: none; transition: .25s; z-index: 100; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(var(--brand-rgb),.5); }
.mobile-nav { display: none; }
.skeleton { min-height: 110px; border-radius: var(--radius); background: linear-gradient(90deg, #101216 25%, #171a20 50%, #101216 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 1150px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 850px) {
  .login-view { grid-template-columns: 1fr; }
  .login-visual { display: none; }
  .login-panel { min-height: 100vh; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .workspace { min-height: 100vh; padding-bottom: 78px; }
  .topbar { min-height: 78px; padding: 14px 16px; }
  .topbar-actions { align-items: center; }
  .month-control { min-width: 145px; }
  .month-control span { display: none; }
  .content { padding: 18px 14px 26px; }
  .mobile-nav { position: fixed; z-index: 30; inset: auto 0 0; display: grid; grid-template-columns: repeat(5, 1fr); background: rgba(10,11,14,.95); border-top: 1px solid var(--line); backdrop-filter: blur(16px); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .mobile-nav button { border: none; background: transparent; color: #868d98; display: grid; gap: 2px; justify-items: center; padding: 5px; }
  .mobile-nav button span { font-size: 1.15rem; }
  .mobile-nav button small { font-size: .61rem; }
  .mobile-nav button.active { color: var(--red); }
  .page-head { align-items: start; flex-direction: column; }
  .page-head .action-row { width: 100%; }
  .page-head .action-row .btn { flex: 1; }
  .report-hero { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topbar h1 { font-size: 1.2rem; }
  .topbar .eyebrow { display: none; }
  .month-control { min-width: 132px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .kpi-card { min-height: 118px; padding: 15px; }
  .kpi-card strong { font-size: 1.25rem; margin-top: 14px; }
  .kpi-card small { font-size: .68rem; }
  .panel { padding: 15px; }
  .chart-wrap { height: 240px; }
  .table-toolbar { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: 1; }
  .modal-body { padding: 17px; }
  .report-summary { grid-template-columns: 1fr 1fr; }
}
@media print {
  body { background: #fff !important; color: #111 !important; }
  .sidebar, .topbar, .mobile-nav, .page-head .action-row, .toast { display: none !important; }
  .app-shell { display: block !important; }
  .content { padding: 0 !important; max-width: none; }
  .panel, .table-panel { border: 1px solid #ddd !important; background: #fff !important; color: #111 !important; box-shadow: none !important; }
  th, td { color: #111 !important; border-color: #ddd !important; }
  .badge { border: 1px solid #bbb; color: #222 !important; background: #fff !important; }
  .report-hero { grid-template-columns: 1fr 1fr; }
}
