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

:root {
  --sidebar-bg: #1e2a3b;
  --sidebar-hover: #2c3e55;
  --sidebar-active: #3b82f6;
  --sidebar-text: #94a3b8;
  --sidebar-text-bright: #e2e8f0;
  --sidebar-width: 230px;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-sm: 0.8125rem;

  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --green: #16a34a;
  --green-light: #dcfce7;
  --green-text: #15803d;
  --red: #dc2626;
  --red-light: #fee2e2;
  --red-text: #b91c1c;
  --orange: #ea580c;
  --orange-light: #ffedd5;
  --orange-text: #c2410c;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --purple-text: #6d28d9;
  --gray-light: #f1f5f9;
  --gray-text: #475569;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

html, body { height: 100%; font-size: 15px; }

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

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 0.875em; background: var(--gray-light); padding: 1px 5px; border-radius: 3px; }

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

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 1.25rem 1.25rem 1rem;
  color: var(--sidebar-text-bright);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-brand svg { flex-shrink: 0; opacity: 0.9; }

.nav-links {
  list-style: none;
  padding: 0.75rem 0.75rem;
  flex: 1;
}

.nav-links li { margin-bottom: 2px; }
.nav-links .nav-divider { height: 1px; background: rgba(255,255,255,0.07); margin: 8px 0; }

.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.nav-links a svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-links a:hover { background: var(--sidebar-hover); color: var(--sidebar-text-bright); }
.nav-links a.active { background: var(--sidebar-active); color: #fff; }

.sidebar-user {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.07);
}
.sidebar-username {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--sidebar-text);
  font-size: 0.8125rem;
  margin-bottom: 8px;
}
.sidebar-username svg { width: 14px; height: 14px; }

.btn-logout {
  width: 100%;
  background: rgba(255,255,255,0.07);
  border: none;
  color: var(--sidebar-text);
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-logout:hover { background: rgba(255,255,255,0.12); color: var(--sidebar-text-bright); }

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 2rem 2.5rem;
  min-width: 0;
  max-width: 1200px;
}

/* ── Flash Messages ────────────────────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}
.flash-success { background: var(--green-light); color: var(--green-text); border: 1px solid #bbf7d0; }
.flash-error { background: var(--red-light); color: var(--red-text); border: 1px solid #fecaca; }

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.page-header p { margin-top: 4px; }

.termination-header { border-bottom: 2px solid var(--red); padding-bottom: 1rem; margin-bottom: 1.5rem; }

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

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1;
}
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }

.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--gray-light); border-color: #cbd5e1; }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--gray-light); color: var(--text); }

.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: var(--red-text); border-color: var(--red-text); }

.btn-danger-outline { background: #fff; color: var(--red); border-color: #fca5a5; }
.btn-danger-outline:hover { background: var(--red-light); }

.btn-sm { padding: 5px 10px; font-size: 0.8125rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.card-form { padding: 1.5rem; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}
.card-header h2 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Stats Grid ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); border-color: #cbd5e1; text-decoration: none; }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-blue { background: #dbeafe; color: var(--blue); }
.stat-green { background: var(--green-light); color: var(--green); }
.stat-orange { background: var(--orange-light); color: var(--orange); }
.stat-purple { background: var(--purple-light); color: var(--purple); }

.stat-number { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8125rem; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ─────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 10px 1.5rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 10px 1.5rem;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }
.table-sm th, .table-sm td { padding: 7px 1.5rem; }

.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--text-sm); }
.nowrap { white-space: nowrap; }

.row-terminated td { opacity: 0.65; }

/* ── Detail Grid ────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 768px) { .detail-grid { grid-template-columns: 1fr; } }

.info-table { width: 100%; border-collapse: collapse; }
.info-table th {
  padding: 9px 1.25rem;
  text-align: left;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  width: 40%;
  vertical-align: top;
  border-bottom: 1px solid #f1f5f9;
}
.info-table td {
  padding: 9px 1.25rem;
  font-size: 0.875rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.info-table tr:last-child th, .info-table tr:last-child td { border-bottom: none; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.125rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 5px;
}
.required { color: var(--red); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
textarea { resize: vertical; }

.field-hint { font-size: 0.8125rem; color: var(--text-muted); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }

/* ── Filter Bar ─────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filter-bar input, .filter-bar select { width: auto; flex: 1; min-width: 140px; }

/* ── Grant Form ─────────────────────────────────────────────── */
.grant-form {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.grant-form select { flex: 1; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
}
.badge-green { background: var(--green-light); color: var(--green-text); }
.badge-red { background: var(--red-light); color: var(--red-text); }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: #f1f5f9; color: var(--gray-text); }
.badge-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.badge-lg { font-size: 0.8125rem; padding: 3px 10px; }
.badge-sm { font-size: 0.6875rem; padding: 1px 6px; }

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--gray-light);
  color: var(--gray-text);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.count-badge-red { background: var(--red-light); color: var(--red-text); }
