/* ==========================================================================
   EDGAR Insights — Admin console styles (public/admin.css)
   Relies on the design tokens defined by styles.css (SPEC §12 token contract),
   but EVERY var() carries a literal fallback so the console renders acceptably
   standalone. Loaded after styles.css.
   ========================================================================== */

/* The [hidden] attribute must always win over author display rules
   (e.g. .admin-gate { display:flex }), or gate/app toggling breaks. */
[hidden] {
  display: none !important;
}

/* ---------- Page chrome ---------- */

.admin-body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg, #F7F8FA);
  color: var(--text, #0B1220);
  font-family: var(--font-sans, -apple-system, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif);
  -webkit-font-smoothing: antialiased;
}

.admin-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.admin-mono {
  font-family: var(--font-mono, ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace);
  font-variant-numeric: tabular-nums;
  font-size: 0.92em;
}

.admin-muted { color: var(--text-muted, #5B6472); }
.admin-strong { font-weight: 600; }
.admin-hint {
  margin: 10px 2px 0;
  font-size: 12.5px;
  color: var(--text-muted, #5B6472);
}

.admin-noscript {
  max-width: 480px;
  margin: 80px auto;
  text-align: center;
  color: var(--text-muted, #5B6472);
}

/* ---------- Token gate ---------- */

.admin-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  box-sizing: border-box;
}

.admin-gate-card {
  width: min(380px, 100%);
  padding: 36px 32px 32px;
  text-align: center;
  background: var(--surface, #FFFFFF);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.10));
  border-radius: var(--radius, 14px);
  box-shadow: var(--shadow-2, 0 12px 32px rgba(11, 18, 32, 0.12));
}

.admin-gate-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.02em;
  color: var(--accent-contrast, #FFFFFF);
  background: var(--accent, #3B5BFD);
  border-radius: 12px;
}

.admin-gate-title {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.admin-gate-sub {
  margin: 0 0 20px;
  font-size: 13.5px;
  color: var(--text-muted, #5B6472);
}

.admin-gate-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 12px;
  padding: 11px 14px;
  font-size: 14px;
  font-family: var(--font-mono, ui-monospace, Menlo, Consolas, monospace);
  color: var(--text, #0B1220);
  background: var(--bg, #F7F8FA);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.14));
  border-radius: 10px;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.admin-gate-input:focus-visible {
  border-color: var(--accent, #3B5BFD);
  box-shadow: 0 0 0 3px rgba(59, 91, 253, 0.20);
}

.admin-gate-btn { width: 100%; }

.admin-gate-error {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--danger, #D5484C);
}

@keyframes admin-shake {
  10%, 90%       { transform: translateX(-1px); }
  20%, 80%       { transform: translateX(2px); }
  30%, 50%, 70%  { transform: translateX(-5px); }
  40%, 60%       { transform: translateX(5px); }
}

.admin-gate-card.is-shaking {
  animation: admin-shake 520ms cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* ---------- Top bar ---------- */

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--bg-elev, #FFFFFF);
  border-bottom: 1px solid var(--border, rgba(11, 18, 32, 0.10));
  backdrop-filter: blur(8px);
}

.admin-wordmark {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text, #0B1220);
  text-decoration: none;
}

.admin-wordmark-sep { color: var(--text-muted, #5B6472); font-weight: 400; }
.admin-wordmark-admin { color: var(--accent, #3B5BFD); }

.admin-topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-icon-btn {
  min-width: 36px;
  padding-left: 10px;
  padding-right: 10px;
  font-size: 15px;
  line-height: 1;
}

/* ---------- Layout ---------- */

.admin-main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 24px 72px;
  box-sizing: border-box;
}

/* ---------- Stat cards ---------- */

.admin-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 10px;
}

@media (max-width: 900px) { .admin-stats { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .admin-stats { grid-template-columns: 1fr; } }

.admin-stat {
  padding: 16px 18px;
  background: var(--surface, #FFFFFF);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.10));
  border-radius: var(--radius, 14px);
  box-shadow: var(--shadow-1, 0 1px 3px rgba(11, 18, 32, 0.06));
}

.admin-stat-label {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted, #5B6472);
}

.admin-stat-value {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text, #0B1220);
}

.admin-stat-value-sm { font-size: 18px; line-height: 1.5; }

.admin-top-tickers {
  margin: 4px 2px 18px;
  font-size: 12.5px;
  color: var(--text-muted, #5B6472);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* ---------- Tabs ---------- */

.admin-tabs {
  display: flex;
  gap: 4px;
  margin: 18px 0 16px;
  padding: 4px;
  background: var(--bg-elev, #EEF0F4);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.08));
  border-radius: 12px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}

.admin-tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 8px 16px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted, #5B6472);
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.admin-tab:hover { color: var(--text, #0B1220); }

.admin-tab:focus-visible {
  outline: 2px solid var(--accent, #3B5BFD);
  outline-offset: 1px;
}

.admin-tab.is-active {
  background: var(--surface, #FFFFFF);
  color: var(--text, #0B1220);
  box-shadow: var(--shadow-1, 0 1px 3px rgba(11, 18, 32, 0.10));
}

/* ---------- Panels & toolbar ---------- */

.admin-panel { display: none; }
.admin-panel.is-active { display: block; animation: admin-fade-in 220ms ease; }

@keyframes admin-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.admin-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.admin-search {
  flex: 1;
  max-width: 340px;
  box-sizing: border-box;
  padding: 9px 13px;
  font-size: 13.5px;
  color: var(--text, #0B1220);
  background: var(--surface, #FFFFFF);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.14));
  border-radius: 10px;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.admin-search:focus-visible {
  border-color: var(--accent, #3B5BFD);
  box-shadow: 0 0 0 3px rgba(59, 91, 253, 0.18);
}

.admin-reload { flex: 0 0 auto; }

/* ---------- Tables ---------- */

.admin-table-wrap {
  max-height: min(62vh, 640px);
  overflow: auto;
  background: var(--surface, #FFFFFF);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.10));
  border-radius: var(--radius, 14px);
  box-shadow: var(--shadow-1, 0 1px 3px rgba(11, 18, 32, 0.06));
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
  color: var(--text-muted, #5B6472);
  background: var(--bg-elev, #F2F3F7);
  border-bottom: 1px solid var(--border, rgba(11, 18, 32, 0.10));
}

.admin-table tbody td {
  padding: 10px 14px;
  vertical-align: top;
  border-bottom: 1px solid var(--border, rgba(11, 18, 32, 0.06));
  color: var(--text, #0B1220);
  font-variant-numeric: tabular-nums;
}

.admin-table tbody tr:last-child td { border-bottom: 0; }

.admin-table tbody tr {
  transition: background 150ms ease;
}

.admin-table tbody tr:hover { background: var(--bg, rgba(11, 18, 32, 0.025)); }

.admin-table-clickable tbody tr[data-id] { cursor: pointer; }

.admin-table-clickable tbody tr[data-id]:focus-visible {
  outline: 2px solid var(--accent, #3B5BFD);
  outline-offset: -2px;
}

.admin-clip {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-error-cell { color: var(--danger, #D5484C); }
.admin-cell-action { text-align: right; white-space: nowrap; }
.admin-tags-cell { max-width: 320px; }

/* Status + tags */

.admin-status {
  display: inline-block;
  min-width: 36px;
  padding: 2px 8px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-radius: 999px;
  border: 1px solid var(--border, rgba(11, 18, 32, 0.10));
}

.admin-status-ok     { color: var(--success, #1F9D55); background: rgba(31, 157, 85, 0.10); border-color: rgba(31, 157, 85, 0.25); }
.admin-status-warn   { color: var(--warning, #B7791F); background: rgba(183, 121, 31, 0.10); border-color: rgba(183, 121, 31, 0.25); }
.admin-status-danger { color: var(--danger, #D5484C);  background: rgba(213, 72, 76, 0.10);  border-color: rgba(213, 72, 76, 0.25); }

.admin-tag {
  display: inline-block;
  padding: 2px 8px;
  margin: 1px 0;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted, #5B6472);
  background: var(--bg-elev, #EEF0F4);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.08));
  border-radius: 999px;
  white-space: nowrap;
}

.admin-tag-hit     { color: var(--success, #1F9D55); background: rgba(31, 157, 85, 0.10);  border-color: rgba(31, 157, 85, 0.25); }
.admin-tag-success { color: var(--success, #1F9D55); background: rgba(31, 157, 85, 0.10);  border-color: rgba(31, 157, 85, 0.25); }
.admin-tag-warn    { color: var(--warning, #B7791F); background: rgba(183, 121, 31, 0.10); border-color: rgba(183, 121, 31, 0.25); }
.admin-tag-danger  { color: var(--danger, #D5484C);  background: rgba(213, 72, 76, 0.10);  border-color: rgba(213, 72, 76, 0.25); }
.admin-tag-accent  { color: var(--accent, #3B5BFD);  background: rgba(59, 91, 253, 0.10);  border-color: rgba(59, 91, 253, 0.25); }

/* ---------- Loading shimmer / empty states ---------- */

@keyframes admin-shimmer-sweep {
  from { background-position: -200px 0; }
  to   { background-position: 200px 0; }
}

.admin-shimmer {
  display: inline-block;
  width: 72%;
  min-width: 36px;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--bg-elev, #EEF0F4) 25%,
    var(--border, rgba(11, 18, 32, 0.10)) 50%,
    var(--bg-elev, #EEF0F4) 75%
  );
  background-size: 400px 100%;
  animation: admin-shimmer-sweep 1.2s linear infinite;
}

.admin-shimmer-wide { width: 100%; height: 16px; }

.admin-shimmer-row td { padding-top: 13px; padding-bottom: 13px; }

.admin-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 44px 16px;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-muted, #5B6472);
}

.admin-empty-glyph { font-size: 22px; opacity: 0.55; }
.admin-empty-error { color: var(--danger, #D5484C); }

/* ---------- Buttons (fallbacks if styles.css absent) ---------- */

.admin-body .btn {
  font: inherit;
  cursor: pointer;
}

.admin-row-refresh {
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 9px;
}

.admin-row-refresh.is-busy { opacity: 0.75; cursor: progress; }

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

.admin-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 7px;
  vertical-align: -1.5px;
  border: 2px solid var(--border, rgba(11, 18, 32, 0.18));
  border-top-color: var(--accent, #3B5BFD);
  border-radius: 50%;
  animation: admin-spin 700ms linear infinite;
}

/* ---------- Refresh tab ---------- */

.admin-refresh-card {
  max-width: 720px;
  padding: 26px 28px;
  background: var(--surface, #FFFFFF);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.10));
  border-radius: var(--radius, 14px);
  box-shadow: var(--shadow-1, 0 1px 3px rgba(11, 18, 32, 0.06));
}

.admin-refresh-title {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.admin-refresh-card p { font-size: 13.5px; line-height: 1.6; margin: 0 0 12px; }

.admin-refresh-card code {
  font-family: var(--font-mono, ui-monospace, Menlo, Consolas, monospace);
  font-size: 0.92em;
  padding: 1px 5px;
  background: var(--bg-elev, #EEF0F4);
  border-radius: 5px;
}

.admin-refresh-summary {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border, rgba(11, 18, 32, 0.10));
  animation: admin-fade-in 220ms ease;
}

.admin-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

@media (max-width: 560px) { .admin-summary-grid { grid-template-columns: repeat(2, 1fr); } }

.admin-summary-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  background: var(--bg-elev, #F2F3F7);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.08));
  border-radius: 10px;
}

.admin-summary-num {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text, #0B1220);
}

.admin-summary-stat-error .admin-summary-num { color: var(--danger, #D5484C); }

.admin-summary-lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted, #5B6472);
}

.admin-summary-errors {
  margin: 0 0 10px;
  padding-left: 20px;
  font-size: 13px;
  color: var(--danger, #D5484C);
}

.admin-summary-errors li { margin-bottom: 4px; }

.admin-summary-ts { font-size: 12px; }

/* ---------- Extraction drawer ---------- */

.admin-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(11, 18, 32, 0.40);
  opacity: 0;
  transition: opacity 200ms ease;
}

.admin-drawer-overlay.is-open { opacity: 1; }

.admin-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 61;
  width: min(680px, 94vw);
  display: flex;
  flex-direction: column;
  background: var(--surface, #FFFFFF);
  border-left: 1px solid var(--border, rgba(11, 18, 32, 0.10));
  box-shadow: var(--shadow-2, -16px 0 48px rgba(11, 18, 32, 0.18));
  transform: translateX(100%);
  transition: transform 220ms ease;
}

.admin-drawer.is-open { transform: translateX(0); }

.admin-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border, rgba(11, 18, 32, 0.10));
}

.admin-drawer-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.admin-drawer-actions { display: flex; align-items: center; gap: 8px; }

.admin-drawer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 20px 0;
}

.admin-json {
  flex: 1;
  margin: 14px 20px 20px;
  padding: 16px;
  overflow: auto;
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
  color: var(--text, #0B1220);
  background: var(--bg, #F7F8FA);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.08));
  border-radius: 12px;
  tab-size: 2;
}

.admin-json:focus-visible { outline: 2px solid var(--accent, #3B5BFD); }

/* ---------- Toasts ---------- */

.admin-toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(380px, calc(100vw - 40px));
}

@keyframes admin-toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.admin-toast {
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text, #0B1220);
  background: var(--surface, #FFFFFF);
  border: 1px solid var(--border, rgba(11, 18, 32, 0.12));
  border-left: 3px solid var(--accent, #3B5BFD);
  border-radius: 12px;
  box-shadow: var(--shadow-2, 0 12px 32px rgba(11, 18, 32, 0.16));
  animation: admin-toast-in 220ms ease;
  transition: opacity 300ms ease, transform 300ms ease;
}

.admin-toast-success { border-left-color: var(--success, #1F9D55); }
.admin-toast-error   { border-left-color: var(--danger, #D5484C); }

.admin-toast.is-leaving { opacity: 0; transform: translateY(6px); }

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .admin-main { padding: 16px 14px 56px; }
  .admin-topbar { padding: 10px 14px; }
  .admin-clip { max-width: 140px; }
  .admin-toolbar { flex-wrap: wrap; }
  .admin-search { max-width: none; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .admin-gate-card.is-shaking,
  .admin-shimmer,
  .admin-spinner,
  .admin-panel.is-active,
  .admin-refresh-summary,
  .admin-toast {
    animation: none;
  }
  .admin-drawer,
  .admin-drawer-overlay,
  .admin-toast {
    transition: none;
  }
}
