/* ============================================================================
   02 · BASE & CORE CONTROLS

   Reset, global UI scale, spinner, apply-template + skeleton loading, badge,
   buttons, form fields, colour picker, checkbox, toggle, card, table, pagination.

   Part of the dashboard stylesheet, split out of the former single style.css.
   LOAD ORDER IS LOAD-BEARING (later parts intentionally override earlier
   ones) — the canonical order is dashboard/views/partials/_app_styles.ejs.
   ========================================================================== */

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* The `hidden` attribute must actually hide. The UA rule behind it is only
   `[hidden]{display:none}`, so ANY author `display` on the same element silently
   beats it — and every layout class here sets one. That is not a theoretical
   footgun: it is why the escalation level editor showed Duration, Role and
   Custom-action on punishments that have none, and why the per-level messages
   block sat permanently open with its toggle button appearing to do nothing
   (`.pn-fld{display:flex}` / `.pn-level-msgs{display:grid}` over `hidden`).
   The stylesheet had already grown six one-off `.thing[hidden]{display:none}`
   patches, each added the day this bit somewhere new; this is that patch made
   general so the next `hidden` works without a seventh. `!important` is required
   — a plain declaration here would lose to the very rules it exists to beat. */
[hidden] { display: none !important; }

/* ===== GLOBAL UI SCALE =====
   The whole dashboard is authored in rem against a 16px root. Dialling the root
   font-size down shrinks every rem-based size (type, padding, gaps, icons)
   proportionally so more content fits on screen, while px values (hairline
   borders, shadows) and px-based media-query breakpoints stay crisp/unchanged.
   Tune this single value to make the UI larger (↑) or denser (↓). */
html { font-size: 90%; }                 /* 16px → 14.4px base (≈10% denser) */
@media (max-width: 900px) { html { font-size: 93.75%; } }  /* ease off on touch */

body {
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
/* max-width:100% keeps content images (welcome/rank-card canvas previews, embed
   image previews, custom backgrounds) from overflowing their container and
   forcing horizontal scroll on small screens. Fixed-size UI images (avatars,
   emoji) set explicit width/height so this only ever clamps, never distorts. */
img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
svg { display: inline-block; vertical-align: middle; }
ion-icon { display: inline-block; vertical-align: middle; pointer-events: none; }

/* ===== SPINNER ===== */
.spinner {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid var(--blurple);
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== APPLY TEMPLATE LOADING ===== */
.apply-bounce-dots { display:flex; gap:0.5rem; align-items:center; }
.apply-bounce-dot {
  width: 0.5rem; height: 0.5rem;
  border-radius: 50%;
  background: var(--blurple);
  display: inline-block;
  animation: apply-bounce 1.1s ease-in-out infinite both;
}
@keyframes apply-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1;   }
}
.apply-step-dot { width:0.5rem; height:0.5rem; border-radius:50%; flex-shrink:0; display:inline-block; }
.apply-step-dot--active  { background:var(--blurple); animation:apply-pulse 1s ease-in-out infinite; }
.apply-step-dot--pending { background:var(--text-muted); }
@keyframes apply-pulse {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%       { transform: scale(1.5); opacity: 0.7; }
}

.spinner-center {
  display: flex;
  justify-content: center;
  padding: 5rem 0;
}

/* ===== SKELETON LOADING =====
   Layout-matched placeholder blocks shown while a page fetches its data (replaces
   the old full-page spinner). Each .sk is a shimmering neutral rectangle; the
   composite page skeletons (see components.js `skeleton()`) reuse the REAL layout
   containers (.page-content / .ga-stats / .ga-layout / .ga-panel / .gw-card) so the
   loaded content drops into the same shape with no reflow "jump". */
.skeleton-page { animation: sk-fade 0.25s var(--ease); }
@keyframes sk-fade { from { opacity: 0; } to { opacity: 1; } }

.sk {
  position: relative;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0.4rem;
  flex-shrink: 0;
}
.sk::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent);
  animation: sk-shimmer 1.5s ease-in-out infinite;
}
@keyframes sk-shimmer { 100% { transform: translateX(100%); } }

