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

:root {
  --ink: #0a0a0a;
  --paper: #fafaf8;
  --accent: #e85d26;
  --accent-glow: #ff7a45;
  --accent-light: rgba(232, 93, 38, 0.08);
  --muted: #6b6b6b;
  --muted-light: #999;
  --border: #e0ddd8;
  --card-bg: #f4f3f0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
}

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

.sidebar {
  width: 240px;
  background: var(--ink);
  color: var(--paper);
  padding: 24px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
  padding: 0 24px 32px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo span { color: var(--accent); }

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  color: var(--muted-light);
  text-decoration: none;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  color: var(--paper);
  background: rgba(255,255,255,0.05);
}

.nav-item.active {
  color: var(--paper);
  background: rgba(232, 93, 38, 0.15);
  border-right: 3px solid var(--accent);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

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

.sidebar-user {
  font-size: 0.85rem;
  color: var(--muted-light);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--muted-light);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}

.btn-logout:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 32px 40px;
  max-width: 1200px;
}

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

.page-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  font-family: 'DM Sans', sans-serif;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-glow);
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
}

.btn-ghost:hover {
  color: var(--ink);
  background: var(--card-bg);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.08);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #16a34a;
}

/* Cards */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

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

.card-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 600;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }
.stat-value.danger { color: var(--danger); }

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

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

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

tr:hover td {
  background: var(--accent-light);
}

.clickable-row {
  cursor: pointer;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.badge-draft { background: var(--card-bg); color: var(--muted); }
.badge-active { background: rgba(59, 130, 246, 0.1); color: var(--info); }
.badge-sent { background: rgba(59, 130, 246, 0.1); color: var(--info); }
.badge-paid { background: rgba(34, 197, 94, 0.1); color: var(--success); }
.badge-overdue { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.badge-completed { background: rgba(34, 197, 94, 0.1); color: var(--success); }
.badge-archived { background: var(--card-bg); color: var(--muted); }

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--ink);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: 'DM Sans', sans-serif;
  background: white;
  color: var(--ink);
  transition: border-color 0.15s ease;
}

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

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

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

.modal {
  background: white;
  border-radius: 16px;
  padding: 32px;
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

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

.modal-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.92rem;
  margin-bottom: 20px;
}

/* Auth page */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  padding: 20px;
}

.auth-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.auth-logo span { color: var(--accent); }

.auth-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 32px;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-toggle a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}

.auth-toggle a:hover {
  text-decoration: underline;
}

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 16px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.08);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
  background: rgba(34, 197, 94, 0.08);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--ink);
  color: var(--paper);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast.error { border-left: 3px solid var(--danger); }
.toast.success { border-left: 3px solid var(--success); }

@keyframes slideIn {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Invoice view */
.invoice-view {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px;
  max-width: 800px;
}

.invoice-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 40px;
}

.invoice-from h2, .invoice-to h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 8px;
}

.invoice-from p, .invoice-to p {
  font-size: 0.92rem;
  line-height: 1.6;
}

.invoice-meta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
  padding: 20px 0;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.invoice-meta-item label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}

.invoice-meta-item span {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
}

.invoice-total-row {
  display: flex;
  justify-content: flex-end;
  padding: 12px 16px;
  font-size: 0.92rem;
}

.invoice-total-row.total {
  background: var(--ink);
  color: var(--paper);
  border-radius: 8px;
  margin-top: 4px;
}

.invoice-total-row .label {
  width: 120px;
  text-align: right;
  margin-right: 24px;
}

.invoice-total-row .value {
  width: 120px;
  text-align: right;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Mobile hamburger */
.hamburger {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
  .hamburger { display: block; }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding: 20px 16px;
    padding-top: 60px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .invoice-meta {
    grid-template-columns: 1fr 1fr;
  }

  .invoice-header-row {
    flex-direction: column;
    gap: 24px;
  }

  .invoice-view {
    padding: 24px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Print styles */
@media print {
  .sidebar, .page-header .btn, .hamburger, .toast-container { display: none !important; }
  .main-content { margin-left: 0; padding: 0; }
  .invoice-view { border: none; box-shadow: none; padding: 0; }
}
