:root {
  --red: #E93323;
  --grey: #676767;
  --dark: #1a1a1a;
  --light: #f5f5f5;
  --white: #ffffff;
  --border: #e2e2e2;
  --sidebar-w: 220px;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--light);
  color: var(--dark);
  font-size: 14px;
  line-height: 1.5;
}

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

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--dark);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo .brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  color: white;
}
.sidebar-logo .sub {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--red);
  margin-top: 3px;
  text-transform: uppercase;
}

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

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  padding: 14px 20px 6px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  font-size: 13px;
  transition: all 0.12s;
}
.sidebar-nav a:hover {
  background: rgba(255,255,255,0.06);
  color: white;
}
.sidebar-nav a.active {
  background: rgba(233,51,35,0.15);
  color: white;
  border-left: 3px solid var(--red);
}
.sidebar-nav .icon { width: 18px; text-align: center; }

.hidden { display: none !important; }

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: white; }
.sidebar-user .user-role { font-size: 11px; color: rgba(255,255,255,0.4); margin-bottom: 10px; }

.logout-btn {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  border: none;
  padding: 7px 14px;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.12s;
}
.logout-btn:hover { background: rgba(255,255,255,0.14); color: white; }

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

.topbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.page-content { padding: 28px 32px; }

/* ── Cards ── */
.card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}
.card-header h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--grey);
  margin: 0;
}
.card-body { padding: 24px; }

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  text-align: center;
}
.stat-num { font-size: 30px; font-weight: 700; color: var(--dark); }
.stat-label { font-size: 12px; color: var(--grey); margin-top: 4px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none !important;
  transition: all 0.12s;
  white-space: nowrap;
}
.btn-primary { background: var(--red); color: white !important; }
.btn-primary:hover { background: #c72b1d; }
.btn-secondary { background: white; color: var(--dark) !important; border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--light); }
.btn-success { background: #2e7d32; color: white !important; }
.btn-success:hover { background: #1b5e20; }
.btn-danger { background: #c62828; color: white !important; }
.btn-danger:hover { background: #b71c1c; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; }
thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--grey);
  padding: 10px 16px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  background: #fafafa;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafafa; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.badge-draft { background: #f0f0f0; color: #555; }
.badge-generated { background: #e3f2fd; color: #1565c0; }
.badge-executed { background: #e8f5e9; color: #2e7d32; }
.badge-scanned { background: #f3e5f5; color: #6a1b9a; }
.badge-admin { background: #fff3e0; color: #e65100; }
.badge-planner { background: #e8f5e9; color: #1b5e20; }
.badge-active { background: #e8f5e9; color: #2e7d32; }
.badge-inactive { background: #ffebee; color: #c62828; }

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

.form-group label,
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--dark);
}
.required { color: var(--red); }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--dark);
  background: white;
  transition: border-color 0.12s;
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(233,51,35,0.08);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

.form-hint { font-size: 11px; color: var(--grey); margin-top: 4px; }

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.alert-error { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; }
.alert-info { background: #e3f2fd; color: #1565c0; border: 1px solid #90caf9; }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--dark);
}
.login-card {
  background: white;
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-brand { text-align: center; margin-bottom: 32px; }
.login-brand .brand { font-size: 20px; font-weight: 700; letter-spacing: 4px; color: var(--dark); }
.login-brand .sub { font-size: 10px; letter-spacing: 2px; color: var(--red); text-transform: uppercase; margin-top: 4px; }

/* ── Wizard ── */
.wizard-progress {
  display: flex;
  align-items: center;
  margin-bottom: 28px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.wizard-step {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.step-circle {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  color: var(--grey);
  background: white;
  transition: all 0.2s;
}
.step-label {
  font-size: 11px;
  color: var(--grey);
  margin-left: 6px;
  white-space: nowrap;
}
.wizard-step.active .step-circle { background: var(--red); border-color: var(--red); color: white; }
.wizard-step.active .step-label { color: var(--dark); font-weight: 500; }
.wizard-step.done .step-circle { background: #2e7d32; border-color: #2e7d32; color: white; }
.step-connector { flex: 1; height: 2px; background: var(--border); margin: 0 8px; min-width: 24px; }
.wizard-step.done + .wizard-step .step-connector,
.step-connector.done { background: #2e7d32; }

.wizard-section { display: none; }
.wizard-section.active { display: block; }

.gift-row, .beneficiary-row {
  background: var(--light);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  position: relative;
}
.remove-row-btn {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; cursor: pointer;
  color: #999; font-size: 16px;
}
.remove-row-btn:hover { color: var(--red); }
.add-row-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 10px;
  width: 100%;
  cursor: pointer;
  color: var(--grey);
  font-size: 13px;
  margin-top: 8px;
  transition: all 0.12s;
}
.add-row-btn:hover { border-color: var(--red); color: var(--red); background: rgba(233,51,35,0.03); }

.wizard-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ── Toast ── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--dark);
  color: white;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 300px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: slideIn 0.2s ease;
}
.toast.success { background: #2e7d32; }
.toast.error { background: #c62828; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Utility ── */
.text-muted { color: var(--grey); }
.text-right { text-align: right; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.max-w-md { max-width: 640px; }
.empty-state { text-align: center; padding: 48px; color: var(--grey); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }

/* ── Layout aliases (normalize both class name variants) ── */
.layout { display: flex; min-height: 100vh; }
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; overflow-x: hidden; }

/* Topbar title alias */
.topbar-title { font-size: 18px; font-weight: 600; }

/* Sidebar brand alias */
.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .brand { font-size: 15px; font-weight: 700; letter-spacing: 3px; color: white; }
.sidebar-brand .sub { font-size: 10px; letter-spacing: 1.5px; color: var(--red); margin-top: 3px; text-transform: uppercase; }
.sidebar-brand .app-label { font-size: 11px; color: rgba(255,255,255,0.35); margin-top: 6px; }

/* Sidebar footer alias */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-footer .user-name { font-size: 13px; font-weight: 600; color: white; }
.sidebar-footer .user-role { font-size: 11px; color: rgba(255,255,255,0.4); margin-bottom: 10px; }

/* Search bar */
.search-bar { display: flex; gap: 10px; padding: 16px; border-bottom: 1px solid var(--border); }
.search-bar .form-control { flex: 1; }

/* Table overflow fix */
.card { overflow-x: auto; }
#clientsTable, #willsTable, #plannersTable { overflow-x: auto; }

/* ── Sidebar JS-rendered class aliases ── */
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: 3px; color: white; }
.brand-sub { font-size: 10px; letter-spacing: 1.5px; color: var(--red); margin-top: 3px; }
.brand-app { font-size: 11px; color: rgba(255,255,255,0.35); margin-top: 6px; }

.sidebar-nav .nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  font-size: 13px;
  transition: all 0.12s;
}
.sidebar-nav .nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.sidebar-nav .nav-item.active { background: rgba(233,51,35,0.15); color: white; border-left: 3px solid var(--red); }
.nav-icon { width: 20px; text-align: center; }

.user-info .user-name { font-size: 13px; font-weight: 600; color: white; margin-bottom: 2px; }
.user-info div { font-size: 11px; color: rgba(255,255,255,0.4); }