@media (prefers-reduced-motion: reduce) {
  .sk::after { animation: none; }
}

/* ===== BADGE ===== */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  white-space: nowrap;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease-in-out, border-color 0.18s ease-in-out,
              box-shadow 0.18s ease-in-out, transform 0.12s ease-in-out, opacity 0.18s;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring-blue); }

.btn-primary {
  background: linear-gradient(135deg, var(--crimson), var(--crimson-dark)); color: #fff;
  box-shadow: 0 8px 22px -6px rgba(220,38,38,.55), inset 0 0 0 1px rgba(255,255,255,0.07);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 14px 30px -6px rgba(220,38,38,.7), inset 0 0 0 1px rgba(255,255,255,0.1); }
.btn-primary:focus-visible { box-shadow: var(--ring-blue); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); border-color: #3E5170; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: rgba(255,255,255,0.05); border-color: #3E5170; }

.btn-secondary {
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(var(--green-rgb),0.32);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--pistachio);
  background: rgba(var(--green-rgb),0.10);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -6px rgba(var(--green-rgb),0.35);
}

/* Success — upgrades, saves, confirmations */
.btn-success {
  background: rgba(var(--green-rgb),0.12);
  border: 1px solid rgba(var(--green-rgb),0.32);
  color: var(--pistachio-light);
}
.btn-success:hover:not(:disabled) {
  background: rgba(var(--green-rgb),0.20);
  border-color: rgba(var(--green-rgb),0.52);
}
.btn-success:focus-visible { box-shadow: 0 0 0 3px rgba(var(--green-rgb),0.35); }
.btn-success-solid { background: linear-gradient(135deg, var(--pistachio), var(--pistachio-dark)); color: #0A0A0F; border-color: transparent; box-shadow: 0 8px 22px -6px rgba(var(--green-rgb),0.55); }
.btn-success-solid:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 14px 28px -6px rgba(var(--green-rgb),0.7); }

.btn-danger {
  background: rgba(var(--red-rgb),0.15);
  border: 1px solid rgba(var(--red-rgb),0.32);
  color: #F87171;
}
.btn-danger:hover:not(:disabled) { background: rgba(var(--red-rgb),0.25); border-color: rgba(var(--red-rgb),0.52); }
.btn-danger:focus-visible { box-shadow: 0 0 0 3px rgba(var(--red-rgb),0.35); }
.btn-danger-solid { background: var(--red); color: #fff; border-color: transparent; }
.btn-danger-solid:hover:not(:disabled) { background: #DC2626; box-shadow: 0 4px 14px rgba(var(--red-rgb),0.4); }

.btn-filter {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  background: var(--surface);
  color: var(--text-muted);
}
.btn-filter.active { background: var(--blurple); color: #fff; border-color: var(--blurple); }

/* ===== FORM ELEMENTS ===== */
.input, .select, .textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  background: rgba(255,255,255,.035);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input:hover:not(:focus), .select:hover:not(:focus), .textarea:hover:not(:focus) { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--crimson);
  box-shadow: 0 0 0 3px rgba(var(--blue-rgb),0.16);
  background: rgba(220,38,38,.04);
}
.select {
  color-scheme: dark;
}
select.input,
select:not([multiple]) {
  -webkit-appearance: none;
  appearance: none;
  color-scheme: dark;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23949BA4' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  background-size: 1rem;
  padding-right: 2.25rem;
  cursor: pointer;
}
select[multiple].input {
  -webkit-appearance: auto;
  appearance: auto;
  background-image: none;
  padding-right: 0.75rem;
  cursor: default;
}
.textarea { resize: vertical; }

/* Color-picker button: a neutral rounded button showing a palette glyph tinted to
   the current colour. The real <input type="color"> sits invisibly on top to open
   the OS colour dialog on click. --col (set inline / synced from JS) is the swatch. */
.color-pick {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  height: 2.4rem;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: rgba(255,255,255,.035);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.color-pick:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.color-pick input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  opacity: 0;
  cursor: pointer;
}
.color-pick ion-icon {
  pointer-events: none;
  font-size: 1.35rem;
  color: var(--col, var(--text-muted));
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.45));
}
/* Small colour bar along the bottom so the exact hue is visible even when the icon
   colour is hard to read on the dark surface. */
