@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700;800&family=DM+Sans:wght@300;400;500;600&display=swap');

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

:root {
  --sidebar-bg:    #0d0d14;
  --sidebar-hover: rgba(167,139,250,0.1);
  --accent:        #A78BFA;
  --accent-dark:   #7C3AED;
  --accent-light:  rgba(167,139,250,0.15);
  --text-primary:  #ffffff;
  --text-secondary:rgba(255,255,255,0.55);
  --text-muted:    rgba(255,255,255,0.35);
  --bg:            #0f0f1a;
  --surface:       #16161f;
  --border:        rgba(255,255,255,0.08);
  --border-light:  rgba(255,255,255,0.04);
  --success:       #10b981;
  --success-bg:    rgba(16,185,129,0.12);
  --warning:       #f59e0b;
  --warning-bg:    rgba(245,158,11,0.12);
  --danger:        #ef4444;
  --danger-bg:     rgba(239,68,68,0.12);
  --gray-badge:    rgba(255,255,255,0.55);
  --gray-badge-bg: rgba(255,255,255,0.07);
  --shadow-sm:     0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow:        0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:     0 10px 40px rgba(0,0,0,.5);
  --radius:        12px;
  --radius-sm:     8px;
  --sidebar-w:     260px;
  --font:          'Space Grotesk', 'DM Sans', system-ui, sans-serif;
}

html { font-size: 15px; }

body {
  font-family: var(--font);
  background:  var(--bg);
  color:       var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 28px 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.logo-img {
  height: 38px;
  width: auto;
  flex-shrink: 0;
  display: block;
}

.logo-text {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.2px;
}

.logo-sub {
  color: rgba(255,255,255,.4);
  font-size: 11px;
  font-weight: 400;
  margin-top: 1px;
}

.sidebar-section {
  padding: 20px 16px 8px;
}

.sidebar-section-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: 0 8px 8px;
}

.sidebar-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.65);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
  text-decoration: none;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: rgba(255,255,255,.9);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: rgba(167,139,250,.18);
  color: #fff;
}

.sidebar-nav a.active .nav-icon { color: var(--accent); }

.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: .75;
}

.sidebar-nav a.active .nav-icon,
.sidebar-nav a:hover .nav-icon { opacity: 1; }

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

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
}

.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name {
  color: rgba(255,255,255,.85);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  color: rgba(255,255,255,.35);
  font-size: 11px;
}

.logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.3);
  padding: 4px;
  border-radius: 6px;
  transition: color .15s;
  display: flex;
  align-items: center;
}
.logout-btn:hover { color: rgba(255,255,255,.7); }
.logout-btn svg { width: 16px; height: 16px; }

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.3px;
}

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

.page-body {
  padding: 32px;
  flex: 1;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.2px;
}

.card-body { padding: 20px 24px; }