.count-badge-green { background: var(--green-light); color: var(--green-text); }

/* ── Empty States ───────────────────────────────────────────── */
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9375rem;
}
.empty-state-sm {
  padding: 1rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-style: italic;
}

/* ── Check icon in termination view ────────────────────────── */
.check-icon { width: 18px; height: 18px; color: var(--green); vertical-align: middle; }

/* ── Termination view ───────────────────────────────────────── */
.checklist-complete {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--green-text);
  background: var(--green-light);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}
.checklist-complete svg { color: var(--green); margin-bottom: 0.75rem; }
.checklist-complete h2 { font-size: 1.25rem; margin-bottom: 0.5rem; }

.checklist-warning {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--orange-light);
  border: 1px solid #fed7aa;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--orange-text);
}

/* ── Secret reveal ──────────────────────────────────────────── */
.secret-value { font-family: monospace; letter-spacing: 0.1em; }
.toggle-secret { margin-left: 6px; }

/* ── Login page ─────────────────────────────────────────────── */
.login-body { background: var(--sidebar-bg); }
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.login-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 2rem;
  color: var(--sidebar-bg);
}
.login-brand h1 { font-size: 1.25rem; font-weight: 700; }
.login-brand svg { color: var(--blue); }
.login-form .form-group { margin-bottom: 1rem; }

/* ── 404 ────────────────────────────────────────────────────── */
.empty-page { text-align: center; padding: 4rem 2rem; }
.empty-page h1 { font-size: 4rem; color: var(--text-muted); }
.empty-page p { margin: 1rem 0 2rem; color: var(--text-muted); }

/* ── Nav section labels ─────────────────────────────────────── */
.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #4a5f7a;
  padding: 14px 10px 4px;
}

