/* ─── CSS Variables ──────────────────────────────────────────────────────── */
:root {
  --bg:           #f0f2f5;
  --surface:      #ffffff;
  --surface-2:    #f8f9fa;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --primary:      #2563eb;
  --primary-h:    #1d4ed8;
  --primary-light:#dbeafe;
  --danger:       #dc2626;
  --danger-h:     #b91c1c;
  --danger-light: #fee2e2;
  --success:      #16a34a;
  --success-light:#dcfce7;
  --warning:      #d97706;
  --warning-light:#fef3c7;
  --info:         #0284c7;
  --info-light:   #e0f2fe;
  --sidebar-w:    240px;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:    0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
}

[data-theme="dark"] {
  --bg:           #0f172a;
  --surface:      #1e293b;
  --surface-2:    #162032;
  --border:       #334155;
  --text:         #f1f5f9;
  --text-muted:   #94a3b8;
  --primary:      #3b82f6;
  --primary-h:    #60a5fa;
  --primary-light:#1e3a5f;
  --danger:       #ef4444;
  --danger-h:     #f87171;
  --danger-light: #450a0a;
  --success:      #22c55e;
  --success-light:#052e16;
  --warning:      #f59e0b;
  --warning-light:#451a03;
  --info:         #38bdf8;
  --info-light:   #0c2a3e;
  --shadow:       0 1px 3px rgba(0,0,0,.3);
  --shadow-md:    0 4px 6px -1px rgba(0,0,0,.4);
}

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

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

.sidebar {
  width: var(--sidebar-w);
  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;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}

.sidebar-brand .brand-sub {
  font-size: .75rem;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
}

.nav-section-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: 12px 8px 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
  text-decoration: none;
  margin-bottom: 2px;
}

.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-light); color: var(--primary); }

.nav-link .nav-icon { font-size: 1rem; width: 20px; text-align: center; }

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

.sidebar-footer .user-email {
  font-size: .8rem;
  color: var(--text-muted);
  padding: 4px 8px;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.page-body { padding: 24px; }

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

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

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .brand { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.login-logo .tagline { font-size: .85rem; color: var(--text-muted); }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

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

.card-title { font-size: 1rem; font-weight: 600; }
.card-body  { padding: 20px; }

/* ─── Stat cards (dashboard) ─────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 6px; }
.stat-note  { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }

.btn-danger    { background: var(--danger);   color: #fff; }
.btn-danger:hover:not(:disabled)  { background: var(--danger-h); }

.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost     { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-sm  { padding: 5px 10px; font-size: .8rem; }
.btn-lg  { padding: 11px 22px; font-size: 1rem; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: 6px; color: var(--text); }

.form-control {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .875rem;
  transition: border-color .15s;
  outline: none;
}

.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }

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

.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.form-check label { font-size: .875rem; cursor: pointer; margin: 0; font-weight: 400; }

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

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:hover td { background: var(--surface-2); }
tr:last-child td { border-bottom: none; }

.td-right { text-align: right; }
.td-center { text-align: center; }

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

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

.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: .95rem; }

/* ─── Tabs ───────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }

.tab-btn {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-success   { background: var(--success-light);  color: var(--success); }
.badge-danger    { background: var(--danger-light);   color: var(--danger); }
.badge-warning   { background: var(--warning-light);  color: var(--warning); }
.badge-info      { background: var(--info-light);     color: var(--info); }
.badge-secondary { background: var(--surface-2);      color: var(--text-muted); border: 1px solid var(--border); }
.badge-muted     { background: var(--border);          color: var(--text-muted); }

/* ─── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-info    { background: var(--info-light);    color: var(--info); }
.alert-success { background: var(--success-light); color: var(--success); }
.alert-warning { background: var(--warning-light); color: var(--warning); }
.alert-error   { background: var(--danger-light);  color: var(--danger); }

/* ─── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-box h3  { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }
.modal-message { margin-bottom: 20px; color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ─── Dropdowns ──────────────────────────────────────────────────────────── */
.input-wrapper { position: relative; }

.dropdown-list {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-height: 220px;
  overflow-y: auto;
}

.dropdown-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: .875rem;
  border-bottom: 1px solid var(--border);
}

.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover      { background: var(--surface-2); }
.dropdown-item.muted      { color: var(--text-muted); cursor: default; }

/* ─── Invoice form specific ──────────────────────────────────────────────── */
.invoice-totals {
  width: 100%;
  max-width: 340px;
  margin-left: auto;
  margin-top: 16px;
}

.invoice-totals table { font-size: .9rem; }
.invoice-totals td    { padding: 6px 8px; border: none; }
.invoice-totals .total-label { color: var(--text-muted); }
.invoice-totals .total-value { text-align: right; font-weight: 500; }
.invoice-totals .grand-total td { font-weight: 700; font-size: 1rem; border-top: 2px solid var(--border); padding-top: 10px; }

.discount-cell { display: flex; gap: 4px; }
.discount-cell .form-control:first-child { flex: 1; }
.discount-cell select { width: 55px; }

.line-qty, .line-amount, .line-disc-val { text-align: right; }

.email-addresses-row { display: flex; gap: 8px; align-items: center; }
.email-addresses-row .form-control { flex: 1; }

.contact-balance-info {
  background: var(--success-light);
  color: var(--success);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: .85rem;
  margin-top: 6px;
}

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

.toast {
  padding: 12px 18px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  max-width: 320px;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast-info    { background: var(--info);    color: #fff; }
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 16px; }

.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  color: var(--text);
}

.page-btn:hover  { background: var(--surface-2); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ─── Misc utilities ─────────────────────────────────────────────────────── */
.muted     { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-8  { gap: 8px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.ml-auto { margin-left: auto; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.loading-spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

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

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

.section-title { font-size: 1rem; font-weight: 600; }

/* ─── BAS / Activity Statement ───────────────────────────────────────────── */
.bas-table { width: 100%; border-collapse: collapse; }
.bas-table th, .bas-table td { padding: 10px 16px; border: 1px solid var(--border); }
.bas-table th { background: var(--surface-2); font-weight: 600; }
.bas-section-header td { background: var(--primary-light); font-weight: 700; color: var(--primary); }
.bas-value { text-align: right; font-weight: 500; }
.bas-total td { font-weight: 700; background: var(--surface-2); }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }

  .page-header { padding: 12px 16px; }
  .page-body   { padding: 16px; }

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

  .hamburger { display: flex !important; }

  table { font-size: .8rem; }
  th, td { padding: 8px; }
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: var(--text);
  font-size: 1.3rem;
}
