:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3347;
  --accent: #4f8ef7;
  --accent-hover: #3a7ae6;
  --accent-light: rgba(79,142,247,0.12);
  --text: #e8eaf0;
  --text-muted: #8b90a4;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --paid: #22c55e;
  --sent: #3b82f6;
  --draft: #8b90a4;
  --overdue: #ef4444;
  --viewed: #a855f7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: all 0.2s ease;
}

[data-theme="light"] {
  --bg: #f0f2f8;
  --surface: #ffffff;
  --surface2: #f5f7ff;
  --border: #e2e5f0;
  --text: #1a1d27;
  --text-muted: #6b7080;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* LAYOUT */
.app { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: var(--transition);
}

.sidebar-logo {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.sidebar-logo span {
  font-size: 11px;
  color: var(--text-muted);
}

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

.nav-section {
  margin-bottom: 8px;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  font-weight: 500;
  font-size: 13.5px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-light); color: var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}

/* MAIN CONTENT */
.main {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.page { padding: 28px; flex: 1; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn svg { width: 16px; height: 16px; }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

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

.card-title { font-size: 15px; font-weight: 600; color: var(--text); }

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: var(--transition);
}

.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); }
.stat-sub { font-size: 12px; color: var(--text-muted); }
.stat-icon { font-size: 28px; margin-bottom: 4px; }

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

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

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--text);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-paid { background: rgba(34,197,94,0.15); color: var(--paid); }
.badge-sent { background: rgba(59,130,246,0.15); color: var(--sent); }
.badge-draft { background: rgba(139,144,164,0.15); color: var(--draft); }
.badge-overdue { background: rgba(239,68,68,0.15); color: var(--overdue); }
.badge-viewed { background: rgba(168,85,247,0.15); color: var(--viewed); }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input, select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  transition: var(--transition);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

select option { background: var(--surface); }
textarea { resize: vertical; min-height: 80px; }

/* LINE ITEMS */
.line-items-table { width: 100%; border-collapse: collapse; }
.line-items-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.line-items-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.line-items-table input {
  background: transparent;
  border: 1px solid transparent;
  padding: 7px 8px;
}
.line-items-table input:focus { background: var(--surface2); border-color: var(--accent); }
.line-items-table .amount-cell { text-align: right; padding: 6px 10px; color: var(--text); font-weight: 500; }

/* TOTALS */
.totals-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  min-width: 280px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.total-row.grand {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform 0.2s;
  box-shadow: var(--shadow);
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-title { font-size: 18px; font-weight: 700; }

/* ALERTS */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--success); }
.alert-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--danger); }
.alert-info { background: rgba(79,142,247,0.1); border: 1px solid rgba(79,142,247,0.3); color: var(--accent); }

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }

/* SEARCH & FILTER BAR */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-input input { padding-left: 36px; }
.search-input svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 16px;
  height: 16px;
}

/* LOGIN PAGE */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-box {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 22px; font-weight: 800; color: var(--accent); }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* INVOICE PREVIEW */
.invoice-preview {
  background: #f5f0e8;
  color: #000000;
  padding: 32px 40px;
  border-radius: var(--radius);
  max-width: 800px;
  margin: 0 auto;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.inv-logo { font-size: 18px; font-weight: 800; color: #000; }
.inv-number-box { background: #4f8ef7; border-radius: 8px; padding: 12px 16px; min-width: 220px; }
.inv-number-row { display: flex; justify-content: space-between; gap: 24px; padding: 3px 0; font-size: 12px; color: white; }
.inv-number-row span:first-child { opacity: 0.85; }
.inv-number-row span:last-child { font-weight: 600; }
.inv-addresses { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 24px; }
.inv-address-label { font-size: 7px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: #c4c9d4; margin-bottom: 3px; }
.inv-address-name { font-size: 13px; font-weight: 600; color: #000; }
.inv-address-detail { font-size: 12px; color: #000; line-height: 1.6; }
.inv-dates { display: flex; gap: 24px; margin-bottom: 24px; padding: 10px 14px; background: #ede8df; border-radius: 8px; }
.inv-date-item label { font-size: 9px; font-weight: 700; text-transform: uppercase; color: #6b7080; }
.inv-date-item div { font-size: 12px; font-weight: 600; color: #000; }
.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; border: 2px solid #4f8ef7; }
.inv-table th { background: #4f8ef7; color: white; padding: 8px 12px; text-align: left; font-size: 11px; font-weight: 600; }
.inv-table td { padding: 9px 12px; border-bottom: 2px solid #4f8ef7; font-size: 12px; color: #000; }
.inv-table tr:last-child td { border-bottom: none; }
.inv-table tr:nth-child(even) td { background: #ede8df; }
.inv-table tr:hover td { background: inherit; }
.inv-totals { display: flex; justify-content: flex-end; margin-bottom: 24px; }
.inv-totals-box { min-width: 220px; }
.inv-total-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12.5px; color: #000; }
.inv-total-row.grand { border-top: 2px solid #000; margin-top: 6px; padding-top: 8px; font-size: 16px; font-weight: 800; color: #000; }
.inv-notes { padding: 12px 14px; background: #ede8df; border-radius: 8px; }
.inv-notes h4 { font-size: 10px; font-weight: 700; text-transform: uppercase; color: #6b7080; margin-bottom: 4px; }
.inv-notes p { font-size: 12px; color: #000; }

/* THEME TOGGLE */
.theme-toggle {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 16px;
  transition: var(--transition);
}
.theme-toggle:hover { background: var(--border); }

/* HAMBURGER BUTTON */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text);
  margin-right: 8px;
}
.hamburger svg { width: 22px; height: 22px; }

/* SIDEBAR OVERLAY */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* RESPONSIVE */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    position: fixed;
    z-index: 100;
    height: 100vh;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page { padding: 16px; }
  .hamburger { display: flex; align-items: center; }
}

/* UTILITIES */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.hidden { display: none !important; }

/* PRINT */
@page { margin: 0.6cm 0.8cm; size: letter; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin-left: 0; }
  .page { padding: 0; }
  body { background: white; font-size: 12px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .invoice-preview {
    box-shadow: none;
    padding: 14px 22px;
    max-width: 100%;
    font-size: 12px;
  }

  .inv-header { margin-bottom: 14px; }
  .inv-logo { font-size: 16px; }
  .inv-number-box { padding: 9px 12px; border-radius: 6px; }
  .inv-number-row { font-size: 11.5px; padding: 2.5px 0; }
  .inv-addresses { margin-bottom: 14px; gap: 20px; }
  .inv-address-name { font-size: 12px; }
  .inv-address-detail { font-size: 11px; line-height: 1.5; }

  .inv-table th { padding: 7px 9px; font-size: 11px; }
  .inv-table td { padding: 7px 9px; font-size: 11px; line-height: 1.45; }
  .inv-table { margin-bottom: 14px; }

  .inv-totals { margin-bottom: 14px; }
  .inv-totals-box { min-width: 180px; }
  .inv-total-row { font-size: 11px; padding: 3px 0; }
  .inv-total-row.grand { font-size: 14px; margin-top: 5px; padding-top: 7px; }

  .inv-notes { padding: 9px 11px; margin-bottom: 0; }
  .inv-notes h4 { font-size: 10.5px; }
  .inv-notes p { font-size: 11px; line-height: 1.45; }

  .mb-6 { margin-bottom: 14px; }
}
