:root {
  --blue: #1d4ed8;
  --blue-dark: #1e3a8a;
  --ink: #1a1f2b;
  --muted: #667085;
  --line: #e2e5eb;
  --bg: #f5f6f8;
  --card: #ffffff;
  --danger: #b42318;
  --radius: 8px;
}

* { box-sizing: border-box; }
/* Elements toggled via the HTML `hidden` attribute (login/app views, the
   modal) must actually disappear — without this, a later rule that sets
   `display: flex` on the same element (e.g. .modal-backdrop) silently wins
   over the browser's default [hidden]{display:none}, since both come from
   an author stylesheet at equal specificity. This forces hidden to win. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* ── Login ───────────────────────────────────────────────────── */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 1px 3px rgba(16,24,40,0.08);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--ink);
}
.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
}
.error-msg {
  background: #fef3f2;
  border: 1px solid #fecdca;
  color: var(--danger);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 14px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { background: #f2f3f5; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,0.05); }
.btn-icon { font-size: 20px; line-height: 1; padding: 2px 8px; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }

/* ── App shell ───────────────────────────────────────────────── */
.app-view { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Impersonation banner ("View as") ───────────────────────────
   Deliberately loud and always at the very top — a platform_admin
   viewing a tenant's data as them needs zero doubt about whose
   account they're looking through, and a one-click way back. */
.impersonation-banner {
  background: #fffaeb;
  border-bottom: 1px solid #fec84b;
  color: #93710a;
  font-size: 13.5px;
  padding: 9px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  text-align: center;
}
.impersonation-banner strong { color: #7a5a00; }
.impersonation-banner .btn {
  padding: 4px 12px;
  font-size: 12.5px;
  background: #93710a;
  border-color: #93710a;
  color: #fff;
}
.impersonation-banner .btn:hover { background: #7a5a00; }
.topbar {
  height: 56px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.brand { font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.whoami { font-size: 13px; color: var(--muted); }

.layout { flex: 1; display: flex; min-height: 0; }
.sidenav {
  width: 220px;
  border-right: 1px solid var(--line);
  background: var(--card);
  padding: 16px 10px;
  flex-shrink: 0;
}
.sidenav a {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 2px;
}
.sidenav a:hover { background: var(--bg); }
.sidenav a.active { background: #eaf0fe; color: var(--blue-dark); font-weight: 600; }
.sidenav .nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 14px 12px 6px;
}
.sidenav .nav-label:first-child { padding-top: 4px; }

.content { flex: 1; padding: 24px 28px; overflow-y: auto; }

/* ── Page header / filters ──────────────────────────────────── */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-head h1 { font-size: 19px; margin: 0; }
.page-filters { display: flex; align-items: center; gap: 8px; }
.page-filters select, .page-filters input {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13.5px;
}

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { background: #fafafb; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; }
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--muted);
}
.badge.active { background: #ecfdf3; color: #067647; }
.badge.inactive { background: #fef3f2; color: var(--danger); }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(16,24,40,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%; max-width: 460px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 30px rgba(16,24,40,0.25);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-form { padding: 18px 20px; overflow-y: auto; }
.modal-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}
.modal-form input, .modal-form select, .modal-form textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.modal-form textarea { min-height: 70px; resize: vertical; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding-top: 6px;
}
.form-error {
  background: #fef3f2;
  border: 1px solid #fecdca;
  color: var(--danger);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 12px;
}

.placeholder-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}
.placeholder-card h2 { color: var(--ink); font-size: 16px; margin: 0 0 6px; }
