/* ============================================================
   Admin Dashboard — Market Insight
   Design system: bg #131316, surface #1c1c20, border #2a2a30,
   accent #4F98A3, text #e0e0e0
   ============================================================ */

:root {
  --bg:           #131316;
  --surface:      #1c1c20;
  --surface-hover:#222226;
  --border:       #2a2a30;
  --accent:       #4F98A3;
  --accent-bg:    rgba(79,152,163,0.1);
  --text:         #e0e0e0;
  --text-muted:   #b0bec5;
  --text-faint:   #5A5957;
  --up:           #0EB35B;
  --down:         #C24A4A;
  --radius:       8px;
  --radius-sm:    6px;
}

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

body.admin-page {
  min-height: 100dvh;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ---- Header ---- */
.admin-header-bg {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 24px;
  max-width: 1440px;
  margin: 0 auto;
}
.admin-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.admin-logo {
  flex-shrink: 0;
}
.admin-logo-title h1 {
  font-family: 'Inter Tight', sans-serif;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 1.5px;
  color: var(--text);
  line-height: 1;
}
.admin-logo-title h1 .logo-highlight {
  color: var(--accent);
  font-weight: 400;
}
.admin-logo-subtitle {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.5px;
  font-weight: 600;
}
.admin-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-user-email {
  font-size: 12px;
  color: var(--text-faint);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-header-btn {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.admin-header-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ---- Back to Dashboard link (matches member dashboard style) ---- */
.admin-back-link,
.admin-back-link:visited,
.admin-back-link:active {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none !important;
  transition: all 0.2s;
  white-space: nowrap;
  cursor: pointer;
}
.admin-back-link:hover {
  background: var(--accent-bg);
  color: var(--accent);
  text-decoration: none !important;
}

/* ---- Admin Avatar (matches member dashboard db-avatar) ---- */
.admin-avatar-wrap {
  position: relative;
}
.admin-avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #4F98A3;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: box-shadow 0.2s, transform 0.15s;
}
.admin-avatar-btn:hover {
  box-shadow: 0 0 0 3px rgba(79, 152, 163, 0.3);
  transform: scale(1.05);
}
.admin-avatar-btn .admin-avatar-initial {
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}
.admin-avatar-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 0;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 1000;
}
.admin-avatar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}
.admin-avatar-dropdown-item:hover {
  background: rgba(79, 152, 163, 0.12);
}

