:root {
  --bg: #f6f8f4; --card: #ffffff; --ink: #121a10; --muted: #667085;
  --brand: #5c9412; --brand-2: #84cc16; --brand-dark: #4d7c0f;
  --accent: #b5e96b; --accent-soft: #f0f9dd; --dark: #0a140b;
  --green: #12b76a; --green-bg: #ecfdf3; --red: #f04438; --red-bg: #fef3f2;
  --amber: #f79009; --amber-bg: #fffaeb; --blue-bg: #eef2ff;
  --border: #eaecf0; --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 24px -6px rgba(16,24,40,.14);
}
* { box-sizing: border-box; margin: 0; }
body { font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }

/* ---------- layout ---------- */
#app { display: flex; min-height: 100vh; }
aside { width: 240px; background: linear-gradient(180deg, #0a140b 0%, #0e1c0f 100%); color: #ccd6c9; padding: 22px 14px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
aside .logo { font-size: 19px; font-weight: 800; color: #fff; padding: 6px 12px 24px; letter-spacing: -.2px; display: flex; align-items: center; gap: 9px; }
aside .logo img { height: 20px; width: auto; display: block; }
aside .logo .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--dark); box-shadow: 0 4px 12px rgba(181,233,107,.35); }
aside .logo span { color: var(--accent); }
aside nav { flex: 1; }
aside nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; margin: 2px 0; color: #97a893; border-radius: 9px; font-weight: 500; font-size: 13.5px; transition: all .15s; }
aside nav a svg { width: 17px; height: 17px; flex-shrink: 0; }
aside nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
aside nav a.active { background: linear-gradient(90deg, rgba(181,233,107,.22), rgba(181,233,107,.07)); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
aside .user-box { padding: 12px; font-size: 12.5px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 10px; }
aside .user-box .avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--brand-2)); color: var(--dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
aside .user-box .who { flex: 1; color: #e6efe3; font-weight: 600; }
aside .user-box .who small { display: block; color: #97a893; font-weight: 400; }
aside .user-box .out { background: none; border: none; color: #97a893; cursor: pointer; padding: 6px; border-radius: 8px; }
aside .user-box .out:hover { background: rgba(255,255,255,.08); color: #fff; }
main { flex: 1; padding: 30px 36px; max-width: 1240px; }
h1 { font-size: 22px; letter-spacing: -.3px; margin-bottom: 3px; }
.sub { color: var(--muted); margin-bottom: 20px; font-size: 13.5px; }

/* ---------- KPI cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); transition: box-shadow .15s; }
.card:hover { box-shadow: var(--shadow-lg); }
.card .chip { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.card .chip svg { width: 18px; height: 18px; }
.chip.green { background: var(--green-bg); color: var(--green); }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.amber { background: var(--amber-bg); color: var(--amber); }
.chip.blue { background: var(--accent-soft); color: var(--brand); }
.card .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.card .value { font-size: 23px; font-weight: 800; letter-spacing: -.5px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.card .value.green { color: var(--green); } .card .value.red { color: var(--red); } .card .value.amber { color: var(--amber); }

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel h3 { font-size: 14.5px; margin-bottom: 12px; letter-spacing: -.1px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > .panel { flex: 1; min-width: 320px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; padding: 9px 12px; border-bottom: 1px solid var(--border); background: #fafbfc; }
th:first-child { border-radius: 8px 0 0 8px; } th:last-child { border-radius: 0 8px 8px 0; }
td { padding: 11px 12px; border-bottom: 1px solid #f2f4f7; font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: #f7fbee; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.paid, .badge.finalized { background: var(--green-bg); color: #067647; }
.badge.sent, .badge.pending { background: var(--blue-bg); color: #3538cd; }
.badge.partial { background: var(--amber-bg); color: #b54708; }
.badge.overdue, .badge.overdue-partial { background: var(--red-bg); color: #b42318; }
.badge.draft, .badge.void, .badge.inactive { background: #f2f4f7; color: #475467; }

/* ---------- forms & buttons ---------- */
button, .btn { background: linear-gradient(180deg, #c6f186, var(--accent)); color: var(--dark); border: none; border-radius: 10px; padding: 9px 16px; font-size: 13.5px; font-weight: 700; cursor: pointer; font-family: inherit; box-shadow: 0 1px 2px rgba(16,24,40,.1), inset 0 1px 0 rgba(255,255,255,.25); transition: all .15s; }
button:hover, .btn:hover { background: #a5dd50; transform: translateY(-1px); box-shadow: 0 4px 10px rgba(132,204,22,.35); }
button.ghost, .btn.ghost { background: #fff; color: var(--ink); border: 1px solid #d0d5dd; box-shadow: var(--shadow); }
button.ghost:hover, .btn.ghost:hover { background: #f9fafb; box-shadow: var(--shadow); }
button.danger { background: #fff; color: var(--red); border: 1px solid #fda29b; box-shadow: none; }
button.danger:hover { background: var(--red-bg); box-shadow: none; }
button.small { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
button.green { background: linear-gradient(180deg, #17c675, var(--green)); }
button.green:hover { background: #0e9f5c; box-shadow: 0 4px 10px rgba(18,183,106,.3); }
input, select, textarea { border: 1px solid #d0d5dd; border-radius: 10px; padding: 9px 12px; font-size: 14px; font-family: inherit; width: 100%; background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 4px rgba(181,233,107,.28); }
label { display: block; font-size: 12.5px; font-weight: 600; color: #344054; margin-bottom: 5px; }
.field { margin-bottom: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 13px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 10px; flex-wrap: wrap; }
.toolbar .right { display: flex; gap: 8px; align-items: center; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(12,17,29,.55); backdrop-filter: blur(3px); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 50; overflow-y: auto; animation: fade .15s; }
.modal { background: #fff; border-radius: 16px; padding: 26px; width: 100%; max-width: 640px; box-shadow: 0 24px 48px -12px rgba(16,24,40,.25); animation: pop .18s; }
.modal h2 { font-size: 17px; margin-bottom: 16px; letter-spacing: -.2px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
@keyframes fade { from { opacity: 0 } } @keyframes pop { from { transform: translateY(8px); opacity: 0 } }

#toast { position: fixed; bottom: 24px; right: 24px; background: var(--dark); color: #fff; padding: 13px 20px; border-radius: 12px; font-size: 13.5px; display: none; z-index: 100; box-shadow: var(--shadow-lg); }
#toast.error { background: var(--red); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1000px 600px at 20% -10%, #23411b 0%, #0a140b 55%), #0a140b; }
.login-card { background: #fff; border-radius: 20px; padding: 40px; width: 400px; box-shadow: 0 32px 64px -16px rgba(0,0,0,.5); }
.login-card img.brand { height: 24px; width: auto; display: block; margin-bottom: 20px; }
.login-card .mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 21px; color: var(--dark); margin-bottom: 18px; box-shadow: 0 8px 20px rgba(181,233,107,.35); }
.login-card h1 { font-size: 21px; margin-bottom: 6px; letter-spacing: -.3px; }
.login-card p { color: var(--muted); margin-bottom: 22px; font-size: 13.5px; }
.login-card button { width: 100%; padding: 12px; margin-top: 8px; }
.err { color: var(--red); font-size: 13px; margin-top: 10px; }

/* ---------- chart ---------- */
.trend { display: flex; gap: 8px; align-items: stretch; height: 190px; padding: 12px 4px 0; }
.trend .bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.trend .bars { display: flex; gap: 5px; align-items: flex-end; flex: 1; width: 100%; justify-content: center; background: linear-gradient(to top, transparent 0, transparent 100%); position: relative; }
.trend .bars::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--border); }
.trend .bar { width: 22px; border-radius: 6px 6px 2px 2px; min-height: 3px; transition: all .2s; cursor: default; }
.trend .bar:hover { filter: brightness(1.12); }
.trend .bar.rev { background: linear-gradient(180deg, var(--accent), var(--brand-2)); }
.trend .bar.cost { background: linear-gradient(180deg, #fbbf24, #f59e0b); }
.trend .m { font-size: 11px; color: var(--muted); font-weight: 600; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- onboarding / empty states ---------- */
.onboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.onboard a.step { display: flex; gap: 12px; align-items: flex-start; padding: 16px; border: 1px solid var(--border); border-radius: 12px; color: var(--ink); transition: all .15s; background: #fff; }
.onboard a.step:hover { border-color: var(--brand-2); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.onboard .n { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--brand); font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.onboard .step.done .n { background: var(--green-bg); color: var(--green); }
.onboard .t { font-weight: 700; font-size: 13.5px; }
.onboard .d { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); font-size: 13.5px; }
.empty .big { font-size: 30px; margin-bottom: 8px; }

/* ---------- print docs ---------- */
.print-doc { background: #fff; max-width: 760px; margin: 0 auto; padding: 44px; }
.print-doc .head { display: flex; justify-content: space-between; margin-bottom: 32px; }
.print-doc h1 { font-size: 27px; letter-spacing: 1px; }
.print-doc .meta { text-align: right; color: var(--muted); font-size: 13px; line-height: 1.7; }
.print-doc img.logo { max-height: 60px; }
.print-total { text-align: right; font-size: 18px; font-weight: 800; margin-top: 16px; }
@media print {
  aside, .toolbar, .no-print, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  body { background: #fff; }
  .panel { border: none; box-shadow: none; padding: 0; }
}
@media (max-width: 900px) {
  #app { flex-direction: column; }
  aside { width: 100%; height: auto; position: static; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  main { padding: 18px; }
}
