/* styles.css */
:root {
  --bg-body: #f4f6f9;
  --bg-surface: #ffffff;
  --bg-sidebar: #111827;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --text-sidebar: #d1d5db;
  --border-color: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 10px;
}

[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-surface: #1e293b;
  --bg-sidebar: #090d16;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
}

body {
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}

.hidden { display: none !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }

/* AUTH VIEW */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 2.25rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.brand-logo {
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.brand-logo.sm { width: 36px; height: 36px; font-size: 0.95rem; margin-bottom: 0; }
.brand-logo.danger { background: var(--danger); }

.auth-header p { color: var(--text-muted); font-size: 0.875rem; margin-top: 0.25rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.35rem; }

input, select, textarea, .form-control {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.9rem;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.auth-actions { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1.25rem; }

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border-color);
}
.divider span { padding: 0 0.75rem; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border-color: var(--border-color); color: var(--text-main); }
.btn-outline:hover { background: rgba(128, 128, 128, 0.1); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-google { background: var(--bg-surface); border-color: var(--border-color); color: var(--text-main); }
.btn-google:hover { background: rgba(128, 128, 128, 0.08); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.45rem;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* APP SHELL & SIDEBAR */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-wrap { display: flex; align-items: center; gap: 0.75rem; }
.brand-wrap h2 { color: #fff; font-size: 1.05rem; display: inline; }
.badge-pro {
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  vertical-align: middle;
}

.sidebar-nav { padding: 1rem 0.75rem; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  color: var(--text-sidebar);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover, .nav-item.active {
  background: rgba(37, 99, 235, 0.18);
  color: #fff;
}
.nav-item svg { width: 18px; height: 18px; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.user-profile-box { display: flex; align-items: center; gap: 0.65rem; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.user-meta { overflow: hidden; }
.user-meta strong { display: block; font-size: 0.8rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-pill { font-size: 0.7rem; background: rgba(255, 255, 255, 0.12); padding: 1px 6px; border-radius: 4px; color: #93c5fd; }

.main-wrapper {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 64px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-left h2 { font-size: 1.15rem; }

.content-area { padding: 1.5rem; max-width: 1400px; width: 100%; margin: 0 auto; }

/* CARDS & GRIDS */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card-header { margin-bottom: 1rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.kpi-value { font-size: 1.5rem; margin-top: 0.35rem; font-weight: 700; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.25rem;
}
.two-col-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 1.25rem;
}
.chart-container { position: relative; height: 290px; width: 100%; }

.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* TABLES */
.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th, .data-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}
.data-table th { font-weight: 600; color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; }

/* STATUS BADGES */
.badge {
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-Paid, .badge-Active { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-Sent { background: rgba(37, 99, 235, 0.15); color: var(--primary); }
.badge-Draft { background: rgba(107, 114, 128, 0.15); color: var(--text-muted); }
.badge-Overdue, .badge-Blocked { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* REPORTS */
.report-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; }
.report-buttons { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.report-header { text-align: center; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border-color); }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 60;
}
.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* TOAST */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 99;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: #1f2937;
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  border-left: 4px solid var(--primary);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

/* MOBILE RESPONSIVE */
.mobile-only { display: none; }
@media (max-width: 900px) {
  .mobile-only { display: inline-flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .dashboard-grid, .two-col-grid, .form-row { grid-template-columns: 1fr; }
}

/* PRINT STYLES */
.invoice-print-container { display: none; }
@media print {
  body * { visibility: hidden; }
  body.printing-invoice #invoice-print-area,
  body.printing-invoice #invoice-print-area * {
    visibility: visible;
  }
  body.printing-invoice #invoice-print-area {
    display: block;
    position: absolute;
    left: 0; top: 0; width: 100%;
    background: #fff; color: #000; padding: 2rem;
  }
  body:not(.printing-invoice) .printable-area,
  body:not(.printing-invoice) .printable-area * {
    visibility: visible;
  }
  body:not(.printing-invoice) .printable-area {
    position: absolute;
    left: 0; top: 0; width: 100%;
    background: #fff; color: #000; border: none; box-shadow: none;
  }
}