/* Admin console layout + components. Depends only on css/tokens.css (linked
   before this file in admin.html), which @imports the shared nc-* primitives
   (buttons, badges, skeletons, dialog, toast, focus ring). No styles.css, so
   nothing bleeds in from the guide's sidebar layout.

   Redesign (Phase 1 — Admin): true black & white + a single orange accent
   (#ED7534). Orange appears only on the active tab, primary actions, the
   headline stat numbers, focus rings, and the "active" status chip. Everything
   else is neutral; danger is red. Orange TEXT on light uses --s-text (AA-safe).
   See docs/redesign/00-discovery-and-spec.md §5. */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--fb);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- gates (not-authorized / loading / error) ---- */
.admin-gate { max-width: 640px; margin: 80px auto; padding: 0 24px; }
.admin-gate h1 { font-family: var(--fd); font-weight: 600; font-size: 32px; margin: 0 0 8px; }
.admin-gate p { color: var(--muted); }
.admin-gate a { color: var(--s-text); }

#admin-app { max-width: 1000px; margin: 0 auto; padding: 24px 24px 64px; }

/* ---- header ---- */
.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
  position: sticky; top: 0; z-index: 80; background: var(--bg);
}
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .admin-header { background: var(--bg-glass); backdrop-filter: blur(var(--blur)) saturate(var(--glass-sat)); -webkit-backdrop-filter: blur(var(--blur)) saturate(var(--glass-sat)); }
}
.admin-header-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.admin-back { color: var(--muted); text-decoration: none; font-size: 13px; white-space: nowrap; transition: color var(--d1); }
.admin-back:hover { color: var(--s-text); }
.admin-header h1 { font-family: var(--fd); font-weight: 600; font-size: 28px; margin: 0; line-height: 1; }
.admin-header-actions { display: flex; align-items: center; gap: 14px; }

/* Dark-mode switch: the same sun/moon component as the main site (index.html /
   styles.css) so the toggle looks and behaves identically across the app. */
.icon { width: 1em; height: 1em; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; fill: none; vertical-align: -0.125em; flex-shrink: 0; }
/* --switch-thumb: the knob stays a bright dot in BOTH modes (reads on the
   neutral track and on the orange checked track), so it's an intentional
   constant rather than a mode-flipping neutral token. */

/* ---- tab bar (active = orange text + a sliding orange indicator) ---- */
.admin-tabs { position: relative; display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.admin-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 9px 14px; margin-bottom: -1px;
  font-family: var(--fb); font-size: 13px; font-weight: 500; letter-spacing: .01em;
  color: var(--muted); cursor: pointer;
  transition: color var(--d1), border-color var(--d1);
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--s-text); }
/* Sliding indicator (js/admin.js positions it via transform+width on tab
   change, resize, and reduced-motion snaps). Sits over the transparent
   border-bottom reserved on every tab, so switching tabs never shifts layout. */
.admin-tab-indicator {
  position: absolute; left: 0; top: 0; height: 2px; width: 0;
  background: var(--s); border-radius: 1px; opacity: 0; pointer-events: none;
  transition: transform var(--spring-dur-1) var(--spring-1), width var(--spring-dur-1) var(--spring-1), opacity var(--d1) var(--ease-out);
}
.admin-tab-indicator.is-visible { opacity: 1; }

/* ---- panels ---- */
/* Each tab panel is the tab's work surface: base --elev-1 + --hairline so it
   reads as a raised card in both modes (the hairline is THE lift cue on true
   black). Only the .active panel is ever displayed. */
.admin-panel {
  display: none;
  background: var(--bg1); border: 1px solid var(--border); border-radius: var(--rl);
  box-shadow: var(--elev-1), var(--hairline); padding: var(--sp-20) var(--sp-24);
}
.admin-panel.active { display: block; animation: admin-panel-in var(--d3) var(--ease-out); }
@keyframes admin-panel-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.admin-panel h2 { font-family: var(--fm); font-weight: 400; font-size: 11px; text-transform: uppercase; letter-spacing: .16em; color: var(--dim); margin: 30px 0 12px; }
.admin-panel h2:first-child { margin-top: 0; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-family: var(--fm); font-weight: 400; font-size: var(--fs-micro);
  letter-spacing: .12em; text-transform: uppercase; color: var(--dim);
  padding: var(--sp-10); border-bottom: 1px solid var(--b2); white-space: nowrap;
}
td { padding: var(--sp-10); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background var(--d1); }
tbody tr:hover td { background: var(--bg2); }
/* Selectable / active row = accent wash + inset orange left-rail (matches nc-row). */
tbody tr[data-selected] td { background: var(--s2); }
tbody tr[data-selected] td:first-child { box-shadow: inset 2px 0 0 var(--s); }
.row-deactivated td { opacity: .55; }

/* ---- form controls ---- */
input[type="text"], input[type="email"], input[type="search"], input[type="number"], select, textarea {
  padding: 8px 11px; border: 1px solid var(--b2); border-radius: var(--r);
  background: var(--bg1); color: var(--text); font: inherit; font-size: 13px;
  transition: border-color var(--d1), box-shadow var(--d2) var(--ease-out);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--s); box-shadow: var(--ring); }
input[type="checkbox"] { accent-color: var(--s); cursor: pointer; }

/* Label color picker — kept (users pick arbitrary colors) but rendered as a
   small round swatch dot rather than a chunky native control (spec §5). */
input[type="color"].label-color {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; padding: 0; margin: 0; vertical-align: middle;
  border: 1px solid var(--b2); border-radius: 50%; background: none; cursor: pointer;
}
input[type="color"].label-color::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"].label-color::-webkit-color-swatch { border: none; border-radius: 50%; }
input[type="color"].label-color::-moz-color-swatch { border: none; border-radius: 50%; }