.color-pick::after {
  content: '';
  position: absolute;
  left: 0.4rem;
  right: 0.4rem;
  bottom: 0.32rem;
  height: 0.2rem;
  border-radius: 999px;
  background: var(--col, var(--text-muted));
}

/* ===== CHECKBOX =====
   Themed to match the glass inputs + crimson accent. Applies to every native
   checkbox in the dashboard (they all use <input type="checkbox">). */
input[type="checkbox"]:not(.toggle-native) {
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  border-radius: 0.375rem;
  border: 1px solid var(--border-strong);
  background: rgba(255,255,255,.04);
  cursor: pointer;
  position: relative;
  display: inline-grid;
  place-content: center;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
  vertical-align: middle;
  color-scheme: dark;
}
input[type="checkbox"]:not(.toggle-native):hover {
  border-color: var(--crimson);
  background: rgba(220,38,38,.06);
}
input[type="checkbox"]:not(.toggle-native)::before {
  content: "";
  width: 0.625rem;
  height: 0.625rem;
  transform: scale(0);
  transition: transform 0.12s var(--spring);
  background-color: #fff;
  /* crisp checkmark glyph */
  clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 16%, 86% 0, 38% 70%);
}
input[type="checkbox"]:not(.toggle-native):checked {
  background: linear-gradient(135deg, var(--crimson), var(--crimson-dark));
  border-color: var(--crimson);
  box-shadow: 0 2px 8px -2px rgba(var(--blue-rgb),0.55);
}
input[type="checkbox"]:not(.toggle-native):checked::before { transform: scale(1); }
input[type="checkbox"]:not(.toggle-native):indeterminate {
  background: linear-gradient(135deg, var(--crimson), var(--crimson-dark));
  border-color: var(--crimson);
}
input[type="checkbox"]:not(.toggle-native):indeterminate::before {
  transform: scale(1);
  clip-path: none;
  width: 0.55rem;
  height: 2px;
  border-radius: 2px;
}
input[type="checkbox"]:not(.toggle-native):focus-visible {
  outline: none;
  box-shadow: var(--ring-blue);
}
input[type="checkbox"]:not(.toggle-native):disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.input-label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ===== TOGGLE ===== */
.toggle-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
}

.toggle-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.toggle-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.45;
}

.toggle-btn {
  position: relative;
  flex-shrink: 0;
  width: 2.75rem;
  height: 1.5rem;
  border-radius: 9999px;
  border: none;
  background: var(--surface-hover);
  cursor: pointer;
  transition: background 0.2s;
  outline: none;
  margin-top: 0.125rem;
}
.toggle-btn.on { background: linear-gradient(135deg, var(--crimson), var(--crimson-dark)); }
.toggle-btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.toggle-thumb {
  position: absolute;
  top: 0.25rem;
  left: 0.25rem;
  width: 1rem;
  height: 1rem;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  pointer-events: none;
}
.toggle-btn.on .toggle-thumb { transform: translateX(1.25rem); }

/* ===== CARD ===== */
.card {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  backdrop-filter: blur(14px);
}
/* hairline highlight along the top edge — the reference's signature card detail */
.card::after {
  content: '';
  position: absolute;
  top: 0; left: 1px; right: 1px;
  height: 1px;
  border-radius: 18px 18px 0 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.22), transparent);
  pointer-events: none;
}

.card-sm {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  backdrop-filter: blur(14px);
}

/* ===== TABLE ===== */
.table-wrap {
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--border);
}

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

thead { background: var(--bg-secondary); }

th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s ease-in-out; }
tr.row-even td { background: var(--bg-card); }
tr.row-odd td { background: rgba(255,255,255,0.015); }
tbody tr:hover td { background: rgba(var(--blue-rgb),0.06); }
td { border-bottom: 1px solid var(--border-color); }

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