/* ---- Auth Gate (redesigned) ---- */
.admin-auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 180px);
  padding: 48px 20px;
}
.admin-auth-card {
  background: var(--surface, #1c1c20);
  border: 1px solid var(--border, #2a2a30);
  border-radius: 10px;
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 20px 40px rgba(0,0,0,0.25);
}
.admin-auth-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: rgba(79,152,163,0.10);
  border: 1px solid rgba(79,152,163,0.22);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}
.admin-auth-gate svg {
  width: 28px;
  height: 28px;
  stroke: var(--accent, #4F98A3);
  margin: 0;
}
.admin-auth-card h2 {
  font-family: 'Inter Tight', -apple-system, sans-serif;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text, #e0e0e0);
  margin: 0 0 8px;
  line-height: 1.15;
}
.admin-auth-card p {
  color: var(--text-muted, #b0bec5);
  font-size: 14px;
  max-width: 360px;
  line-height: 1.55;
  margin: 0 auto 24px;
}
.admin-auth-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.admin-auth-primary {
  color: #fff;
  text-decoration: none;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent, #4F98A3);
  padding: 11px 22px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  transition: filter 160ms ease, transform 160ms ease;
  display: inline-flex;
  align-items: center;
}
.admin-auth-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.admin-auth-secondary {
  color: var(--text-muted, #b0bec5);
  text-decoration: none;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 11px 16px;
  border-radius: 8px;
  transition: color 160ms ease;
}
.admin-auth-secondary:hover { color: var(--text, #e0e0e0); }

/* ---- Main Content ---- */
.admin-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* ---- Status Summary Bar ---- */
.admin-status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
}
.admin-status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.admin-status-indicator.healthy { background: var(--up); box-shadow: 0 0 6px rgba(14,179,91,0.4); }
.admin-status-indicator.degraded { background: #F59E0B; box-shadow: 0 0 6px rgba(245,158,11,0.4); }
.admin-status-indicator.error { background: var(--down); box-shadow: 0 0 6px rgba(194,74,74,0.4); }
.admin-status-text {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
}
.admin-status-text span { color: var(--text-muted); font-weight: 400; }
.admin-refresh-btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--accent-bg);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s;
}
.admin-refresh-btn:hover { background: rgba(79,152,163,0.2); }
.admin-refresh-btn.loading svg { animation: admin-spin 0.8s linear infinite; }
@keyframes admin-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ---- Tabs ---- */
.admin-tabs-nav {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.admin-tab-btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 20px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.admin-tab-btn:hover { color: var(--text); }
.admin-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---- Feedback open-status indicator ----
   A red flashing dot sits above the Feedback tab button whenever one or more
   feedback items have status = "Open". The dot is rendered via ::after so the
   DOM stays untouched; admin.js simply toggles the data-has-open attribute. */
.admin-tab-btn[data-admintab="feedback"] {
  position: relative;
}
.admin-tab-btn[data-admintab="feedback"][data-has-open="1"]::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #C24A4A;
  box-shadow: 0 0 0 0 rgba(194,74,74, 0.7);
  animation: adminFeedbackDotPulse 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  pointer-events: none;
}
@keyframes adminFeedbackDotPulse {
  0%   { opacity: 1;   box-shadow: 0 0 0 0    rgba(194,74,74, 0.75); }
  60%  { opacity: 0.55; box-shadow: 0 0 0 7px  rgba(194,74,74, 0);    }
  100% { opacity: 1;   box-shadow: 0 0 0 0    rgba(194,74,74, 0);    }
}
@media (prefers-reduced-motion: reduce) {
  .admin-tab-btn[data-admintab="feedback"][data-has-open="1"]::after {
    animation: none;
  }
}

/* ---- Iter 12CN — Mobile (≤640px) admin tabs: horizontal scroll ----
   The admin tab strip has ~11 tabs (Data Feeds, Cron Jobs, Cache Stats,
   Feedback, AI Feeds, Users, Analytics, Content, AI Prompts, Error Log,
   Audit Log, AI Sanity). On phone widths the flex row either wraps (ugly,
   takes 3+ rows of vertical space) or visually clips the trailing tabs
   (which is what happened on iPhone before this rule — "AI Feeds" was
   cut off mid-word). Convert the strip into a single-row swipeable
   horizontal scroller:
     • nowrap + overflow-x:auto so tabs flow off-screen and the user
       swipes left to reveal more.
     • -webkit-overflow-scrolling: touch for native iOS momentum.
     • scrollbar-width: none + ::-webkit-scrollbar { display:none } to
       hide the visible scrollbar (the swipe affordance is enough; the
       border-bottom on the nav makes it obvious you can swipe).
     • flex-shrink:0 on each button so they keep their natural width
       instead of squashing.
     • tighter padding (10px →14px) to fit more tabs per swipe.
     • scroll-snap-type: x proximity — swipe naturally settles on a tab
       edge rather than mid-button.
   Gated at ≤640px so desktop/tablet keep the full-width flex layout. */
@media (max-width: 640px) {
  .admin-tabs-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    /* Bleed the scroll area to the viewport edges so the last tab can
       sit flush against the right edge when fully scrolled. */
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
  }
  .admin-tabs-nav::-webkit-scrollbar { display: none; }
  .admin-tab-btn {
    flex-shrink: 0;
    padding: 10px 14px;
    white-space: nowrap;
    scroll-snap-align: start;
  }
  /* Pull the active tab's underline flush with the bottom of the nav
     so it doesn't appear to float when the user has scrolled. */
  .admin-tab-btn.active { border-bottom-width: 2px; }
}

/* ---- Data Feeds Table ---- */
.admin-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.admin-table thead th {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.admin-table tbody tr {
  border-bottom: 1px solid rgba(42,42,48,0.3);
  transition: background 0.1s;
}
.admin-table tbody tr:nth-child(even) { background: rgba(28,28,32,0.5); }
.admin-table tbody tr:hover { background: var(--surface-hover); }
.admin-table tbody td {
  padding: 10px 16px;
  color: var(--text);
  vertical-align: middle;
}
.admin-table .feed-name {
  font-weight: 600;
  white-space: nowrap;
}
.admin-table .feed-source {
  color: var(--text-muted);
  font-size: 12px;
}
.admin-table .feed-ticker {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  color: var(--accent);
}
.admin-table .feed-frequency {
  font-size: 12px;
  color: var(--text-muted);
}

/* Status dot */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.status-dot.green { background: #0EB35B; box-shadow: 0 0 4px rgba(14,179,91,0.5); }
.status-dot.red { background: #C24A4A; box-shadow: 0 0 4px rgba(194,74,74,0.5); }
.status-label {
  font-size: 12px;
  font-weight: 500;
}
.status-label.ok { color: #0EB35B; }
.status-label.err { color: #C24A4A; }

.admin-table .feed-updated {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  color: var(--text-faint);
}
.admin-table .feed-error {
  font-size: 12px;
  color: var(--text-faint);
}
.admin-table .feed-error.has-error {
  color: #C24A4A;
  font-weight: 500;
}

/* ---- Page/Tab Section Headers ---- */
.admin-table .feed-page-row { background: rgba(79, 152, 163, 0.06) !important; }
.admin-table .feed-page-row:hover { background: rgba(79, 152, 163, 0.10) !important; }
.admin-table .feed-page-header {
  font-family: 'Inter Tight', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.feed-page-header .page-label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.feed-page-header .page-label::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
}
.feed-page-header .page-count {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0;
}
.feed-page-header .page-count.page-all-ok {
  background: rgba(14, 179, 91, 0.15);
  color: #0EB35B;
}
.feed-page-header .page-count.page-has-errors {
  background: rgba(217, 18, 34, 0.15);
  color: #C24A4A;
}

/* ---- Feed View Toggle ---- */
.feed-view-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: fit-content;
}
.feed-view-btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 18px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.feed-view-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}
.feed-view-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.feed-view-btn.active {
  background: var(--accent-bg);
  color: var(--accent);
}

/* ---- Collapsible Page Sections ---- */
.feed-page-collapsible { user-select: none; }
.feed-page-collapsible:hover { background: rgba(79, 152, 163, 0.10) !important; }
.feed-page-chevron {
  display: inline-block;
  width: 14px;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.15s;
}

/* ---- Loading Skeleton ---- */
.admin-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
  gap: 10px;
}
.admin-loading svg { animation: admin-spin 0.8s linear infinite; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .admin-header { padding: 0 14px; }
  .admin-main { padding: 16px 12px 40px; }
  .admin-status-bar { flex-wrap: wrap; padding: 12px 14px; }
  .admin-table { font-size: 12px; }
  .admin-table thead th, .admin-table tbody td { padding: 8px 10px; }
  .admin-user-email { display: none; }
}

/* ---- Auto-refresh bar ---- */
.admin-autorefresh-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 16px;
}
.admin-autorefresh-bar svg {
  flex-shrink: 0;
  stroke: var(--text-faint);
}

/* ---- Tab panels ---- */
.admin-tab-panel { display: none; }
.admin-tab-panel.active { display: block; }

/* ---- Cache Stats ---- */
.admin-cache-timestamp {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 16px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.admin-cache-error {
  padding: 24px;
  color: var(--down);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-cache-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 16px;
}
.admin-cache-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.admin-cache-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(79,152,163,0.06);
}
.admin-cache-label {
  font-family: 'Inter Tight', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}
.admin-cache-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.admin-cache-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}
.admin-cache-summary {
  display: flex;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid rgba(42,42,48,0.4);
  font-size: 12px;
}
.admin-cache-fresh { color: var(--up); font-weight: 600; }
.admin-cache-stale { color: var(--down); font-weight: 600; }
.admin-cache-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.admin-cache-table thead th {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.admin-cache-table tbody tr {
  border-bottom: 1px solid rgba(42,42,48,0.2);
}
.admin-cache-table tbody tr:hover { background: var(--surface-hover); }
.admin-cache-table tbody td {
  padding: 7px 12px;
  vertical-align: middle;
}
.cache-key {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
}
.cache-stale-row { opacity: 0.6; }
.cache-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.cache-badge.fresh {
  background: rgba(14,179,91,0.15);
  color: #0EB35B;
}
.cache-badge.stale {
  background: rgba(194,74,74,0.15);
  color: #C24A4A;
}

.admin-cache-section-title {
  font-family: 'Inter Tight', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.admin-cache-section-title:first-of-type { margin-top: 0; }
.admin-sqlite-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

@media (max-width: 768px) {
  .admin-cache-grid { grid-template-columns: 1fr; }
}

/* ---- Feedback Tab ---- */
.admin-feedback-table { table-layout: fixed; }
.admin-feedback-table thead th:nth-child(1) { width: 50px; }   /* ID */
.admin-feedback-table thead th:nth-child(2) { width: 110px; }  /* Username */
.admin-feedback-table thead th:nth-child(3) { width: 160px; }  /* Email */
.admin-feedback-table thead th:nth-child(4) { width: 130px; }  /* Type */
.admin-feedback-table thead th:nth-child(5) { width: 150px; }  /* Subject */
.admin-feedback-table thead th:nth-child(6) { width: auto; }   /* Description */
.admin-feedback-table thead th:nth-child(7) { width: 140px; }  /* Submitted At */
.admin-feedback-table thead th:nth-child(8) { width: 120px; }  /* Status */

.fb-col-id {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  color: var(--text-faint);
}
.fb-col-user { font-weight: 600; white-space: nowrap; }
.fb-col-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fb-col-subject {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
  cursor: pointer;
}
.fb-col-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
  cursor: pointer;
}

/* Hover tooltips for truncated feedback cells */
.fb-col-subject:hover::after,
.fb-col-desc:hover::after {
  content: attr(data-full-text);
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 1000;
  background: #1e1e24;
  border: 1px solid #3a3a42;
  border-radius: 6px;
  padding: 10px 14px;
  color: #e0e0e0;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  max-width: 400px;
  min-width: 200px;
  white-space: normal;
  word-wrap: break-word;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  pointer-events: none;
}
.fb-col-desc:hover::after {
  left: auto;
  right: 0;
}
.fb-col-date {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
}
.fb-type-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--accent-bg);
  color: var(--accent);
  white-space: nowrap;
}
.fb-status-select {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s;
  appearance: auto;
}
.fb-status-select:focus {
  border-color: var(--accent);
  outline: none;
}
.fb-status-select.fb-status-open {
  color: #F59E0B;
  border-color: rgba(245,158,11,0.3);
}
.fb-status-select.fb-status-progress {
  color: var(--accent);
  border-color: rgba(79,152,163,0.3);
}
.fb-status-select.fb-status-resolved {
  color: var(--up);
  border-color: rgba(14,179,91,0.3);
}

/* Expandable feedback rows */
.admin-feedback-table tbody tr {
  cursor: pointer;
}

.admin-feedback-table tbody tr:hover {
  background: rgba(79, 152, 163, 0.05);
}

.admin-feedback-table tbody tr.fb-expanded {
  background: rgba(79, 152, 163, 0.08);
}

.fb-expand-row td {
  padding: 0 !important;
  border-top: none !important;
}

.fb-expand-row:hover {
  background: none !important;
  cursor: default;
}

.fb-expand-content {
  padding: 12px 16px 16px;
  background: var(--bg-tertiary, #222226);
  border-radius: 0 0 6px 6px;
  margin: 0 8px 8px;
  animation: fbExpandIn 0.2s ease;
}

@keyframes fbExpandIn {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 300px; }
}

.fb-expand-field {
  margin-bottom: 10px;
}

.fb-expand-field:last-child {
  margin-bottom: 0;
}

.fb-expand-label {
  display: block;
  font-size: 11px;
  color: #8a8f98;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.fb-expand-text {
  display: block;
  color: #e0e0e0;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* === Cron Jobs + MI Rank Section === */
.admin-cron-section {
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--card-bg, #1a1c1e);
  border: 1px solid rgba(79,152,163,0.12);
  border-radius: 10px;
}
.cron-uptime {
  font-size: 12px;
  color: #b0bec5;
  margin-bottom: 12px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.cron-uptime strong {
  color: var(--accent, #4F98A3);
}
.cron-table {
  margin-bottom: 16px;
}
.cron-table th:first-child,
.cron-table td:first-child {
  width: 180px;
}
.status-dot.grey {
  background: #555;
}
.status-label.pending {
  color: #b0bec5;
}
/* Cron Trigger Buttons */
.cron-trigger-btn {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: rgba(79,152,163,0.1);
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.cron-trigger-btn:hover:not(:disabled) {
  background: rgba(79,152,163,0.25);
}
.cron-trigger-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}
.cron-trigger-btn.running {
  border-color: #F59E0B;
  color: #F59E0B;
  background: rgba(245,158,11,0.1);
  animation: cron-pulse 1.5s ease-in-out infinite;
}
@keyframes cron-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}
.cron-trigger-btn.success {
  border-color: #22c55e;
  color: #22c55e;
  background: rgba(34,197,94,0.15);
}
.cron-trigger-btn.error {
  border-color: #C24A4A;
  color: #C24A4A;
  background: rgba(194,74,74,0.1);
}
.cron-trigger-na {
  color: var(--text-faint);
  font-size: 12px;
}

/* Uptime row + Yahoo crumb refresh tool */
.cron-uptime-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.cron-uptime-row .cron-uptime {
  margin-bottom: 0;
}
.cron-yahoo-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.et-diagnostic-wrap {
  position: relative;
  margin: 12px 0 16px;
}
.et-diagnostic-out {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  line-height: 1.5;
  color: #b0bec5;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border, #2a2f33);
  border-radius: var(--radius-sm, 6px);
  padding: 12px 14px;
  margin: 0;
  max-height: 520px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}
.et-diagnostic-copy-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-sm, 6px);
  border: 1px solid var(--accent, #4F98A3);
  background: rgba(79,152,163,0.15);
  color: var(--accent, #4F98A3);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.et-diagnostic-copy-btn:hover { background: rgba(79,152,163,0.25); }
.et-diagnostic-copy-btn.ok {
  border-color: #22c55e;
  color: #22c55e;
  background: rgba(34,197,94,0.12);
}
.et-diagnostic-copy-btn.err {
  border-color: #C24A4A;
  color: #C24A4A;
  background: rgba(194,74,74,0.12);
}
.yahoo-crumb-status {
  font-size: 11px;
  color: #b0bec5;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.yahoo-crumb-status .mono {
  color: var(--text-faint, #8a9299);
}
.yahoo-crumb-status .mono.ok {
  color: #22c55e;
}
.yahoo-crumb-status .mono.warn {
  color: #f59e0b;
}
.cron-yahoo-refresh-btn {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: rgba(79,152,163,0.1);
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.cron-yahoo-refresh-btn:hover:not(:disabled) {
  background: rgba(79,152,163,0.25);
}
.cron-yahoo-refresh-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}
.cron-yahoo-refresh-btn.ok {
  border-color: #22c55e;
  color: #22c55e;
  background: rgba(34,197,94,0.15);
}
.cron-yahoo-refresh-btn.err {
  border-color: #C24A4A;
  color: #C24A4A;
  background: rgba(194,74,74,0.1);
}

/* Overdue cron row — red tinted background with left border accent */
.cron-row-overdue {
  background: rgba(217, 18, 34, 0.08) !important;
  border-left: 3px solid #C24A4A;
}
.cron-row-overdue td {
  color: #ff6b6b;
}
.cron-row-overdue .feed-error.has-error {
  color: #C24A4A;
  font-weight: 600;
}

/* ---- Collapsible cron-job groups (e.g. Earnings Trade pipeline) ---- */
.cron-group-header {
  background: rgba(79, 152, 163, 0.10);
  border-top: 1px solid rgba(79, 152, 163, 0.30);
  border-bottom: 1px solid rgba(79, 152, 163, 0.30);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}
.cron-group-header:hover {
  background: rgba(79, 152, 163, 0.18);
}
.cron-group-header.collapsed {
  border-bottom: 1px solid rgba(42, 42, 48, 0.6);
}
.cron-group-header-cell {
  padding: 10px 14px !important;
  font-size: 13px;
}
.cron-group-chevron {
  display: inline-block;
  width: 22px;
  color: #4F98A3;
  font-size: 20px;
  line-height: 1;
  margin-right: 10px;
  vertical-align: middle;
  transition: transform 0.15s ease;
}
.cron-group-label {
  font-weight: 700;
  color: #e0e0e0;
  letter-spacing: 0.3px;
  margin-right: 8px;
}
.cron-group-count {
  display: inline-block;
  background: rgba(79, 152, 163, 0.20);
  color: #6cd4e0;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 12px;
}
.cron-group-desc {
  color: #b0bec5;
  font-size: 11px;
  font-weight: 400;
}
.cron-group-header-action {
  padding: 8px 12px !important;
  text-align: right;
}
.cron-group-header-action .cron-trigger-btn {
  background: rgba(79, 152, 163, 0.20);
  border: 1px solid rgba(79, 152, 163, 0.50);
  color: #6cd4e0;
  font-weight: 600;
}
.cron-group-header-action .cron-trigger-btn:hover:not(:disabled) {
  background: rgba(79, 152, 163, 0.35);
}

/* Rows inside a group indent slightly to show nesting */
.cron-row-grouped td.feed-name {
  padding-left: 28px !important;
  position: relative;
}
.cron-row-grouped td.feed-name::before {
  content: '\2514';  /* └ — tree branch */
  position: absolute;
  left: 14px;
  color: rgba(79, 152, 163, 0.5);
  font-weight: 400;
}

/* Hidden when group is collapsed */
.cron-row-hidden {
  display: none !important;
}

.cron-mirank-summary {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.cron-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent, #4F98A3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 10px 0;
}
.mirank-dist-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.mirank-dist-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid;
  border-radius: 6px;
  background: rgba(255,255,255,0.03);
}
.mirank-dist-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.mirank-dist-count {
  font-size: 14px;
  font-weight: 700;
  color: #e0ddd8;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.cron-mirank-meta {
  font-size: 11px;
  color: #5a5855;
  font-family: 'Inter', sans-serif;
}

/* === AI Feeds Tab ===
   Iter 7i — compact summary bars + color-coded per-row tints. Five rows are
   stacked: Calls (teal), Tokens (blue), Cost (green), AI Lab (purple),
   AI Social (amber). Each row has its own subtle background tint and a 3px
   left accent border so they're easy to distinguish at a glance on iPad. */
.ai-summary-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.ai-summary-bar:last-of-type { margin-bottom: 16px; }
.ai-summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 80px;
  flex: 1;
}
.ai-summary-value {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
}
.ai-summary-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
  text-align: center;
}
.ai-summary-health {
  font-size: 14px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 12px;
}
.ai-summary-health.ai-health-healthy {
  background: rgba(63,185,168,0.15);
  color: #3fb9a8;
}
.ai-summary-health.ai-health-degraded {
  background: rgba(245,158,11,0.15);
  color: #F59E0B;
}
.ai-summary-health.ai-health-error {
  background: rgba(194,74,74,0.15);
  color: #C24A4A;
}
.admin-aifeeds-table { table-layout: auto; width: 100%; }
.admin-aifeeds-table th,
.admin-aifeeds-table td {
  padding: 8px 6px;
  font-size: 0.8rem;
}
.admin-aifeeds-table .ai-num {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}
.admin-aifeeds-table .ai-model-cell {
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
}
.ai-schedule-cell {
  font-size: 0.75rem;
  color: var(--text-faint);
  white-space: nowrap;
}
.ai-health-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.ai-badge-healthy {
  background: rgba(63,185,168,0.15);
  color: #3fb9a8;
}
.ai-badge-degraded {
  background: rgba(245,158,11,0.15);
  color: #F59E0B;
}
.ai-badge-error {
  background: rgba(194,74,74,0.15);
  color: #C24A4A;
}
.ai-badge-token-limit {
  background: rgba(194,74,74,0.25);
  color: #C24A4A;
  font-weight: 700;
  border: 1px solid rgba(194,74,74,0.4);
}
@media (max-width: 768px) {
  .ai-summary-bar { gap: 8px; padding: 8px 10px; }
  .ai-summary-item { min-width: 64px; }
  .ai-summary-value { font-size: 15px; }
  .ai-summary-label { font-size: 9px; }
  .admin-aifeeds-table { font-size: 11px; }
}

/* === Source Summary Cards (Feeds Tab) === */
.source-summary-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.source-summary-card {
  flex: 1 1 130px;
  min-width: 120px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.source-summary-card.source-card-ok {
  border-color: rgba(14,179,91,0.25);
}
.source-summary-card.source-card-err {
  border-color: rgba(194,74,74,0.3);
  background: rgba(194,74,74,0.04);
}
.source-card-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}
.source-card-count {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.source-card-ok .source-card-count { color: var(--up); }
.source-card-err .source-card-count { color: var(--down); }
.source-card-icon {
  font-size: 14px;
  margin-left: 4px;
}

/* === Feed Requests Column === */
.feed-requests {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
}

/* === AI Token Summary Bar (legacy butting removed in Iter 7i;
   superseded by .ai-token-bar definition below with stronger tint) === */
.ai-token-value {
  color: var(--accent) !important;
  font-size: 17px !important;
}

/* === AI Cost Summary Bar === */
.ai-cost-bar {
  background: rgba(34,197,94,0.05);
  border-left-color: #22c55e;
}
/* AI Lab subtotal row — purple tint to distinguish from system-wide cost */
.ai-lab-bar {
  background: rgba(168,85,247,0.06);
  border-left-color: #a855f7;
}
/* AI Social subtotal row (Iter 7h) — amber tint */
.ai-social-bar {
  background: rgba(245,158,11,0.06);
  border-left-color: #f59e0b;
}
/* Calls row (default first .ai-summary-bar with no extra modifier) — teal */
.ai-summary-bar:not(.ai-token-bar):not(.ai-cost-bar):not(.ai-lab-bar):not(.ai-social-bar) {
  border-left-color: #3fb9a8;
  background: rgba(63,185,168,0.04);
}
/* Tokens row — ensure a stronger tint + accent border */
.ai-token-bar {
  border-left-color: var(--accent, #4f98a3);
  background: rgba(79,152,163,0.06);
}
.cost-value {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 700;
}
.cost-value.cost-low { color: #22c55e !important; }
.cost-value.cost-med { color: #f59e0b !important; }
.cost-value.cost-high { color: #C24A4A !important; }
.cost-cell {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  color: #22c55e;
}

/* Cost bar chart */
.ai-cost-chart-item {
  min-width: 200px !important;
  flex: 2 !important;
}
.cost-bar-wrap {
  margin-bottom: 6px;
}
.cost-bar-wrap:last-child { margin-bottom: 0; }
.cost-bar-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
  display: block;
  margin-bottom: 3px;
}
.cost-bar {
  display: flex;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: rgba(255,255,255,0.05);
}
.cost-bar-seg {
  height: 100%;
  min-width: 2px;
  transition: width 0.3s;
}
.cost-bar-empty {
  color: var(--text-faint);
  font-size: 10px;
  line-height: 10px;
  text-align: center;
  width: 100%;
}

/* === AI Model Distribution Column === */
.ai-model-dist {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === AI Last Run Timestamps === */
.ai-last-run {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  white-space: nowrap;
  cursor: default;
}
.ai-last-run.recent {
  color: #22c55e;
}
.ai-last-run.stale {
  color: #f59e0b;
}
.ai-last-run.overdue {
  color: #C24A4A;
}

/* === AI Activity Indicator === */
.ai-activity-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 13px;
}
.ai-activity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ai-activity-indicator.ai-activity-green .ai-activity-dot {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34,197,94,0.5);
}
.ai-activity-indicator.ai-activity-amber .ai-activity-dot {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245,158,11,0.5);
}
.ai-activity-indicator.ai-activity-red .ai-activity-dot {
  background: #C24A4A;
  box-shadow: 0 0 6px rgba(194,74,74,0.5);
}
.ai-activity-label {
  color: var(--text-muted);
  font-weight: 600;
}
.ai-activity-time {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 700;
}
.ai-activity-indicator.ai-activity-green .ai-activity-time { color: #22c55e; }
.ai-activity-indicator.ai-activity-amber .ai-activity-time { color: #f59e0b; }
.ai-activity-indicator.ai-activity-red .ai-activity-time { color: #C24A4A; }

/* === AI Efficiency Insights Panel === */
.ai-insights-panel {
  margin-top: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.ai-insights-title {
  font-family: 'Inter Tight', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.ai-insight-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  border-bottom: 1px solid rgba(42,42,48,0.3);
}
.ai-insight-row:last-child { border-bottom: none; }
.ai-insight-icon {
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1.5;
  width: 20px;
  text-align: center;
}
.ai-insight-row.insight-warn { color: #F59E0B; }
.ai-insight-row.insight-warn .ai-insight-icon { color: #F59E0B; }
.ai-insight-row.insight-info { color: var(--accent); }
.ai-insight-row.insight-info .ai-insight-icon { color: var(--accent); }
.ai-insight-row.insight-ok { color: var(--up); }
.ai-insight-row.insight-ok .ai-insight-icon { color: var(--up); }

/* === Feed Reliability Section === */
.reliability-section {
  margin-top: 20px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.reliability-table { margin-top: 10px; }
.uptime-badge {
  display: inline-block;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 10px;
}
.uptime-badge.uptime-green {
  background: rgba(34,197,94,0.15);
  color: #22c55e;
}
.uptime-badge.uptime-amber {
  background: rgba(245,158,11,0.15);
  color: #f59e0b;
}
.uptime-badge.uptime-red {
  background: rgba(194,74,74,0.15);
  color: #C24A4A;
}

/* ---- Error Log tab ---- */
.log-stats-bar {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.log-stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 100px;
}
.log-stat-value { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; font-size: 15px; font-weight: 700; color: var(--text); }
.log-stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }

.log-filter-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.log-filter-select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 10px; font-size: 12px; font-family: 'Inter', sans-serif; cursor: pointer; outline: none;
}
.log-filter-select:focus { border-color: var(--accent); }
.log-refresh-btn { margin-left: 0; }
.log-resolve-all-btn { background: rgba(194,74,74,0.12); color: #C24A4A; border: 1px solid rgba(194,74,74,0.25); font-size: 11px; padding: 5px 12px; border-radius: var(--radius-sm); cursor: pointer; }
.log-resolve-all-btn:hover { background: rgba(194,74,74,0.2); }

.log-live-indicator {
  display: flex; align-items: center; gap: 5px; margin-left: auto;
  font-size: 11px; color: var(--up); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.log-live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--up);
  animation: logPulse 1.5s ease-in-out infinite;
}
@keyframes logPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(14,179,91,0.5); }
  50% { opacity: 0.6; box-shadow: 0 0 6px 2px rgba(14,179,91,0.3); }
}

.error-log-table { font-size: 12px; }
.error-log-table td { vertical-align: top; padding: 8px 10px; }
.error-log-table .log-time { white-space: nowrap; color: var(--text-muted); font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; font-size: 11px; }
.error-log-table .log-source { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; font-size: 11px; color: var(--accent); }
.error-log-table .log-endpoint { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; font-size: 11px; color: var(--text-muted); max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.error-log-table .log-message { max-width: 280px; word-break: break-word; }

.log-level-badge {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 8px; border-radius: 10px; white-space: nowrap;
}
.log-level-badge.level-error { background: rgba(194,74,74,0.15); color: #C24A4A; }
.log-level-badge.level-warn  { background: rgba(245,158,11,0.15); color: #f59e0b; }
.log-level-badge.level-info  { background: rgba(59,130,246,0.15); color: #3b82f6; }
.log-level-badge.level-debug { background: rgba(107,114,128,0.15); color: #9ca3af; }

.log-details-toggle {
  background: var(--accent-bg); color: var(--accent); border: 1px solid rgba(79,152,163,0.3);
  border-radius: var(--radius-sm); padding: 2px 8px; font-size: 10px; cursor: pointer; font-family: inherit;
}
.log-details-toggle:hover { background: rgba(79,152,163,0.2); }

.log-details-panel {
  margin-top: 6px; padding: 8px 10px; background: #0d0d10; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; font-size: 11px;
  color: #a5d6ff; white-space: pre-wrap; word-break: break-all; max-height: 200px; overflow-y: auto;
}

.log-resolved { color: var(--up); font-size: 14px; cursor: default; }
.log-unresolved { color: #C24A4A; font-size: 14px; cursor: pointer; }
.log-unresolved:hover { color: #D87878; }

.error-log-date-group {
  margin-bottom: 4px;
}

.error-log-date-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface, #1c1c20);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.error-log-date-header:hover {
  background: #252529;
}

.date-toggle-icon {
  font-size: 0.7rem;
  color: #888;
  width: 12px;
}

.date-label {
  font-weight: 600;
  color: #e0e0e0;
  font-size: 0.85rem;
}

.date-stats {
  margin-left: auto;
  display: flex;
  gap: 12px;
  font-size: 0.72rem;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.date-error-count { color: #C24A4A; }
.date-warn-count { color: #f59e0b; }
.date-info-count { color: #60a5fa; }

.error-log-date-content {
  padding: 0 4px;
}

@media (max-width: 768px) {
  .source-summary-grid { gap: 6px; }
  .source-summary-card { min-width: 90px; padding: 8px 10px; }
  .source-card-count { font-size: 14px; }
  .ai-insights-panel { padding: 12px 14px; }
  .reliability-section { padding: 12px 14px; }
  .log-stats-bar { gap: 6px; }
  .log-stat-card { min-width: 80px; padding: 8px 10px; }
  .log-filter-bar { padding: 8px 10px; }
  .error-log-table .log-message { max-width: 150px; }
}

/* ============================================================
   Content Management — Upload
   ============================================================ */
.admin-content-upload {
  max-width: 680px;
}
.admin-upload-desc {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 20px;
}
.admin-upload-current {
  margin-bottom: 20px;
}
.admin-upload-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.admin-upload-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.admin-upload-preview img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.admin-upload-none {
  color: var(--text-faint);
  font-size: 12px;
  font-style: italic;
}
.admin-upload-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-faint);
}
.admin-upload-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.admin-upload-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 28px 20px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  transition: border-color 0.2s, background 0.2s;
}
.admin-upload-dropzone:hover,
.admin-upload-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(0,200,200,0.04);
}
.admin-upload-dropzone svg {
  color: var(--text-faint);
  opacity: 0.5;
}
.admin-upload-hint {
  font-size: 11px;
  color: var(--text-faint);
  opacity: 0.6;
}
.admin-upload-btn {
  align-self: flex-start;
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.admin-upload-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.admin-upload-btn:hover:not(:disabled) {
  opacity: 0.85;
}
.admin-upload-status {
  font-size: 12px;
  min-height: 18px;
}
.admin-upload-status.success { color: var(--up); }
.admin-upload-status.error { color: var(--down); }

/* ============================================================
   AI Prompts Library Tab
   ============================================================ */
.aip-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 18px;
  flex-wrap: wrap;
}
.aip-search {
  flex: 1 1 260px;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.aip-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.aip-filter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  cursor: pointer;
}
.aip-count {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: auto;
  white-space: nowrap;
}

.aip-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.aip-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.aip-item:hover {
  border-color: rgba(79, 152, 163, 0.4);
}
.aip-item.aip-open {
  border-color: var(--accent);
}

.aip-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}
.aip-chev {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s;
}
.aip-item.aip-open .aip-chev {
  transform: rotate(90deg);
  color: var(--accent);
}

.aip-title-wrap {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.aip-title {
  font-family: 'Inter Tight', 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.aip-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid rgba(79, 152, 163, 0.3);
  white-space: nowrap;
}
.aip-badge-status-live {
  background: rgba(14, 179, 91, 0.12);
  color: var(--up);
  border-color: rgba(14, 179, 91, 0.35);
}
.aip-badge-status-draft {
  background: rgba(255, 165, 0, 0.1);
  color: #ffa726;
  border-color: rgba(255, 165, 0, 0.3);
}

.aip-summary {
  flex: 0 0 100%;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 2px;
}

/* Expanded body */
.aip-body {
  border-top: 1px solid var(--border);
  padding: 14px 18px 18px;
  display: none;
}
.aip-item.aip-open .aip-body { display: block; }

.aip-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 18px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--border);
}
.aip-meta-item {
  font-size: 12px;
}
.aip-meta-label {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 3px;
}
.aip-meta-value {
  color: var(--text);
  font-family: 'Inter', sans-serif;
  word-break: break-word;
}
.aip-meta-value code {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.aip-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.aip-tag {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
}

.aip-prompt-block {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 48px 14px 14px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 520px;
  overflow-y: auto;
}

/* Header copy icon button (top-right of collapsed/expanded row) */
.aip-copy-icon-btn {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.aip-copy-icon-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}
.aip-copy-icon-btn.aip-copied {
  background: rgba(14, 179, 91, 0.15);
  color: var(--up);
  border-color: rgba(14, 179, 91, 0.4);
}
.aip-copy-icon-btn svg { width: 15px; height: 15px; }

/* Body copy button (full-width style with text label at bottom of expanded body) */
.aip-copy-btn {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.aip-copy-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}
.aip-copy-btn.aip-copied {
  background: rgba(14, 179, 91, 0.15);
  color: var(--up);
  border-color: rgba(14, 179, 91, 0.4);
}
.aip-copy-btn svg { width: 14px; height: 14px; }

/* Icon swap between copy + check (shared) */
.aip-copy-btn .aip-copy-icon-done,
.aip-copy-icon-btn .aip-copy-icon-done { display: none; }
.aip-copy-btn.aip-copied .aip-copy-icon-default,
.aip-copy-icon-btn.aip-copied .aip-copy-icon-default { display: none; }
.aip-copy-btn.aip-copied .aip-copy-icon-done,
.aip-copy-icon-btn.aip-copied .aip-copy-icon-done { display: inline-flex; }
.aip-copy-btn .aip-copy-icon-default,
.aip-copy-icon-btn .aip-copy-icon-default { display: inline-flex; }

.aip-empty {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* =================================================================
   Analytics tab
   ================================================================= */
.an-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 12px 0 20px;
}
.an-card {
  background: var(--bg-secondary, #1c1c20);
  border: 1px solid var(--border, #2a2a30);
  border-radius: 8px;
  padding: 14px 16px;
}
.an-card > h4 {
  margin: 0 0 10px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary, #a0a0a8);
}
.an-card-kpi {
  padding: 12px 14px;
}
.an-card-label {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted, #797876);
  margin-bottom: 4px;
}
.an-card-value {
  font-family: 'Inter Tight', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--text, #e0e0e0);
  letter-spacing: 0.01em;
}
.an-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 820px) {
  .an-row { grid-template-columns: 1fr; }
}
.an-table-wrap {
  max-height: 360px;
  overflow-y: auto;
}
.an-table-wrap table.admin-table {
  width: 100%;
  font-size: 12px;
}
.an-table-wrap table.admin-table code {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  color: var(--text-secondary, #a0a0a8);
}

/* AI Lab access toggle (Users table) */
.admin-toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  vertical-align: middle;
  cursor: pointer;
}
.admin-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.admin-toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.12);
  border-radius: 20px;
  transition: background 160ms ease;
}
.admin-toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #f5f5f7;
  border-radius: 50%;
  transition: transform 160ms ease;
}
.admin-toggle input:checked + .admin-toggle-slider {
  background: #4f98a3;
}
.admin-toggle input:checked + .admin-toggle-slider::before {
  transform: translateX(16px);
}
.admin-toggle input:disabled + .admin-toggle-slider {
  opacity: 0.5;
  cursor: not-allowed;
}
.admin-ailab-locked {
  display: inline-block;
  font-size: 11px;
  color: #8a8a9a;
  font-style: italic;
}

/* AI Lab admin: per-user caps + default-limits panel ----------------------- */
.admin-ailab-defaults {
  margin: 8px 0 16px 0;
  padding: 12px 14px;
  background: var(--bg-elevated, #1a1a1f);
  border: 1px solid var(--border, #2a2a32);
  border-radius: 10px;
}
.admin-ailab-defaults-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #f5f5f7);
  margin-bottom: 10px;
}
.admin-ailab-defaults-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}
.admin-ailab-defaults-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted, #8a8a9a);
}
.admin-ailab-defaults-row input {
  width: 160px;
  padding: 6px 8px;
  background: var(--bg, #0e0e12);
  color: var(--text, #f5f5f7);
  border: 1px solid var(--border, #2a2a32);
  border-radius: 6px;
  font-size: 12px;
}
.admin-ailab-defaults-row input:focus {
  outline: none;
  border-color: #4f98a3;
}
.admin-ailab-defaults-status {
  font-size: 11px;
  color: var(--text-muted, #8a8a9a);
}
.admin-ailab-defaults-status.is-ok    { color: #34d399; }
.admin-ailab-defaults-status.is-error { color: #D87878; }
.admin-ailab-defaults-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted, #8a8a9a);
}

/* ─── Iter 9o: split-panel layout with feature-flag toggle on the right ─── */
.admin-ailab-defaults--split {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 16px 24px;
  align-items: start;
}
.admin-ailab-defaults-col {
  min-width: 0;
}
.admin-ailab-defaults-col--feature {
  border-left: 1px solid rgba(255,255,255,0.06);
  padding-left: 24px;
}
@media (max-width: 900px) {
  .admin-ailab-defaults--split {
    grid-template-columns: 1fr;
  }
  .admin-ailab-defaults-col--feature {
    border-left: 0;
    padding-left: 0;
    border-top: 1px solid rgba(255,255,255,0.06);
    padding-top: 16px;
  }
}
.admin-ailab-defaults-row--toggle {
  flex-wrap: wrap;
}
.admin-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--text, #e6e6ec);
}
.admin-toggle-input {
  width: 16px;
  height: 16px;
  accent-color: #34d399;
  cursor: pointer;
  flex-shrink: 0;
}
.admin-toggle-input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.admin-toggle-text {
  line-height: 1.35;
}

/* Per-user cap inputs in the user table */
.admin-ailab-cap-input {
  width: 96px;
  padding: 4px 6px;
  background: var(--bg, #0e0e12);
  color: var(--text, #f5f5f7);
  border: 1px solid var(--border, #2a2a32);
  border-radius: 4px;
  font-size: 12px;
}
.admin-ailab-cap-input:focus {
  outline: none;
  border-color: #4f98a3;
}
.admin-ailab-cost-cell {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* === AI Sanity tab: explicit Inter sizing for title + body copy === */
#adminTabAisanity .admin-section-title {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 8px 0;
}
#adminTabAisanity .admin-section-sub,
#adminTabAisanity .admin-section-sub strong {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
