:root {
  --bg: #0f1115;
  --surface: #181b22;
  --border: #262a33;
  --text: #e6e8eb;
  --muted: #8c93a3;
  --accent: #5b8def;
  --error: #e5484d;
  --success: #30a46c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.admin-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.admin-nav .brand { font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.admin-nav .links { display: flex; gap: 1rem; align-items: center; }
.admin-nav a { color: var(--text); text-decoration: none; }
.admin-nav a:hover { color: var(--accent); }
.admin-nav .identity { color: var(--muted); font-size: 0.9rem; }
.nav-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: var(--error);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}

.banner {
  padding: 0.85rem 1rem;
  border-radius: 6px;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}
.banner a { color: inherit; font-weight: 600; margin-left: 0.35rem; }
.banner-danger {
  background: rgba(229, 72, 77, 0.12);
  color: var(--error);
  border: 1px solid rgba(229, 72, 77, 0.5);
}

.payload-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.85rem 1rem;
  font-size: 0.8rem;
  color: var(--text);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.error-block {
  background: rgba(229, 72, 77, 0.08);
  border: 1px solid rgba(229, 72, 77, 0.4);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  color: var(--error);
  font-size: 0.85rem;
  white-space: pre-wrap;
}
.inline-form { display: inline; margin: 0; }
.linklike {
  background: none; border: none; color: var(--text);
  cursor: pointer; padding: 0; font: inherit;
}
.linklike:hover { color: var(--accent); }

.auth-card {
  max-width: 360px;
  margin: 4rem auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
}
.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.auth-card .muted { color: var(--muted); margin: 0 0 1.5rem; font-size: 0.9rem; }
.auth-card form { display: flex; flex-direction: column; gap: 1rem; }
.auth-card label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.85rem; color: var(--muted);
}
.auth-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
}
.auth-card input:focus { border-color: var(--accent); outline: none; }
.auth-card button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.7rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  margin-top: 0.5rem;
}
.auth-card button:hover { filter: brightness(1.1); }

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}
.flash-error { background: rgba(229, 72, 77, 0.15); color: var(--error); border: 1px solid var(--error); }
.flash-success { background: rgba(48, 164, 108, 0.15); color: var(--success); border: 1px solid var(--success); }

.muted { color: var(--muted); }
h1 { margin-top: 0; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.stat-group { margin-bottom: 2rem; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
}
.stat-card-warn {
  border-color: rgba(229, 72, 77, 0.6);
}
/* Linked stat cards render as <a> so middle-click / right-click-in-new-tab
   work. Reset link styling, add a pointer and a subtle hover lift so the
   affordance is obvious without the card looking like a button. */
a.stat-card-link {
  color: inherit;
  text-decoration: none;
  display: block;
  transition: transform 120ms ease-out, border-color 120ms ease-out;
}
a.stat-card-link:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
a.stat-card-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* "Active filters" chips shown when a drill-down filter is in effect
   that isn't selectable from the dropdown UI (created_within /
   last_seen_within). The chip's href clears just that one axis. */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  background: rgba(91, 141, 239, 0.12);
  border: 1px solid rgba(91, 141, 239, 0.4);
  color: var(--accent);
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.78rem;
}
.filter-chip:hover {
  background: rgba(91, 141, 239, 0.2);
  border-color: var(--accent);
}
.filter-chip-x {
  font-weight: 600;
  font-size: 1rem;
  line-height: 0.8;
}

/* Dev-only simulation card. Visually differentiated with a dashed
   border so operators don't mistake it for a production action. */
