:root {
  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #060d1b;
  --bg-sidebar-hover: #132240;
  --bg-sidebar-active: #2563eb;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.45;
}

.num, .amount, td.num, th.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Shell Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 256px;
  background: var(--bg-sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 8px;
}

.brand-name {
  font-weight: 800;
  font-size: 13.5px;
  letter-spacing: 0.03em;
  color: #ffffff;
  word-break: break-word;
}

.brand-sub {
  font-size: 10.5px;
  color: #60a5fa;
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.nav-section {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 12px 10px 6px;
  font-weight: 700;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background: var(--bg-sidebar-active);
  color: #ffffff;
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  text-align: center;
  opacity: 0.9;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
}

.storage-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11.5px;
}

.dot-green {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

.storage-note {
  margin-top: 6px;
  color: #94a3b8;
  font-size: 11px;
}

.main-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.page-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.content-area {
  padding: 24px 28px 40px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* Cards & Grid */
.grid {
  display: grid;
  gap: 18px;
}

.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #fff; border-color: var(--border-strong); color: var(--text-primary); }
.btn-secondary:hover { background: #f8fafc; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: #f1f5f9; color: var(--text-primary); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: capitalize;
}
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-sent { background: #eff6ff; color: #1d4ed8; }
.badge-partial { background: var(--warning-soft); color: var(--warning); }
.badge-paid, .badge-accepted, .badge-converted { background: var(--success-soft); color: var(--success); }
.badge-overdue, .badge-declined, .badge-unpaid { background: var(--danger-soft); color: var(--danger); }
.badge-void { background: #e2e8f0; color: #64748b; text-decoration: line-through; }

/* Toolbar & Filters */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tabs {
  display: inline-flex;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 8px;
  gap: 2px;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 6px 13px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.tab-btn.active {
  background: #fff;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover {
  background: #f8fafc;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-primary);
  background: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.input-sm {
  padding: 6px 8px;
  font-size: 13px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-backdrop.hidden, .hidden {
  display: none !important;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 680px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal.modal-lg { max-width: 980px; }
.modal.modal-xl { max-width: 1120px; }

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* Invoice Line Items Builder */
.line-items-table th, .line-items-table td {
  padding: 7px 6px;
}

.totals-box {
  margin-left: auto;
  width: 320px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13.5px;
}

.totals-row.grand {
  border-top: 2px solid var(--border-strong);
  margin-top: 6px;
  padding-top: 8px;
  font-size: 16px;
  font-weight: 800;
}

/* Printable Invoice Sheet */
.invoice-sheet {
  background: #fff;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #0f172a;
}

.inv-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 2px solid #2563eb;
  padding-bottom: 18px;
  margin-bottom: 20px;
}

.inv-brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 6px;
}

.inv-logo-badge {
  width: 74px;
  height: 74px;
  background: transparent;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.inv-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0.62) contrast(1.35) saturate(1.25) drop-shadow(0 1px 1px rgba(15, 23, 42, 0.25));
}

.inv-system-note {
  margin-top: 22px;
  padding-top: 10px;
  border-top: 1px dashed #cbd5e1;
  text-align: center;
  font-size: 11.5px;
  color: #64748b;
}

.inv-company-name {
  font-size: 22px;
  font-weight: 800;
  color: #060d1b;
}

.inv-doc-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2563eb;
  text-align: right;
}

/* Toast */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  max-width: 380px;
}

.toast.toast-success { border-left: 4px solid #10b981; }
.toast.toast-error { border-left: 4px solid #ef4444; }

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  height: 190px;
  padding: 16px 8px 6px;
  border-bottom: 1px solid var(--border);
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  gap: 6px;
}

.chart-pair {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: 100%;
  justify-content: center;
  height: 140px;
}

.bar-rev {
  width: 16px;
  background: #2563eb;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}

.bar-exp {
  width: 16px;
  background: #f59e0b;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}

.chart-label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.print-only { display: none; }

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  body { background: #fff; }
  .app-shell, .modal-backdrop, .toast-stack { display: none !important; }
  .print-only { display: block !important; }
  .invoice-sheet { border: none; padding: 0; }
}
