:root {
  /* Sanduku la Maoni brand colors, sampled from the official logo */
  --brand-red: #F70909;
  --brand-red-dark: #B30707;
  --brand-green: #97C21B;
  --brand-green-dark: #7BA015;

  --color-owner: #dc2626;
  --color-manager: #f59e0b;
  --color-viewer: #6b7280;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: var(--brand-red);
  --primary-hover: var(--brand-red-dark);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: var(--brand-green-dark);
  --sidebar-bg: #3f0202;
  --sidebar-bg-light: #5c0606;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

/* ---------- Layout ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, #2a0101 100%);
  color: #f1d9d9;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  padding: 0 20px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 10px;
}

.sidebar .brand img { width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0; }
.sidebar .brand span { color: var(--brand-green); }
.sidebar .brand .brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.sidebar .brand .tagline { font-size: 11px; font-weight: 600; font-style: italic; color: #e0b3b3; }

.sidebar nav { display: flex; flex-direction: column; gap: 3px; padding: 0 10px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  color: #f1d9d9;
  font-size: 15px;
  font-weight: 700;
}

.sidebar nav a:hover { background: rgba(255,255,255,0.1); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a.nav-logout-mobile { display: none; }
.sidebar nav select.nav-switcher-mobile { display: none; }

.sidebar .user-box {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.12);
}

.sidebar .user-box .email { font-size: 14px; color: #fff; font-weight: 700; word-break: break-all; }
.sidebar .user-box .role-badge { margin-top: 6px; }
.sidebar .user-box .logout-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 700;
  color: #ffb4b4;
  cursor: pointer;
}

.sidebar-credit {
  padding: 10px 20px 4px 20px;
  text-align: center;
}
.sidebar-credit a {
  font-size: 11px;
  font-weight: 600;
  color: #8a6b6b;
  text-decoration: none;
  letter-spacing: 0.02em;
}
.sidebar-credit a:hover { color: #e0b3b3; text-decoration: underline; }
.sidebar-credit a span { color: var(--brand-green); }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 36px;
}

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

.page-header h1 { margin: 0; font-size: 27px; font-weight: 800; letter-spacing: -0.01em; }
.page-header p { margin: 4px 0 0 0; color: var(--text-muted); font-size: 13px; font-weight: 500; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 { margin: 0 0 14px 0; font-size: 16px; font-weight: 800; }

/* Generic collapsible-card pattern (settings/admin/dashboard/users pages --
   see initCollapsibleCards() in nav.js). Reuses the same chevron+header
   idiom feedback.html hand-wrote first for its Share Link / Categories
   cards, generalized here so other pages don't each hand-roll a listener. */
.collapsible-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none; }
.collapsible-header h2 { margin: 0; }
.collapsible-chevron { font-size: 12px; color: var(--text-muted); transition: transform 0.15s; display: inline-block; }
.collapsible-body { margin-top: 14px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

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

.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
.stat-card .value { font-size: 32px; font-weight: 800; margin-top: 6px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s ease;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f0f1f3; }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Forms ---------- */

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: var(--font);
  background: #fff;
  color: var(--text);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > .form-group { flex: 1; min-width: 160px; }

.logo-preview {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: #fafafa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
  overflow: hidden;
}
.logo-preview img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Tables ---------- */

#users-table, #invitations-table, #businesses-table, #pending-approvals-table, #pending-payments-table, #recent-activity {
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 480px; }
th { text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 700; }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* ---------- Badges ---------- */

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #fff;
}
.role-badge.owner { background: var(--color-owner); }
.role-badge.manager { background: var(--color-manager); }
.role-badge.viewer { background: var(--color-viewer); }
.role-badge.super_admin { background: #1e3a5f; }

.status-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.status-badge.pending { background: #fef3c7; color: #92400e; }
.status-badge.expired { background: #fee2e2; color: #991b1b; }
.status-badge.active { background: #dcfce7; color: #166534; }
.status-badge.new { background: #dbeafe; color: #1e40af; }

.category-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #eef0f3;
  color: #475569;
}

/* ---------- Login page ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-red-dark) 0%, var(--brand-red) 55%, var(--brand-green-dark) 130%);
  padding: 20px;
}

.login-box {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  width: 100%;
  max-width: 420px;
  padding: 36px 34px;
}

.login-box .logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login-box .logo-row img { width: 48px; height: 48px; border-radius: 12px; flex-shrink: 0; }
.login-box .logo { font-size: 20px; font-weight: 800; line-height: 1.15; }
.login-box .logo span { color: var(--brand-green-dark); }
.login-box .subtitle { color: var(--text-muted); font-size: 13px; margin: 10px 0 26px 0; }

.demo-accounts {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}
.demo-accounts h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 0 0 10px 0; }
.demo-business-group { margin-bottom: 10px; }
.demo-business-group .biz-name { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 5px; }
.demo-account-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  margin: 0 6px 6px 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fafafa;
  font-size: 12px;
  cursor: pointer;
}
.demo-account-chip:hover { background: #eef2ff; border-color: var(--primary); }

.error-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.error-banner.show { display: block; }

.success-banner {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.success-banner.show { display: block; }

/* ---------- Misc ---------- */

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.muted { color: var(--text-muted); font-weight: 500; }
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-0 { margin-top: 0; }
.text-right { text-align: right; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); padding: 24px;
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.permission-group { margin-bottom: 14px; }
.permission-group .cat-name { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; }
.permission-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.permission-item .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.permission-item .dot.granted { background: var(--success); }
.permission-item .dot.denied { background: #d1d5db; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: visible;
    padding: 10px;
  }
  .sidebar .brand, .sidebar .user-box, .sidebar-credit { display: none; }
  .sidebar nav { flex-direction: row; }
  .sidebar nav a.nav-logout-mobile { display: flex; color: #ffb4b4; }
  .sidebar nav select.nav-switcher-mobile { display: inline-block; padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.25); background: var(--sidebar-bg-light); color: #fff; font-size: 13px; font-family: var(--font); font-weight: 700; max-width: 200px; }
  .main { padding: 20px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-row { flex-direction: column; }
  .modal { max-width: 92vw; padding: 18px; }
}
