@font-face { font-family: Inter; font-weight: 400; src: url(/fonts/inter-latin-400-normal.woff) format('woff'); font-display: swap; }
@font-face { font-family: Inter; font-weight: 500; src: url(/fonts/inter-latin-500-normal.woff) format('woff'); font-display: swap; }
@font-face { font-family: Inter; font-weight: 600; src: url(/fonts/inter-latin-600-normal.woff) format('woff'); font-display: swap; }
@font-face { font-family: Inter; font-weight: 700; src: url(/fonts/inter-latin-700-normal.woff) format('woff'); font-display: swap; }

:root {
  --bg: #f4f3ef; --panel: #ffffff; --ink: #1b1f1d; --muted: #6b716d; --faint: #9aa09c;
  --line: #e3e1da; --line-2: #d3d0c7; --accent: #163a2b; --accent-2: #24704d; --accent-soft: #e5f0e9;
  --danger: #b2352a; --danger-soft: #fbe9e6; --warn: #9a6a00; --warn-soft: #fbf1d6; --info-soft: #e8eef8; --info: #2f5597;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,25,.05), 0 4px 16px rgba(20,30,25,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--accent); color: #dfeae3; padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; font-weight: 600; color: #fff; font-size: 15px; letter-spacing: -.01em; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: #e8f3ec; display: grid; place-items: center; }
.brand-mark i { display: block; width: 12px; height: 2px; background: var(--accent); border-radius: 2px; box-shadow: 0 -5px 0 var(--accent), 0 5px 0 var(--accent); }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: #c9dad0; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.nav .pill { background: rgba(255,255,255,.16); border-radius: 20px; padding: 0 8px; font-size: 12px; }
.side .spacer { flex: 1; }
.side .new-btn { margin: 0 2px 16px; justify-content: center; background: #e8f3ec; color: var(--accent); }
.side .new-btn:hover { background: #fff; }
.side .logout { background: none; border: 0; color: #9fb8aa; text-align: left; padding: 8px 10px; cursor: pointer; }
.main { padding: 28px 36px 60px; max-width: 1240px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
h1 { font-size: 24px; letter-spacing: -.02em; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-2); background: var(--panel); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 500; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #b9b5aa; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0f2c20; }
.btn.green { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.grid { display: grid; gap: 16px; }
.grid > *, .editor > *, .view > *, .stack > * { min-width: 0; }
.kpis { grid-template-columns: repeat(4, 1fr); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; margin-top: 6px; }
.kpi .note { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi.alert .value { color: var(--danger); }
.two { grid-template-columns: 1.4fr 1fr; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.r { text-align: right; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: #faf9f6; }
.table-card { padding: 0; overflow: hidden; }
.table-card .scroll { overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.b-paid { background: var(--accent-soft); color: var(--accent-2); }
.b-overdue { background: var(--danger-soft); color: var(--danger); }
.b-outstanding { background: var(--info-soft); color: var(--info); }
.b-partial { background: var(--warn-soft); color: var(--warn); }
.b-draft { background: #eeede8; color: #6b6a64; }
.b-void { background: #eeede8; color: #9a9890; text-decoration: line-through; }

/* tabs / filters */
.tabs { display: flex; gap: 4px; background: #e9e7e0; padding: 3px; border-radius: 9px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--muted); }
.tabs button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.search { border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 11px; background: var(--panel); min-width: 220px; }

/* forms */
label.f { display: block; font-size: 12.5px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; background: #fff; }
.input:focus, .search:focus { outline: 2px solid #b8d6c4; outline-offset: 0; border-color: var(--accent-2); }
textarea.input { resize: vertical; min-height: 70px; }
.fields { display: grid; gap: 14px; }
.f2 { grid-template-columns: 1fr 1fr; } .f3 { grid-template-columns: repeat(3, 1fr); } .f4 { grid-template-columns: repeat(4, 1fr); }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); cursor: pointer; }
.hint { font-size: 12px; color: var(--faint); margin-top: 4px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin: 0 0 12px; }

/* invoice editor */
.editor { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
.items td { padding: 6px 6px; vertical-align: top; border-bottom: 1px dashed var(--line); }
.items th { padding: 8px 6px; }
.items .input { padding: 6px 8px; }
.items textarea.input { min-height: 34px; margin-top: 4px; font-size: 13px; color: var(--muted); }
.items .amt { padding-top: 13px; font-weight: 500; }
.x { border: 0; background: none; color: var(--faint); font-size: 18px; cursor: pointer; padding: 6px; line-height: 1; }
.x:hover { color: var(--danger); }
.totals-box .line { display: flex; justify-content: space-between; padding: 6px 0; }
.totals-box .grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 600; font-size: 18px; }
.sticky { position: sticky; top: 20px; }

/* invoice view */
.view { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
.pdf-frame { width: 100%; height: calc(100vh - 140px); min-height: 640px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.stat-line { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); }
.stat-line:last-child { border-bottom: 0; }
.big-balance { font-size: 28px; font-weight: 600; letter-spacing: -.02em; }
.stack > * + * { margin-top: 16px; }
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions-grid .btn { justify-content: center; }

/* aging + chart */
.aging { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: #eeede8; margin: 6px 0 14px; }
.aging span { display: block; height: 100%; }
.legend { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.legend div { font-size: 12px; color: var(--muted); }
.legend b { display: block; color: var(--ink); font-size: 14px; font-weight: 600; margin-top: 2px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar span { width: 100%; background: var(--accent-2); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bars .bar:hover span { opacity: 1; }
.bars .bar em { font-style: normal; font-size: 10.5px; color: var(--faint); }
.cur-switch { display: flex; gap: 6px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,25,22,.35); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal header { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; font-size: 17px; }
.modal .body { padding: 18px 22px; }
.modal footer { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fbfaf7; border-radius: 0 0 12px 12px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 360px; padding: 30px; }
.login h1 { margin-bottom: 18px; }

.logo-prev { max-height: 50px; max-width: 200px; display: block; margin-bottom: 8px; }

@media (max-width: 1000px) {
  .kpis { grid-template-columns: 1fr 1fr; } .two, .editor, .view { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; }
  .brand { padding: 0 8px 0 0; } .side .spacer { display: none; } .nav { display: flex; gap: 2px; flex-wrap: wrap; }
  .side .new-btn { margin: 0; }
  .main { padding: 18px 16px 50px; }
  .f2, .f3, .f4, .kpis { grid-template-columns: 1fr !important; }
  .topbar .btn-row { width: 100%; }
  .pdf-frame { height: 70vh; min-height: 0; }
  .side .logout { padding: 6px 8px; }
  .search { min-width: 0; width: 100%; }
  .legend { grid-template-columns: repeat(3, 1fr); }
  .hide-sm { display: none; }
}