/* ── Stats Row ────────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.stat-icon.blue  { background: var(--accent-light); color: var(--accent); }
.stat-icon.green { background: var(--success-bg);   color: var(--success); }
.stat-icon.amber { background: var(--warning-bg);   color: var(--warning); }
.stat-icon.red   { background: var(--danger-bg);    color: var(--danger); }

.stat-icon svg { width: 22px; height: 22px; }

.stat-body { flex: 1; }

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -.5px;
  line-height: 1.1;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, box-shadow .15s, opacity .15s, transform .1s;
  border: none;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  color: #0d0d14;
  box-shadow: 0 2px 8px rgba(167,139,250,.35);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
  color: #fff;
  box-shadow: 0 4px 14px rgba(167,139,250,.4);
}

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

.btn-success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16,185,129,.3);
}
.btn-success:hover:not(:disabled) { background: #0ea271; }

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--border-light);
  color: var(--text-primary);
}

.btn-sm { padding: 6px 13px; font-size: 13px; }
.btn-lg { padding: 12px 26px; font-size: 15px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
}

.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-paid  { background: var(--success-bg); color: var(--success); }
.badge-sent  { background: var(--warning-bg); color: var(--warning); }
.badge-draft { background: var(--gray-badge-bg); color: var(--gray-badge); }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead tr {
  background: var(--border-light);
  border-bottom: 1px solid var(--border);
}

th {
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  white-space: nowrap;
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.td-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.td-muted { color: var(--text-secondary); font-size: 13px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167,139,250,.15);
}

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

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%23A78BFA' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
  padding-right: 36px;
}

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

.form-row-3 {
  display: grid;
  grid-template-columns: 2fr 1fr 1.2fr auto;
  gap: 12px;
  align-items: end;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 2px;
}

/* ── Alert / Toast ────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-error   { background: var(--danger-bg);  color: #ff8080;  border: 1px solid rgba(239,68,68,.25); }
.alert-success { background: var(--success-bg); color: #4ade80; border: 1px solid rgba(16,185,129,.25); }
.alert-info    { background: var(--accent-light); color: var(--accent); border: 1px solid rgba(167,139,250,.25); }

.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: #1a1f2e;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideUp .25s ease;
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  max-width: 360px;
}

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

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Login Page ───────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0d0d14;
  background-image: radial-gradient(rgba(167,139,250,0.08) 1px, transparent 1px);
  background-size: 44px 44px;
  padding: 24px;
}

.login-box {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 48px 44px;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 36px;
  gap: 12px;
}

.login-logo-img {
  height: 64px;
  width: auto;
  display: block;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -.4px;
}

.login-logo p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: -6px;
}

.login-form .form-group { margin-bottom: 16px; }

.login-form .btn-primary {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  margin-top: 8px;
}

/* ── Invoice Detail ───────────────────────────────────────────────────────── */
.invoice-header-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 32px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 24px;
}

.invoice-from { display: flex; flex-direction: column; gap: 4px; }
.invoice-from .company-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -.3px;
}
.invoice-from .company-sub { color: var(--text-secondary); font-size: 14px; }

.invoice-meta {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.invoice-number {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -.4px;
}

.invoice-meta-row {
  font-size: 13px;
  color: var(--text-secondary);
}

.invoice-meta-row strong { color: var(--text-primary); }

.line-items-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 24px;
}

.invoice-totals {
  padding: 20px 24px;
  border-top: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.total-row {
  display: flex;
  gap: 40px;
  font-size: 14px;
}

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

.total-label { color: var(--text-secondary); }
.total-amount { font-weight: 600; min-width: 100px; text-align: right; font-variant-numeric: tabular-nums; }

/* ── Stripe Payment Section ───────────────────────────────────────────────── */
.payment-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 2px solid var(--accent);
  box-shadow: 0 4px 24px rgba(167,139,250,.15);
  padding: 32px;
  margin-bottom: 24px;
}

.payment-card h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

#payment-element { margin-bottom: 20px; }

#payment-message {
  margin-top: 12px;
  font-size: 14px;
}

/* ── Admin Panel ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.4px;
  color: var(--text-primary);
}

.page-header p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 2px;
}

/* ── Line Items Builder ───────────────────────────────────────────────────── */
#line-items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.line-item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1.3fr auto;
  gap: 10px;
  align-items: center;
}

.line-item-row input { margin-bottom: 0; }

.remove-item-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--danger);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}

.remove-item-btn:hover { background: var(--danger-bg); }
.remove-item-btn svg { width: 15px; height: 15px; }

.line-items-header {
  display: grid;
  grid-template-columns: 2fr 1fr 1.3fr auto;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  padding: 0 2px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

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

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  padding: 32px;
  transform: translateY(16px);
  transition: transform .2s;
}

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

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

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

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 6px;
  transition: color .15s;
  display: flex;
  align-items: center;
}
.modal-close:hover { color: var(--text-primary); }
.modal-close svg { width: 20px; height: 20px; }

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  color: var(--text-muted);
  display: block;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-state p { font-size: 14px; }

/* ── Loading Spinner ──────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}

.spinner-dark {
  border-color: rgba(167,139,250,.2);
  border-top-color: var(--accent);
}

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

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px;
}

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

.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-0 { margin-bottom: 0; }
.mt-auto { margin-top: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(167,139,250,.25);
}

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

  .stats-row { grid-template-columns: 1fr 1fr; }
  .form-row  { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
  .line-item-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .stats-row { grid-template-columns: 1fr; }
  .login-box { padding: 32px 24px; }
  .invoice-header-card { flex-direction: column; }
  .invoice-meta { text-align: left; }
}