/* Narrow number inputs keep the shared field style, just a fixed width. */
input[type="number"].ai-cap-input { width: 96px; }
input[type="number"].brand-order-input { width: 68px; }

/* ---- buttons ---- */
/* Primary/secondary/danger/ghost actions use the shared .nc-btn classes from
   css/primitives.css. This base rule only catches any bare <button>. */
button {
  padding: 8px 14px; border: 1px solid var(--b2); border-radius: var(--r);
  background: var(--bg1); color: var(--text); font: inherit; font-size: 13px;
  cursor: pointer; transition: border-color var(--d1), background var(--d1);
}
/* Scoped to bare buttons: without :not(.nc-btn) this element-level :hover
   (specificity 0,1,1) would override .nc-btn--primary's orange border (0,1,0),
   graying the primary button's edge on hover. The .nc-btn primitive owns all
   .nc-btn hover/press styling (spring + --glow-accent). */
button:not(.nc-btn):hover { border-color: var(--b3); }
button:disabled { opacity: .45; cursor: not-allowed; }

/* Compact inline row actions (Resend / Deactivate / Delete …) stay as subtle
   text buttons so tables read cleanly; danger variant is red. */
.link-btn {
  background: none; border: none; color: var(--muted); text-decoration: underline;
  text-underline-offset: 2px; padding: 0 6px 0 0; cursor: pointer; font-size: 12px;
  font-family: var(--fb); transition: color var(--d1);
}
.link-btn:hover { color: var(--s-text); }
.link-btn.danger { color: var(--red); }
.link-btn:disabled { color: var(--dim); text-decoration: none; cursor: not-allowed; }

/* ---- forms / toolbars ---- */
.admin-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.admin-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 12px; }
.admin-toolbar label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dept-checkbox { display: inline-flex; align-items: center; gap: 2px; margin-right: 8px; font-size: 12px; }

/* ---- inline click-to-edit ---- */
.inline-edit { cursor: text; border-bottom: 1px dashed var(--b2); transition: border-color var(--d1); }
.inline-edit:hover { border-bottom-color: var(--s); }

/* ---- stat tiles (neutral surface, orange headline number, mono label) ---- */
.pm-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.pm-stat {
  border: 1px solid var(--border); border-radius: var(--rl); padding: 12px 18px;
  min-width: 92px; text-align: center; background: var(--bg1);
  box-shadow: var(--elev-1), var(--hairline);
  transition: border-color var(--d2), box-shadow var(--d2) var(--ease-out);
}
.pm-stat:hover { border-color: var(--border-raised); box-shadow: var(--elev-2), var(--hairline); }
.pm-stat-n { display: block; font-family: var(--fd); font-size: 30px; font-weight: 600; line-height: 1; color: var(--s-text); }
.pm-stat-l { display: block; margin-top: 6px; font-family: var(--fm); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }

/* ---- loading skeletons (js/admin/skeleton.js) ---- */
.admin-sk-cell { display: block; width: 80%; height: 12px; }
.admin-sk-stat { display: block; width: 52px; height: 26px; margin: 2px auto; border-radius: 6px; }

/* ---- misc text ---- */
.admin-error { color: var(--red); margin: 8px 0; min-height: 18px; }
.admin-empty { color: var(--muted); font-style: italic; text-align: center; padding: 22px 12px; }
.admin-hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.admin-note { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.admin-muted { color: var(--muted); }

/* Brand Review reference-asset thumbnail. */
.brand-asset-thumb {
  display: block; width: 48px; height: 48px; object-fit: cover;
  border: 1px solid var(--border); border-radius: var(--r);
}

/* ---- responsive: tablet (≤900px) ---- */
@media (max-width: 900px) {
  /* Every table here has 2–7 columns, some with per-row checkboxes/badges/
     action links that don't compress well. Rather than squeeze columns
     until they're unreadable, let each table scroll horizontally within its
     own box — setting the <table> itself to display:block generates an
     anonymous table box for its rows/cells, so column alignment between
     thead/tbody is preserved while the outer box scrolls. Harmless on
     tables that already fit (no scrollbar appears). */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---- responsive: phone (≤640px) ---- */
@media (max-width: 640px) {
  #admin-app { padding: 16px 16px 48px; }
  .admin-header h1 { font-size: 22px; }
  .admin-header-actions { gap: 10px; }

  /* Bigger tap targets for touch (~40-44px): tab bar, primary/secondary
     buttons, inline row-action links, checkboxes. */
  .admin-tab { padding: 12px 12px; }
  .nc-btn { padding: 13px 18px; }
  .link-btn { padding: 6px 8px 6px 0; }
  input[type="checkbox"] { width: 18px; height: 18px; }

  /* Toolbar/form fields: stack text-like inputs to full width instead of
     the cramped multi-per-row layout flex-wrap alone produces. Fixed-width
     numeric fields (.ai-cap-input, .brand-order-input) and checkboxes are
     intentionally excluded so they keep their compact size. */
  .admin-form input[type="text"],
  .admin-form input[type="email"],
  .admin-form input[type="search"],
  .admin-form select,
  .admin-toolbar input[type="search"] { flex: 1 1 100%; }
  .admin-form button[type="submit"] { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .admin-panel.active { animation: none; }
  .admin-tab, .admin-back,
  input, select, textarea, button, .link-btn, .inline-edit, .pm-stat, tbody tr,
  .admin-tab-indicator { transition: none; }
}
