:root {
  --ink: #151515;
  --muted: #6e6b68;
  --line: #dedbd7;
  --panel: #ffffff;
  --canvas: #f4f2ef;
  --soft: #ebe7e2;
  --warm: #b79e8d;
  --danger: #9b2c2c;
  --success: #22613f;
  --warning: #8a5a16;
  --blue: #345c83;
  --shadow: 0 18px 50px rgba(25, 20, 16, .08);
  --radius: 16px;
  --sidebar: 250px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Arial, sans-serif; color: var(--ink); background: var(--canvas); }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
a { color: inherit; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #efece8, #f9f8f6 55%, #e7e0da); }
.login-card { width: min(430px, 100%); background: rgba(255,255,255,.96); padding: 38px; border: 1px solid rgba(0,0,0,.06); border-radius: 24px; box-shadow: var(--shadow); }
.login-logo { display: block; width: 230px; max-width: 75%; margin: 0 auto 10px; }
.login-kicker, .eyebrow { font-size: 11px; letter-spacing: .24em; font-weight: 800; color: var(--muted); }
.login-card h1 { font-size: 28px; line-height: 1.18; margin: 18px 0 8px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-note { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }
.form-stack { display: grid; gap: 14px; }
label { display: grid; gap: 7px; font-size: 12px; font-weight: 700; color: #46413d; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 11px 12px; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: #8c8178; box-shadow: 0 0 0 3px rgba(140,129,120,.13); }
textarea { min-height: 110px; resize: vertical; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) 1fr; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: #161616; color: #fff; padding: 22px 14px 16px; display: flex; flex-direction: column; z-index: 20; }
.brand-block { padding: 8px 10px 24px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-block img { width: 180px; max-width: 100%; filter: invert(1) brightness(1.7); }
.brand-block span { display: block; margin-top: 5px; font-size: 10px; letter-spacing: .28em; color: #c7beb7; }
#sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 0; }
.nav-group-label { font-size: 10px; letter-spacing: .18em; color: #877f79; padding: 14px 12px 7px; font-weight: 800; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 11px; border: 0; background: transparent; color: #cfcac5; padding: 10px 12px; border-radius: 9px; text-align: left; font-size: 13px; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.09); }
.nav-icon { width: 20px; text-align: center; opacity: .9; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding: 14px 10px 0; }
.user-name { font-size: 13px; font-weight: 700; }
.user-email { font-size: 11px; color: #99928c; margin-top: 3px; }
.link-button { border: 0; background: transparent; color: #c5bcb5; padding: 10px 0 0; font-size: 12px; }
.main-area { grid-column: 2; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 28px; background: rgba(244,242,239,.92); backdrop-filter: blur(15px); border-bottom: 1px solid rgba(0,0,0,.06); }
.topbar h1 { margin: 4px 0 0; font-size: 24px; }
.topbar-actions { display: flex; gap: 10px; }
.page-content { padding: 26px 28px 80px; max-width: 1650px; margin: 0 auto; }
.btn { border: 1px solid transparent; border-radius: 9px; padding: 9px 13px; font-weight: 750; font-size: 12px; transition: transform .12s, opacity .12s, background .12s; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: #171717; color: #fff; }
.btn.secondary { background: var(--soft); color: var(--ink); border-color: #d7d1cb; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.danger { background: #fff4f4; color: var(--danger); border-color: #e6bdbd; }
.btn.success { background: #eef8f2; color: var(--success); border-color: #bddbc9; }
.btn.wide { width: 100%; }
.btn.small { padding: 6px 9px; font-size: 11px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.search { min-width: 260px; }
.card, .panel { background: var(--panel); border: 1px solid rgba(0,0,0,.06); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(25,20,16,.035); }
.panel { padding: 20px; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 18px; min-height: 125px; display: flex; flex-direction: column; justify-content: space-between; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.kpi-value { font-size: 25px; line-height: 1; font-weight: 800; margin-top: 16px; }
.kpi-foot { font-size: 11px; color: var(--muted); margin-top: 13px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-top: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-title h2 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.table-wrap { width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th { position: sticky; top: 0; z-index: 1; text-align: left; background: #f2efec; font-size: 11px; letter-spacing: .03em; text-transform: uppercase; color: #5f5852; padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid #ece9e6; font-size: 12px; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #faf9f7; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: 10px; font-weight: 800; white-space: nowrap; background: #efefef; color: #555; }
.badge.draft { background: #ece8e4; color: #625950; }
.badge.approved { background: #e7f1ff; color: #315f8e; }
.badge.posted, .badge.done, .badge.paid { background: #e9f6ee; color: #266343; }
.badge.unpaid, .badge.overdue { background: #fff0e7; color: #965214; }
.badge.cancelled, .badge.reversed { background: #fdeaea; color: #9b2c2c; }
.badge.pending { background: #fff6d9; color: #7b5b10; }
.empty { padding: 34px 20px; text-align: center; color: var(--muted); }
.checklist { display: grid; gap: 9px; }
.check-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; }
.check-dot { width: 11px; height: 11px; border-radius: 50%; background: #c7c2bd; }
.check-dot.done { background: var(--success); }
.ai-hero { background: #171717; color: white; border-radius: 20px; padding: 26px; display: grid; grid-template-columns: 1.3fr .7fr; gap: 24px; align-items: center; margin-bottom: 16px; }
.ai-hero h2 { font-size: 27px; margin: 0 0 8px; }
.ai-hero p { margin: 0; color: #bbb4ae; line-height: 1.6; }
.ai-tabs { display: flex; gap: 8px; }
.ai-tab { border: 1px solid rgba(255,255,255,.2); background: transparent; color: #ddd; border-radius: 9px; padding: 8px 11px; }
.ai-tab.active { background: #fff; color: #111; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2,minmax(0,1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; flex-wrap: wrap; }
.alert { border-radius: 10px; padding: 11px 13px; font-size: 12px; border: 1px solid; margin-bottom: 12px; }
.alert.warning { background: #fff8e7; border-color: #ead29c; color: #725312; }
.alert.success { background: #ecf8f1; border-color: #bcdac8; color: #245d3d; }
.alert.error { background: #fff0f0; border-color: #e4bcbc; color: #8c2d2d; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(12,10,9,.58); z-index: 100; display: grid; place-items: center; padding: 18px; }
.modal { width: min(950px, 100%); max-height: 93vh; overflow: auto; background: white; border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.modal.large { width: min(1200px,100%); }
.modal-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 17px 20px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(10px); }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 20px; }
.close-btn { border: 0; background: #eeeae6; width: 32px; height: 32px; border-radius: 50%; font-size: 18px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.detail-block { border: 1px solid var(--line); border-radius: 11px; padding: 13px; }
.detail-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
.detail-value { margin-top: 6px; font-size: 13px; font-weight: 650; }
.upload-box { border: 1.5px dashed #bdb4ad; border-radius: 12px; padding: 14px; background: #faf8f6; }
.upload-preview { margin-top: 10px; max-width: 220px; max-height: 160px; border-radius: 8px; border: 1px solid var(--line); }
.invoice-paper { width: 210mm; min-height: 297mm; max-width: 100%; margin: 0 auto; background: #fff; padding: 16mm 18mm 12mm; color: #111; box-shadow: 0 8px 25px rgba(0,0,0,.12); font-family: Arial, sans-serif; }
.invoice-logo { display: block; width: 82mm; margin: 0 auto 7mm; }
.invoice-paper h1 { text-align: center; font-size: 24px; margin: 0 0 8mm; }
.invoice-meta { text-align: center; font-size: 12px; }
.invoice-client { margin-top: 22mm; line-height: 1.6; font-size: 12px; }
.invoice-lines { margin-top: 27mm; min-width: 0; border-top: 1px solid #777; }
.invoice-lines table { min-width: 0; }
.invoice-lines th { background: white; color: #111; text-transform: none; font-size: 12px; border-bottom: none; position: static; }
.invoice-lines td { font-size: 12px; border-bottom: 1px solid #777; }
.invoice-total-row { display: flex; justify-content: space-between; font-size: 12px; font-weight: 800; margin-top: 5px; }
.payment-banner { margin-top: 76mm; background: #f3f3f3; padding: 7mm; text-align: center; }
.payment-banner h2 { margin: 0 0 5mm; font-size: 18px; letter-spacing: .05em; }
.invoice-footer { margin-top: 21mm; padding-top: 5mm; border-top: 1px solid #888; display: flex; justify-content: space-between; font-size: 10px; }
.report-tabs { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }
.report-tab { border: 1px solid var(--line); background: white; border-radius: 9px; padding: 8px 11px; font-size: 12px; font-weight: 700; }
.report-tab.active { background: #171717; color: white; border-color: #171717; }
.metric-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.metric-pill { padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px; background: white; font-size: 12px; }
.metric-pill b { display: block; font-size: 17px; margin-top: 4px; }
.mobile-nav { display: none; }
#toast-root { position: fixed; right: 18px; top: 18px; z-index: 200; display: grid; gap: 9px; }
.toast { min-width: 260px; max-width: 400px; background: #171717; color: white; padding: 12px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 12px; animation: toastIn .2s ease; }
.toast.error { background: #8d2929; }
.toast.success { background: #245d3d; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }
@media (max-width: 1150px) {
  .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .form-grid .span-3 { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  :root { --sidebar: 0px; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main-area { width: 100%; }
  .topbar { padding: 15px 16px; }
  .topbar h1 { font-size: 20px; }
  .topbar-actions .ghost { display: none; }
  .page-content { padding: 16px 14px 92px; }
  .kpi-grid, .grid-3, .form-grid, .form-grid.two, .detail-grid, .ai-hero { grid-template-columns: 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: auto; }
  .kpi { min-height: 105px; }
  .kpi-value { font-size: 22px; }
  .toolbar { align-items: stretch; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .search { min-width: 0; flex: 1; }
  .mobile-nav { display: grid; position: fixed; z-index: 30; bottom: 0; left: 0; right: 0; grid-template-columns: repeat(5,1fr); background: rgba(20,20,20,.97); color: #fff; padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); }
  .mobile-nav button { border: 0; background: transparent; color: #a9a39d; font-size: 9px; display: grid; gap: 3px; justify-items: center; }
  .mobile-nav button.active { color: #fff; }
  .mobile-nav .micon { font-size: 18px; }
  .invoice-paper { padding: 10mm 7mm; min-height: auto; }
  .payment-banner { margin-top: 45mm; }
  .invoice-footer { gap: 8px; font-size: 8px; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 94vh; }
  .login-card { padding: 28px 22px; }
}
@media print {
  body * { visibility: hidden !important; }
  .invoice-paper, .invoice-paper * { visibility: visible !important; }
  .invoice-paper { position: absolute; inset: 0; width: 210mm; min-height: 297mm; box-shadow: none; margin: 0; }
}