.card-dev {
  border-style: dashed;
  border-color: rgba(229, 168, 72, 0.5);
  background: rgba(229, 168, 72, 0.04);
}
.card-dev h2 .badge {
  font-size: 0.65rem;
  vertical-align: middle;
  margin-left: 0.4rem;
}
.dev-sim-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.dev-sim-grid form { margin: 0; }
.stat-card-highlight {
  border-color: rgba(99, 179, 237, 0.6);
  background: rgba(99, 179, 237, 0.06);
}
.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.stat-value {
  font-size: 1.75rem;
  font-weight: 600;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.filter-bar input,
.filter-bar select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.filter-bar input { flex: 1 1 240px; min-width: 0; }
.filter-bar button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.users-table, .history-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.users-table th, .users-table td,
.history-table th, .history-table td {
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.users-table th, .history-table th {
  background: var(--bg);
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}
.users-table tbody tr:hover { background: rgba(91, 141, 239, 0.05); }
.users-table a { color: var(--accent); text-decoration: none; }
.users-table a.btn { color: white; } /* buttons override the default link color */
.users-table a:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  background: var(--border);
  color: var(--text);
}
.badge-plan { background: rgba(91, 141, 239, 0.2); color: var(--accent); }
.badge-ok { background: rgba(48, 164, 108, 0.2); color: var(--success); }
.badge-warn { background: rgba(229, 168, 72, 0.2); color: #e5a848; }
.badge-danger { background: rgba(229, 72, 77, 0.2); color: var(--error); }

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.25rem;
}
.pagination a, .pagination span { font-size: 0.9rem; }
.pagination a { color: var(--accent); text-decoration: none; }
.pagination a:hover { text-decoration: underline; }

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.back-link:hover { color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.kv {
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr;
  gap: 0.4rem 1rem;
  margin: 0;
  font-size: 0.9rem;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv code { background: var(--bg); padding: 0.05rem 0.3rem; border-radius: 4px; font-size: 0.85rem; }

.card-actions { border-color: rgba(229, 168, 72, 0.4); }
.action-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.75rem 0 0;
}
.action-form input[type="text"] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn-success { background: var(--success); }
.btn-warn    { background: #c98a2e; }
.btn-danger  { background: var(--error); }
.btn-primary { background: var(--accent); }
.btn-cancel {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-cancel:hover { background: var(--bg); filter: none; }

/* Confirmation modal. Single instance in base.gohtml; confirm.js wires
   it up against any <form data-confirm="..."> on the page. */
.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modal-fade-in 120ms ease-out;
}
@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem 1.75rem 1.25rem;
  min-width: 320px;
  max-width: 480px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  animation: modal-pop 140ms ease-out;
}
@keyframes modal-pop {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.modal-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}
.modal-message {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}
body.modal-open { overflow: hidden; }

/* ---------------------------------------------------------------
   Patterns for the system-events page (and any future drill-in
   admin page that wants collapsible filters + a detail modal).
   --------------------------------------------------------------- */

/* Toolbar row above the filter form. `justify-content: space-between`
   lets the right-side controls hug the right edge while keeping an
   empty spacer slot on the left for future affordances (e.g. a live-
   refresh toggle). */
.events-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 0.75rem;
}
.controls-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Set-filters toggle button. Caret rotates when expanded; count badge
   appears when at least one filter is active. */
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
.filter-toggle:hover { border-color: var(--accent); }
.filter-toggle[aria-expanded="true"] .filter-toggle-caret {
  transform: rotate(180deg);
}
.filter-toggle-caret {
  display: inline-block;
  font-size: 0.75rem;
  transition: transform 120ms ease-out;
}
.filter-count {
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 9999px;
  padding: 0.05rem 0.45rem;
  min-width: 1.1rem;
  text-align: center;
}

/* Marker class on the filter <form>. The form is shown/hidden via the
   plain `hidden` HTML attribute (matching .modal-backdrop's pattern);
   the class itself only exists so future tweaks have a hook. */
.filter-collapse[hidden] { display: none; }

/* Row hover affordance: rows are clickable, so hint that with a
   pointer cursor + a slightly brighter background on hover. */
.history-table tbody tr.events-row { cursor: pointer; }
.history-table tbody tr.events-row:hover {
  background: rgba(91, 141, 239, 0.05);
}

/* Wide modal variant — the existing .modal is sized for confirm
   dialogs (max-width 480px); detail JSON wants more room. */
.modal-wide {
  max-width: 720px;
  width: min(90vw, 720px);
}
.modal-wide .hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1rem;
}
.modal-wide .hint code {
  color: var(--text);
  background: var(--bg);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-size: 0.85rem;
}

/* Close (×) button anchored to the modal's top-right. Visually quiet
   so it doesn't fight with the title. */
.btn-dismiss {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  font-family: inherit;
}
.btn-dismiss:hover { color: var(--text); }
.modal { position: relative; } /* anchor for btn-dismiss */

/* Pretty-printed JSON box inside the detail modal. Scrolls when the
   payload is taller than the viewport allows; word-breaks long lines
   so a stray long string doesn't blow out the modal width. */
.code-block-wrap {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 60vh;
  overflow: auto;
}
.code-block {
  margin: 0;
  padding: 0.9rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* -------------------------------------------------------------------
   Plan management pages — list + edit form + reconcile report.
   ------------------------------------------------------------------- */

/* Page header: title on the left, action buttons on the right. Mirrors
   the users list but with "New plan" + "Reconcile" primary actions. */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.page-header h1 { margin: 0; }
.page-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Row action cluster in tables: Edit + Archive sit side-by-side without
   stretching. Inline-form avoids trapping the button below the row. */
.row-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}
.row-actions .inline-form { display: inline-flex; margin: 0; }

/* Plan edit form. Stacks card sections; each label is a flex column so
   the help text lines up under the input. */
.plan-form .card { margin-bottom: 1rem; }
.plan-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}
.plan-form label:last-child { margin-bottom: 0; }
.plan-form label > span { font-weight: 500; font-size: 0.9rem; }
.plan-form input[type="text"],
.plan-form input[type="number"],
.plan-form textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
}
.plan-form input[readonly] { opacity: 0.7; cursor: not-allowed; }
.plan-form textarea { resize: vertical; line-height: 1.4; }
.plan-form small { font-size: 0.8rem; }

/* Side-by-side inputs on a single row: pricing trio, sort/active/featured. */
.inline-fields {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.inline-fields > label { flex: 1 1 180px; margin-bottom: 0; }

/* Checkbox label: inline layout, not stacked. Overrides the column
   default so "Active" reads left-to-right. */
.plan-form label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}
.plan-form label.checkbox > span { font-weight: 400; }
.plan-form label.checkbox input { margin: 0; }

/* Tighter kv list used under the Pricing card to show Stripe IDs
   without the breathing room the profile dl uses. */
.kv-compact { font-size: 0.85rem; margin-top: 0.75rem; }
.kv-compact dt, .kv-compact dd { padding: 0.15rem 0; }

/* Form submit row: Cancel on the left, Save on the right. */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}
.form-actions .btn-cancel { margin-right: auto; }
