:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f3f5;
  --border: #d9dee6;
  --border-strong: #c4cad4;
  --text: #111827;
  --muted: #667085;
  --primary: #0f172a;
  --secondary: #334155;
  --accent: #2563eb;
  --success: #166534;
  --warning: #92400e;
  --danger: #991b1b;
  --radius-sm: 6px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
.btn { border-radius: var(--radius-sm); font-weight: 650; }
.form-control, .form-select { border-radius: var(--radius-sm); border-color: var(--border); font-size: .92rem; }
.form-control:focus, .form-select:focus { border-color: var(--secondary); box-shadow: 0 0 0 .18rem rgba(15, 23, 42, .12); }
.form-label { color: var(--secondary); font-size: .78rem; font-weight: 700; margin-bottom: .3rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 18px;
  background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 22px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--primary); color: #fff; font-size: .78rem; font-weight: 800; letter-spacing: .04em;
}
.brand small { display: block; color: var(--muted); font-size: .72rem; margin-top: 1px; }
.nav-list { display: grid; gap: 4px; }
.nav-list a { padding: 9px 10px; border-radius: var(--radius-sm); color: var(--secondary); font-weight: 650; }
.nav-list a.active, .nav-list a:hover { background: var(--surface-muted); color: var(--primary); }
.plan-card { margin-top: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--surface-muted); }
.plan-card span, .plan-card small { display: block; color: var(--muted); font-size: .76rem; }
.plan-card strong { display: block; margin: 4px 0; }

.main-panel { padding: 22px; max-width: 1320px; width: 100%; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
h1, h2, h3 { letter-spacing: -.03em; }
.topbar h1 { font-size: clamp(1.3rem, 2vw, 1.85rem); margin: 0; }
.eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: .68rem; font-weight: 800; }

.hero-panel { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; margin-bottom: 16px; }
.hero-copy, .summary-card, .panel-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.hero-copy { padding: clamp(22px, 4vw, 42px); }
.pill { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 5px 9px; color: var(--secondary); font-weight: 700; font-size: .76rem; margin-bottom: 14px; }
.hero-copy h2 { font-size: clamp(1.8rem, 4vw, 3rem); max-width: 780px; margin-bottom: 12px; line-height: 1.02; }
.hero-copy p { color: var(--muted); max-width: 660px; font-size: 1rem; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.summary-card { padding: 18px; display: grid; align-content: center; gap: 10px; }
.metric-row { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.metric-row:last-child { border-bottom: 0; }
.metric-row span { color: var(--muted); }
.metric-row strong { font-size: 1.05rem; }

.grid-two { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .7fr); gap: 16px; }
.panel-card { padding: 18px; }
.section-heading { margin-bottom: 14px; }
.section-heading h2 { font-size: 1.15rem; margin: 0; }
.with-action { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.compact-alert { border-radius: var(--radius); border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.line-items { display: grid; gap: 10px; margin-top: 18px; }
.line-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; background: #fbfcfd; }
.live-total { height: 100%; min-height: 62px; border: 1px solid var(--border); border-radius: var(--radius-sm); display: grid; align-content: center; padding: 10px 12px; background: var(--surface-muted); }
.live-total span { color: var(--muted); font-size: .76rem; font-weight: 700; }
.live-total strong { font-size: 1.1rem; }
.form-footer { margin-top: 16px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.module-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.module-list li { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.module-list span { display: block; color: var(--muted); margin-top: 2px; }

.invoice-table { margin-bottom: 0; }
.invoice-table th { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; border-bottom-color: var(--border); }
.invoice-table td { border-bottom-color: var(--border); }
.invoice-table td span { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.status-pill { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px; padding: 4px 8px; font-size: .75rem; font-weight: 800; }
.status-draft { color: var(--secondary); background: #f8fafc; }
.status-sent { color: #1d4ed8; background: #eff6ff; border-color: #bfdbfe; }
.status-paid { color: var(--success); background: #f0fdf4; border-color: #bbf7d0; }
.status-overdue { color: var(--danger); background: #fef2f2; border-color: #fecaca; }
.empty-state { text-align: center; padding: 36px 18px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: #fbfcfd; }
.empty-state h3 { font-size: 1.15rem; }
.empty-state p { color: var(--muted); max-width: 460px; margin: 0 auto 16px; }
.mobile-cards { display: none; gap: 10px; }
.invoice-mobile-card { display: grid; gap: 6px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.invoice-mobile-card small { color: var(--muted); }

.detail-wrap, .public-invoice { max-width: 980px; margin: 0 auto; padding: 22px; }
.detail-nav { display: flex; justify-content: space-between; margin-bottom: 12px; color: var(--secondary); font-weight: 700; }
.invoice-head { display: flex; justify-content: space-between; align-items: start; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.invoice-head h1 { font-size: clamp(1.35rem, 3vw, 2rem); margin-bottom: 6px; }
.detail-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 0; }
.detail-grid div { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; background: #fbfcfd; }
.detail-grid span, .detail-grid small { display: block; color: var(--muted); }
.address-note, .notes-box, .payment-placeholder { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; background: #fbfcfd; }
.notes-box { margin-top: 14px; }
.notes-box p { margin: 6px 0 0; color: var(--secondary); }
.totals-box { margin-left: auto; width: min(360px, 100%); display: grid; gap: 8px; padding-top: 16px; }
.totals-box div { display: flex; justify-content: space-between; color: var(--secondary); }
.totals-box .grand { border-top: 1px solid var(--border); padding-top: 10px; color: var(--primary); font-size: 1.15rem; }
.action-bar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.status-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status-form .form-select { width: 140px; }
.public-body { background: #eef1f5; }
.public-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 24px; }
.payment-placeholder { margin-top: 18px; display: flex; justify-content: space-between; gap: 12px; color: var(--secondary); }

.toast-stack { position: fixed; right: 16px; bottom: 16px; z-index: 20; display: grid; gap: 8px; }
.app-toast { background: var(--primary); color: #fff; padding: 10px 12px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-weight: 650; max-width: 320px; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .plan-card { display: none; }
  .hero-panel, .grid-two { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .main-panel, .detail-wrap, .public-invoice { padding: 14px; }
  .topbar, .invoice-head, .action-bar, .public-head, .form-footer { align-items: stretch; flex-direction: column; }
  .nav-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .desktop-table { display: none; }
  .mobile-cards { display: grid; }
  .detail-grid { grid-template-columns: 1fr; }
  .hero-copy h2 { font-size: 1.8rem; }
}

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .public-invoice { max-width: none; padding: 0; }
  .panel-card { box-shadow: none; border: 0; }
}