/* ── Key level badges ───────────────────────────────────────── */
.badge-level-gmk        { background: #1e3a5f; color: #93c5fd; }
.badge-level-mk         { background: #1e4d3a; color: #6ee7b7; }
.badge-level-sub_master { background: #4a2c6e; color: #c4b5fd; }
.badge-level-change     { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

/* ── Access type badges ─────────────────────────────────────── */
.badge-access-keyed { background: #dbeafe; color: #1e40af; }
.badge-access-fob   { background: #fef3c7; color: #92400e; }
.badge-access-both  { background: #d1fae5; color: #065f46; }

/* ── Key tree / hierarchy map ───────────────────────────────── */
.key-tree-wrapper {
  padding: 1.25rem 1.5rem 1.5rem;
  overflow-x: auto;
}

.key-tree-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tree-root { padding-left: 0; }
.tree-children { padding-left: 2rem; margin-top: 4px; }

.key-tree-node {
  position: relative;
  padding: 3px 0;
}

/* vertical connector line from parent */
.tree-children > .key-tree-node::before {
  content: '';
  position: absolute;
  left: -1.25rem;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}
.tree-children > .key-tree-node:last-child::before { bottom: 50%; }

/* horizontal connector line to card */
.tree-children > .key-tree-node > .key-tree-card::before {
  content: '';
  position: absolute;
  left: -1.25rem;
  top: 50%;
  width: 1rem;
  height: 1px;
  background: var(--border);
}

.key-tree-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  margin: 3px 0;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.key-tree-card:hover { border-color: #94a3b8; }

.key-tree-number {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text);
}

.tree-bitting {
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--gray-light);
  padding: 1px 6px;
  border-radius: 3px;
}

.tree-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.tree-door-count {
  font-size: 0.75rem;
  background: #dbeafe;
  color: #1e40af;
  padding: 1px 7px;
  border-radius: 12px;
  font-weight: 600;
}

.tree-ring-count {
  font-size: 0.75rem;
  background: var(--orange-light);
  color: var(--orange-text);
  padding: 1px 7px;
  border-radius: 12px;
  font-weight: 600;
}

.tree-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ── Dashboard extended stats ───────────────────────────────── */
.stat-teal   { background: #ccfbf1; color: #0f766e; }
.stat-indigo { background: #e0e7ff; color: #4338ca; }

/* ── Reports grid ───────────────────────────────────────────── */
.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
}
.report-card:hover { box-shadow: var(--shadow-md); border-color: #94a3b8; transform: translateY(-1px); text-decoration: none; }

.report-icon {
  width: 44px;
  height: 44px;
  background: #eff6ff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--blue);
}
.report-icon svg { width: 22px; height: 22px; }

.report-body h3 { font-size: 0.9375rem; font-weight: 600; margin-bottom: 4px; }
.report-body p  { font-size: 0.8125rem; color: var(--text-muted); line-height: 1.5; margin: 0; }

.report-count {
  padding: 0.5rem 1.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

/* ── Report section cards (keyring inventory, staff access, etc) */
.report-section { margin-bottom: 1.25rem; }

.report-section-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0;
  border-top: 1px solid var(--border);
}

.report-col {
  padding: 1rem 1.5rem;
  border-right: 1px solid var(--border);
}
.report-col:last-child { border-right: none; }

.report-col-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.report-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.875rem;
}

.inline-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8125rem;
}

/* ── Grant form with 3 columns (FOB profile + serial + button) ─ */
.grant-form-3col { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grant-form-3col select { flex: 2; min-width: 180px; }
.grant-form-3col input  { flex: 1; min-width: 120px; }

/* ── Keytrak index — extra columns ──────────────────────────── */
.keytrak-counts { display: flex; gap: 6px; }

/* ── Dashboard extra stat colors ────────────────────────────── */
.stat-slate  { background: #f1f5f9; color: #475569; }
.stat-cyan   { background: #cffafe; color: #0e7490; }
.stat-rose   { background: #ffe4e6; color: #be123c; }

/* ══════════════════════════════════════════════════════════════
   FLOOR PLANS
   ══════════════════════════════════════════════════════════════ */

/* ── Section heading ──────────────────────────────────────────── */
.section-heading {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .75rem;
}

/* ── Index grid ───────────────────────────────────────────────── */
.fp-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.fp-index-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.fp-index-card:hover { box-shadow: var(--shadow-md); }

.fp-thumb-link {
  display: block;
  position: relative;
  background: #f8fafc;
  aspect-ratio: 4/3;
  overflow: hidden;
}
.fp-thumb {
  width: 100%; height: 100%;
  object-fit: contain;
  transition: filter .2s;
}
.fp-thumb-overlay {
  position: absolute; inset: 0;
  background: rgba(30,42,59,.55);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  color: #fff; font-size: .8125rem; font-weight: 600;
  opacity: 0; transition: opacity .2s;
}
.fp-thumb-link:hover .fp-thumb-overlay { opacity: 1; }
.fp-thumb-link:hover .fp-thumb { filter: brightness(.8); }

.fp-index-info {
  padding: .75rem 1rem;
}
.fp-index-title { font-weight: 600; margin-bottom: .25rem; }
.fp-index-title a { color: var(--text); text-decoration: none; }
.fp-index-title a:hover { color: var(--blue); }
.fp-index-meta { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; font-size: .8125rem; }
.fp-index-actions { display: flex; gap: .5rem; }

/* ── Viewer ───────────────────────────────────────────────────── */
.fp-viewer-wrap { }

.fp-legend {
  display: flex; align-items: center; gap: 1rem;
  font-size: .8125rem; color: var(--text-muted);
  margin-bottom: .75rem;
  flex-wrap: wrap;
}
.fp-legend-item { display: flex; align-items: center; gap: 5px; }
.fp-legend-tip  { margin-left: auto; font-style: italic; }

.fp-pin-dot {
  width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex-shrink: 0;
}
.fp-dot-keyed { background: #3b82f6; }
.fp-dot-fob   { background: #f59e0b; }
.fp-dot-both  { background: #16a34a; }

/* ── Canvas (shared by viewer + editor) ───────────────────────── */
.fp-canvas {
  position: relative;
  display: inline-block;
  max-width: 100%;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  line-height: 0; /* prevent gap under image */
}
.fp-canvas-edit { cursor: default; }
.fp-canvas-edit.fp-placing { cursor: crosshair; }

.fp-img {
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none; /* clicks fall through to .fp-pin or canvas */
}

/* ── Pins ─────────────────────────────────────────────────────── */
.fp-pin {
  position: absolute;
  transform: translate(-50%, -100%);
  cursor: pointer;
  z-index: 10;
  background: none; border: none; padding: 0;
  line-height: 0;
  /* subtle entrance animation */
  animation: pinPop .18s ease-out;
}
@keyframes pinPop {
  from { transform: translate(-50%, calc(-100% - 8px)) scale(.7); opacity: 0; }
  to   { transform: translate(-50%, -100%) scale(1);               opacity: 1; }
}

.fp-pin-marker {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 38px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
  transition: transform .12s, box-shadow .12s;
}
.fp-pin:hover .fp-pin-marker,
.fp-pin-active .fp-pin-marker {
  transform: rotate(-45deg) scale(1.2);
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.fp-pin-marker svg {
  transform: rotate(45deg);
  width: 14px; height: 14px;
  stroke: #fff;
}

.fp-pin-keyed { background: #3b82f6; }
.fp-pin-fob   { background: #f59e0b; }
.fp-pin-both  { background: #16a34a; }

/* Label shown on editor pins */
.fp-pin-label-edit {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: .6875rem; font-weight: 600;
  color: #fff;
  background: rgba(30,42,59,.75);
  padding: 1px 5px;
  border-radius: 3px;
  pointer-events: none;
  line-height: 1.4;
}

.fp-pin-dragging { opacity: .7; z-index: 50; }

/* ── Viewer popover ───────────────────────────────────────────── */
.fp-popover {
  position: absolute;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem 1rem;
  min-width: 210px; max-width: 280px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
  line-height: 1.4;
}
/* caret pointing down */
.fp-popover::after {
  content: '';
  position: absolute;
  bottom: -7px; left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 13px; height: 13px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.fp-popover-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none;
  font-size: 1.1rem; line-height: 1;
  color: var(--text-muted); cursor: pointer;
  padding: 0 2px;
}
.fp-popover-close:hover { color: var(--text); }
.fp-popover-badge  { margin-bottom: .3rem; }
.fp-popover-name   { font-weight: 700; font-size: .9375rem; margin-bottom: .25rem; padding-right: 18px; }
.fp-popover-meta   { font-size: .8125rem; color: var(--text-muted); margin-bottom: .3rem; }
.fp-popover-notes  { font-size: .8125rem; color: var(--text-muted); font-style: italic; margin-bottom: .6rem; }
.fp-popover-link   { display: inline-block; font-size: .8125rem; }

/* ── Editor layout ────────────────────────────────────────────── */
.fp-editor-layout {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}
.fp-editor-main {
  flex: 1 1 0;
  min-width: 0;
}
.fp-editor-panel {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.fp-editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: .55rem .85rem;
  font-size: .8125rem;
  margin-bottom: -1px; /* merge with canvas border */
  z-index: 1;
  position: relative;
}
.fp-mode-label { color: var(--text-muted); }
.fp-mode-label strong { color: var(--text); }
.fp-canvas-hint {
  font-size: .75rem; color: var(--text-muted); margin-top: .4rem;
  text-align: center;
}

.fp-save-indicator {
  font-size: .75rem; font-weight: 600;
  min-width: 70px; text-align: right;
  transition: opacity .3s;
}
.fp-save-ok  { color: var(--green); }
.fp-save-err { color: var(--red); }

/* ── Editor panel internals ───────────────────────────────────── */
.fp-panel-section { padding: .85rem .9rem; }
.fp-panel-divider { height: 1px; background: var(--border); }
.fp-panel-heading {
  font-size: .8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  margin-bottom: .6rem;
  display: flex; align-items: center; gap: .4rem;
}
.fp-panel-empty { font-size: .8125rem; color: var(--text-muted); }
.fp-door-search {
  width: 100%; margin-bottom: .5rem;
  font-size: .8125rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .3rem .55rem;
  background: var(--bg); color: var(--text);
}
.fp-panel-door {
  display: flex; align-items: center; gap: .45rem;
  padding: .35rem .4rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
}
.fp-panel-door-avail {
  cursor: pointer;
  transition: background .1s;
}
.fp-panel-door-avail:hover    { background: var(--gray-light); }
.fp-panel-door-selected       { background: #dbeafe; }
.fp-panel-door-placed { background: transparent; }

.fp-panel-door-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-remove-btn {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0 2px;
  flex-shrink: 0;
}
.fp-remove-btn:hover { color: var(--red); }

/* ── Remove tooltip ───────────────────────────────────────────── */
.fp-remove-tooltip {
  position: absolute;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem .9rem;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
  font-size: .8125rem; min-width: 180px;
  pointer-events: auto;
}
.fp-remove-tooltip-name { font-weight: 600; }

/* ══════════════════════════════════════════════════════════════
   IMPORT / EXPORT PAGES
   ══════════════════════════════════════════════════════════════ */

.import-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.import-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .55rem;
}

.import-card h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.card-sub {
  font-size: .8125rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.col-hint {
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--gray-light);
  border-radius: var(--radius-sm);
  padding: .35rem .6rem;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  line-height: 1.6;
  word-break: break-word;
}

.template-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .8125rem;
  color: var(--text-muted);
}

.import-form { display: flex; flex-direction: column; gap: .5rem; margin-top: auto; }

.file-row {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.file-row input[type="file"] {
  flex: 1;
  font-size: .8125rem;
}

.result-box {
  display: none;
  font-size: .8125rem;
  border-radius: var(--radius-sm);
  padding: .55rem .75rem;
  line-height: 1.5;
}

.result-box.show { display: block; }

.result-box.ok {
  background: var(--green-light);
  color: var(--green-text);
  border: 1px solid #bbf7d0;
}

.result-box.err {
  background: var(--red-light);
  color: var(--red-text);
  border: 1px solid #fecaca;
}

.result-box .summary { font-weight: 700; margin-bottom: .25rem; }

.result-box ul {
  margin: .25rem 0 0 1rem;
  padding: 0;
}

.export-count {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .8125rem;
  color: var(--text-muted);
}

/* ══════════════════════════════════════════════════════════════
   PRINT STYLES
   ══════════════════════════════════════════════════════════════ */

/* Hidden on screen — shown only when printing */
.print-header { display: none; }

@media print {
  /* Hide navigation and interactive chrome */
  .sidebar,
  .no-print,
  .flash,
  .filter-bar,
  .page-header .btn-group,
  .page-header .btn { display: none !important; }

  /* Collapse app layout — full width content */
  .app-layout { display: block; }
  .main-content { padding: 0; margin: 0; }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  /* Show the print header */
  .print-header {
    display: flex !important;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 2px solid #1e2a3b;
    padding-bottom: .4rem;
    margin-bottom: 1.2rem;
  }

  .print-header-brand {
    font-weight: 800;
    font-size: 13pt;
    color: #1e2a3b;
    margin-right: .75rem;
  }

  .print-header-title {
    font-size: 11pt;
    color: #444;
  }

  .print-header-date {
    font-size: 9pt;
    color: #666;
  }

  /* Page setup */
  @page { margin: 1.5cm 1.8cm; }

  /* Keep report cards together */
  .report-section { page-break-inside: avoid; }
  .card { page-break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }

  /* Report table borders for readability */
  .table th, .table td { border-color: #ccc; }

  /* Links don't need to show URLs */
  a::after { content: none !important; }

  /* Trees */
  .key-tree-wrapper { overflow: visible; }

  /* Physical key pages */
  .pk-status-bar, .tx-tabs, .action-tiles { display: none; }
  .tx-panel.hidden { display: block !important; }
  .agreement-doc { box-shadow: none; border: 1px solid #ccc; }
}

/* ══════════════════════════════════════════════════════════════
   PHYSICAL KEY COPY TRACKING
   ══════════════════════════════════════════════════════════════ */

/* ── Status badges ────────────────────────────────────────────── */
.badge-pk-active    { background: #dcfce7; color: #15803d; }
.badge-pk-lost      { background: #fee2e2; color: #b91c1c; }
.badge-pk-damaged   { background: #ffedd5; color: #c2410c; }
.badge-pk-destroyed { background: #f1f5f9; color: #475569; }

/* ── Transaction type badges ──────────────────────────────────── */
.badge-tx-issued-from-locksmith { background: #dbeafe; color: #1d4ed8; }
.badge-tx-issued-to-person      { background: #d1fae5; color: #065f46; }
.badge-tx-returned              { background: #e0e7ff; color: #3730a3; }
.badge-tx-lost                  { background: #fee2e2; color: #b91c1c; }
.badge-tx-damaged               { background: #ffedd5; color: #c2410c; }
.badge-tx-destroyed             { background: #f1f5f9; color: #475569; }
.badge-tx-replaced              { background: #fef9c3; color: #854d0e; }

/* ── Row states ───────────────────────────────────────────────── */
.row-overdue   { background: #fff5f5; }
.row-expiring  { background: #fffbeb; }
.row-checked-out { background: #fffbeb; }
.text-danger   { color: var(--red); }
.text-warning  { color: var(--orange); }
.ml-1          { margin-left: .25rem; }
.font-weight-bold { font-weight: 700; }

/* ── Status bar (physical keys list) ─────────────────────────── */
.pk-status-bar {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.pk-stat {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .35rem .75rem;
  border-radius: 999px;
  font-size: .8125rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: border-color .15s;
}
.pk-stat:hover { border-color: #94a3b8; text-decoration: none; }
.pk-stat-active { border-color: var(--blue); color: var(--blue); background: #eff6ff; }

/* ── Custody timeline ─────────────────────────────────────────── */
.custody-timeline {
  padding: .75rem 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.custody-event {
  display: flex;
  gap: .85rem;
  position: relative;
  padding-bottom: 1.1rem;
}

.custody-event:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 20px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.custody-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 1px;
  border: 2px solid var(--border);
  background: var(--surface);
}

.custody-dot-issued_from_locksmith { background: #dbeafe; border-color: #93c5fd; }
.custody-dot-issued_to_person      { background: #d1fae5; border-color: #6ee7b7; }
.custody-dot-returned              { background: #e0e7ff; border-color: #a5b4fc; }
.custody-dot-lost                  { background: #fee2e2; border-color: #fca5a5; }
.custody-dot-damaged               { background: #ffedd5; border-color: #fdba74; }
.custody-dot-destroyed             { background: #f1f5f9; border-color: #cbd5e1; }
.custody-dot-replaced              { background: #fef9c3; border-color: #fde047; }

.custody-body { flex: 1; min-width: 0; }
.custody-type { font-size: .875rem; font-weight: 600; text-transform: capitalize; }
.custody-people { font-size: .8125rem; margin-top: .1rem; }
.custody-meta   { margin-top: .15rem; }
.custody-notes  { margin-top: .15rem; font-style: italic; }

/* ── Action tiles (report event section) ─────────────────────── */
.action-tiles { display: flex; flex-direction: column; gap: .75rem; }

.action-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.action-tile > summary {
  padding: .65rem 1rem;
  font-weight: 600;
  font-size: .875rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--bg);
  user-select: none;
}

.action-tile > summary::-webkit-details-marker { display: none; }
.action-tile > summary::before { content: '▶'; font-size: .65rem; color: var(--text-muted); transition: transform .15s; }
.action-tile[open] > summary::before { transform: rotate(90deg); }
.action-tile-warning > summary { color: var(--orange); }
.action-tile-danger > summary  { color: var(--red); }
.tile-form { padding: 1rem; border-top: 1px solid var(--border); }

/* ── Inline action form (return form) ────────────────────────── */
.inline-action-form {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
  padding: .85rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.inline-action-form input { font-size: .8125rem; }

/* ── Card section ─────────────────────────────────────────────── */
.card-section {
  padding: 1rem 1.5rem;
}

/* ── Form stacked (inside card section) ──────────────────────── */
.form-stacked .form-row { margin-bottom: .5rem; }

/* ── Transaction tabs ─────────────────────────────────────────── */
.tx-tabs {
  display: flex;
  gap: .35rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.tx-tab {
  padding: .45rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: .8125rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
}
.tx-tab:hover { border-color: #94a3b8; color: var(--text); }
.tx-tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.tx-panel { display: block; }
.tx-panel.hidden { display: none; }

/* ── Stats bar (reports index) ────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .35rem .85rem;
  font-size: .8125rem;
  color: var(--text-muted);
}
.stat-pill-orange { background: #fff7ed; border-color: #fed7aa; color: var(--orange-text); }
.stat-pill-red    { background: #fff1f2; border-color: #fecdd3; color: var(--red-text); }

/* ── Filter group (label + input inline) ─────────────────────── */
.filter-group {
  display: flex;
  align-items: center;
  gap: .4rem;
}
.filter-label {
  font-size: .8125rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ════════════════════════════════════════════════════════════════
   KEY AGREEMENT PRINTABLE DOCUMENT
   ════════════════════════════════════════════════════════════════ */

.agreement-doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: 860px;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  font-size: .9375rem;
}

.agreement-header {
  background: #1e2a3b;
  color: #fff;
  padding: 1.5rem 2rem;
}
.agreement-brand {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -.02em;
  margin-bottom: .25rem;
}
.agreement-title {
  font-size: 1.25rem;
  font-weight: 700;
}
.agreement-meta {
  margin-top: .3rem;
  font-size: .8125rem;
  color: #94a3b8;
}

.agreement-section {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
}
.agreement-section:last-child { border-bottom: none; }

.agreement-section-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: .75rem;
}

.agreement-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.agreement-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  padding: .3rem .75rem .3rem 0;
  width: 130px;
  vertical-align: top;
}
.agreement-table td {
  padding: .3rem .75rem .3rem 0;
  vertical-align: top;
}

.agreement-ack-text {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  font-size: .875rem;
  line-height: 1.7;
  color: var(--text);
}

.agreement-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.agreement-sig-block { padding-top: .5rem; }
.agreement-sig-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 2rem;
}
.agreement-sig-line {
  border-bottom: 2px solid var(--text);
  margin-bottom: .4rem;
}
.agreement-sig-name {
  font-size: .875rem;
  font-weight: 600;
}
.agreement-sig-date {
  font-size: .8125rem;
  color: var(--text-muted);
  margin-top: .75rem;
}

.agreement-footer {
  text-align: center;
  padding: .85rem 2rem;
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--bg);
  border-top: 1px solid var(--border);
}

@media print {
  .agreement-doc {
    box-shadow: none;
    border: none;
    max-width: 100%;
  }
  .agreement-header { background: #1e2a3b !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Batch add ────────────────────────────────────────────────────── */
.batch-mode-tabs {
  display: flex;
  gap: .5rem;
  padding: 1rem 1.25rem .75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}
.batch-mode-tab {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.batch-mode-tab:hover { background: var(--bg); color: var(--text); }
.batch-mode-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.batch-panel { padding: 0 1.25rem 1rem; }
.batch-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .85rem 1rem;
  margin-top: .75rem;
}
.batch-preview-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.batch-preview-stamps {
  font-family: monospace;
  font-size: .8125rem;
  color: var(--text);
  line-height: 1.6;
  word-break: break-all;
}
.batch-preview-warn {
  margin-top: .5rem;
  font-size: .8125rem;
  color: #b91c1c;
  font-weight: 600;
}
