:root {
  --paper: #F5F2EC;
  --paper-2: #ECE8DF;
  --paper-3: #E0DBD0;
  --ink: #14130F;
  --ink-2: #2A2823;
  --ink-3: #4B4842;
  --ink-4: #767169;
  --forest: #0F4F3F;
  --forest-soft: #DDE9E3;
  --danger: #B81B1B;
  --sans: 'Inter Tight', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--paper-3);
  position: sticky; top: 0; background: var(--paper); z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; }
.wordmark { font-weight: 700; font-size: 18px; letter-spacing: -0.4px; }

main { max-width: 1100px; margin: 0 auto; padding: 32px 28px 96px; }

.eyebrow {
  font-family: var(--mono); font-size: 11px; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--ink-4); display: inline-block;
  margin-bottom: 8px;
}
h1 { font-size: 38px; line-height: 1.05; letter-spacing: -1px; margin: 0 0 12px; font-weight: 700; }
h2 { font-size: 22px; letter-spacing: -0.4px; margin: 36px 0 10px; font-weight: 700; }
.lede { color: var(--ink-3); margin: 0 0 18px; max-width: 600px; }

.auth { max-width: 440px; margin: 60px auto; padding: 32px; border: 1px solid var(--ink); border-radius: 12px; background: white; }
#auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
#auth-form input {
  padding: 12px 14px; border: 1px solid var(--paper-3); border-radius: 8px;
  font-family: var(--sans); font-size: 15px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 18px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 500; font-size: 14px; cursor: pointer;
  font-family: var(--sans);
  transition: transform 100ms ease, background 100ms ease;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { transform: translateY(-1px); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn.ghost:hover { background: var(--paper-2); }

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

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-top: 16px;
}
.stat {
  background: white; border: 1px solid var(--paper-3); border-radius: 10px;
  padding: 16px;
}
.stat-label {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--ink-4); display: block;
}
.stat-value {
  display: block; font-size: 32px; font-weight: 700; letter-spacing: -0.6px;
  margin-top: 4px;
}

.map {
  height: 360px; background: var(--paper-2);
  border: 1px solid var(--paper-3); border-radius: 10px;
  position: relative; overflow: hidden;
  /* Seal leaflet's internal z-indexes (panes 200–700, controls 1000) into
     this element's stacking context so they can't compete with the modal
     at the page level. Without this, `.map` doesn't form a stacking context
     (position:relative alone doesn't) and leaflet's controls bleed up. */
  isolation: isolate;
  z-index: 0;
}
/* Leaflet renders the map content inside .map. Override its default
   attribution font + tile background so it harmonises with the rest of
   the dashboard. */
.map .leaflet-container {
  height: 100%; width: 100%;
  background: var(--paper-2);
  font-family: var(--mono); font-size: 10px;
}
.map .leaflet-control-attribution {
  background: rgba(245,242,236,0.85);
  font-size: 9px;
  letter-spacing: 0.4px;
}

table.users {
  width: 100%; border-collapse: collapse; margin-top: 16px;
  background: white; border: 1px solid var(--paper-3); border-radius: 10px; overflow: hidden;
}
table.users th, table.users td {
  padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--paper-3);
  font-size: 13px;
}
table.users th {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--ink-4); background: var(--paper-2);
}
table.users tr:last-child td { border-bottom: none; }
.tag { font-family: var(--mono); font-size: 10px; letter-spacing: 0.6px; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; }
.tag.active { background: var(--forest-soft); color: var(--forest); }
.tag.trial { background: var(--paper-2); color: var(--ink-3); }
.tag.expired { background: #f3dada; color: var(--danger); }

/* Role segmented control — three pill buttons sharing a rounded shell. */
.role-seg {
  display: inline-flex;
  border: 1px solid var(--paper-3);
  border-radius: 999px;
  background: var(--paper-2);
  padding: 2px;
  gap: 0;
}
.role-btn {
  background: transparent;
  border: 0;
  padding: 4px 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--ink-3);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.role-btn:hover:not(.on):not(:disabled) { color: var(--ink); }
.role-btn.on {
  background: var(--ink);
  color: var(--paper);
}
.role-btn[data-role="admin"].on   { background: var(--forest); color: var(--paper); }
.role-btn[data-role="blocked"].on { background: var(--danger); color: white; }
.role-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.row-actions { text-align: right; }
.row-actions .muted { color: var(--ink-4); font-family: var(--mono); font-size: 10px; letter-spacing: 0.6px; text-transform: uppercase; }
.btn-link {
  background: transparent; border: 0; padding: 0; cursor: pointer;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.6px;
  text-transform: uppercase; color: var(--ink-3);
}
.btn-link:hover { color: var(--ink); }
.btn-link.danger { color: var(--danger); }
.btn-link.danger:hover { text-decoration: underline; }
.btn-link:disabled { opacity: 0.5; cursor: progress; }

table.users tbody tr { cursor: pointer; }
table.users tbody tr:hover { background: var(--paper-2); }

/* User-detail modal */
.user-detail {
  /* Leaflet's internal panes/controls run up to z-index 1000 (zoom buttons,
     attribution). `.map` doesn't form its own stacking context — it sets
     position:relative but no z-index — so those leaflet layers compete at
     the page level. Park the modal well above them. */
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
/* Native [hidden] is normally `display: none`, but our explicit `display:
   flex` above wins — so the modal renders even when JS sets hidden=true.
   Force the override back. */
.user-detail[hidden] { display: none; }
.user-detail-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 19, 15, 0.55);
}
.user-detail-card {
  position: relative;
  width: 100%; max-width: 720px; max-height: 88vh;
  background: white;
  border: 1px solid var(--paper-3); border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
}
.user-detail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--paper-3);
}
.user-detail-head h2 { margin: 0; font-size: 16px; }
.user-detail-body {
  padding: 20px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 20px;
}
.detail-eyebrow {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--ink-4); margin-bottom: 8px;
}
.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.detail-cell {
  background: var(--paper-2); border: 1px solid var(--paper-3); border-radius: 8px;
  padding: 10px 12px; min-width: 0;
}
.detail-cell .label {
  font-family: var(--mono); font-size: 9px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--ink-4);
}
.detail-cell .value {
  margin-top: 4px; font-size: 13px; word-break: break-word;
}
.session-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
  border: 1px solid var(--paper-3); border-radius: 8px; overflow: hidden;
}
.session-table th, .session-table td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--paper-3);
}
.session-table th {
  font-family: var(--mono); font-size: 10px; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--ink-4); background: var(--paper-2);
}
.session-table tr:last-child td { border-bottom: none; }
.kind-pill {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.6px;
  padding: 2px 8px; border-radius: 999px; text-transform: uppercase;
}
.kind-pill.register { background: #dfe8e3; color: var(--forest); }
.kind-pill.login    { background: #e6e1cf; color: var(--ink); }
.kind-pill.active   { background: var(--paper-2); color: var(--ink-4); }
