/* ── Reset & tokens ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --indigo:      #4F46E5;
  --indigo-lt:   #EEF2FF;
  --indigo-mid:  #C7D2FE;
  --indigo-dk:   #3730A3;
  --indigo-text: #4F46E5;
  --violet:      #6366F1;
  --green:       #059669;
  --green-lt:    #D1FAE5;
  --green-text:  #059669;
  --amber:       #D97706;
  --amber-lt:    #FEF3C7;
  --red:         #DC2626;
  --red-lt:      #FEE2E2;
  --red-text:    #DC2626;
  --gray-50:     #F9FAFB;
  --gray-100:    #F3F4F6;
  --gray-200:    #E5E7EB;
  --gray-300:    #D1D5DB;
  --gray-400:    #9CA3AF;
  --gray-500:    #6B7280;
  --gray-600:    #4B5563;
  --gray-700:    #374151;
  --gray-900:    #111827;
  --white:       #FFFFFF;
  --surface:     #FFFFFF;
  --shadow-card:  0 1px 2px rgba(0,0,0,.03);
  --shadow-popup: 0 10px 30px rgba(0,0,0,.15);
  --shadow-login: 0 1px 3px rgba(0,0,0,.05);
  --overlay-bg:   rgba(17,24,39,.35);
  --spinner-track: rgba(255,255,255,.4);
  --radius:      12px;
  --radius-sm:   8px;
  --font:        'Inter', system-ui, -apple-system, sans-serif;
}

/* ── Dark mode — OS-driven by default, with a manual override ───────
   Same custom-property convention used across the KG Apps suite:
   every color lives on :root, and this block redefines the same names
   with a dark palette. The login screen is intentionally pinned back
   to the light palette (see body.login-body below), matching the
   Hub's own sign-in page, which never goes dark.

   A manual toggle (see common.js) sets data-theme="dark"/"light" on
   <html> to override the OS setting; :not([data-theme="light"]) lets
   an explicit light choice suppress the dark media query, and the
   :root[data-theme="dark"] block below applies dark regardless of OS
   when the user explicitly chose it. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --indigo-lt:   #1E1B4B;
    --indigo-mid:  #A5B4FC;
    --indigo-dk:   #C7D2FE;
    --indigo-text: #A5B4FC;
    --green-lt:    #052E22;
    --green-text:  #34D399;
    --amber-lt:    #3A2405;
    --red-lt:      #3F1212;
    --red-text:    #F87171;
    --gray-50:     #0B1220;
    --gray-100:    #1D2738;
    --gray-200:    #28344A;
    --gray-300:    #3B4A63;
    --gray-400:    #6B7A8F;
    --gray-500:    #8D9AAC;
    --gray-600:    #A7B2C2;
    --gray-700:    #C3CCD9;
    --gray-900:    #EEF1F5;
    --surface:     #151D2B;
    --shadow-card:  0 1px 2px rgba(0,0,0,.5);
    --shadow-popup: 0 10px 40px rgba(0,0,0,.6);
    --overlay-bg:   rgba(0,0,0,.55);
  }

  body.login-body {
    /* Sign-in stays in the light palette across the whole KG Apps
       suite even when the OS is in dark mode — same convention as
       the Hub's own login screen and the sibling apps. */
    --indigo-lt:   #EEF2FF;
    --indigo-mid:  #C7D2FE;
    --indigo-dk:   #3730A3;
    --indigo-text: #4F46E5;
    --green-lt:    #D1FAE5;
    --green-text:  #059669;
    --amber-lt:    #FEF3C7;
    --red-lt:      #FEE2E2;
    --red-text:    #DC2626;
    --gray-50:     #F9FAFB;
    --gray-100:    #F3F4F6;
    --gray-200:    #E5E7EB;
    --gray-300:    #D1D5DB;
    --gray-400:    #9CA3AF;
    --gray-500:    #6B7280;
    --gray-600:    #4B5563;
    --gray-700:    #374151;
    --gray-900:    #111827;
    --surface:     #FFFFFF;
    --shadow-card:  0 1px 2px rgba(0,0,0,.03);
    --shadow-popup: 0 10px 30px rgba(0,0,0,.15);
    --overlay-bg:   rgba(17,24,39,.35);
  }
}

/* Explicit override so the manual toggle works regardless of the OS setting */
:root[data-theme="dark"] {
  --indigo-lt:   #1E1B4B;
  --indigo-mid:  #A5B4FC;
  --indigo-dk:   #C7D2FE;
  --indigo-text: #A5B4FC;
  --green-lt:    #052E22;
  --green-text:  #34D399;
  --amber-lt:    #3A2405;
  --red-lt:      #3F1212;
  --red-text:    #F87171;
  --gray-50:     #0B1220;
  --gray-100:    #1D2738;
  --gray-200:    #28344A;
  --gray-300:    #3B4A63;
  --gray-400:    #6B7A8F;
  --gray-500:    #8D9AAC;
  --gray-600:    #A7B2C2;
  --gray-700:    #C3CCD9;
  --gray-900:    #EEF1F5;
  --surface:     #151D2B;
  --shadow-card:  0 1px 2px rgba(0,0,0,.5);
  --shadow-popup: 0 10px 40px rgba(0,0,0,.6);
  --overlay-bg:   rgba(0,0,0,.55);
}
html[data-theme="dark"] body.login-body {
  --indigo-lt:   #EEF2FF;
  --indigo-mid:  #C7D2FE;
  --indigo-dk:   #3730A3;
  --indigo-text: #4F46E5;
  --green-lt:    #D1FAE5;
  --green-text:  #059669;
  --amber-lt:    #FEF3C7;
  --red-lt:      #FEE2E2;
  --red-text:    #DC2626;
  --gray-50:     #F9FAFB;
  --gray-100:    #F3F4F6;
  --gray-200:    #E5E7EB;
  --gray-300:    #D1D5DB;
  --gray-400:    #9CA3AF;
  --gray-500:    #6B7280;
  --gray-600:    #4B5563;
  --gray-700:    #374151;
  --gray-900:    #111827;
  --surface:     #FFFFFF;
  --shadow-card:  0 1px 2px rgba(0,0,0,.03);
  --shadow-popup: 0 10px 30px rgba(0,0,0,.15);
  --overlay-bg:   rgba(17,24,39,.35);
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header / nav ───────────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.logo { display: flex; align-items: center; gap: 9px; }
.logo-text { font-weight: 700; font-size: .97rem; color: var(--gray-900); letter-spacing: -.01em; }

.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-link {
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-500);
  padding: 6px 12px;
  border-radius: 8px;
  text-decoration: none;
  transition: color .15s, background .15s;
}
.nav-link:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-link.active { color: var(--indigo-text); background: var(--indigo-lt); }

.nav-right { display: flex; align-items: center; gap: 14px; }
.nav-user { font-size: .82rem; color: var(--gray-500); }
.nav-logout {
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-600);
  background: var(--gray-100);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
}
.nav-logout:hover { background: var(--gray-200); }

.theme-toggle-btn {
  font-size: .9rem;
  line-height: 1;
  background: var(--gray-100);
  border: none;
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.theme-toggle-btn:hover { background: var(--gray-200); }

/* ── Page wrapper ───────────────────────────────────────────────── */
.page { flex: 1; padding: 28px 24px 56px; }
.page-inner { max-width: 1100px; margin: 0 auto; }
.page-title-block { margin-bottom: 20px; }
.page-title { font-size: 1.45rem; font-weight: 800; color: var(--gray-900); letter-spacing: -.025em; }
.page-sub { margin-top: 6px; font-size: .88rem; color: var(--gray-500); line-height: 1.6; max-width: 640px; }

/* ── Toolbar (filter / toggle / export) ─────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.toolbar-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.toolbar-label { font-size: .75rem; font-weight: 600; color: var(--gray-500); }
.toolbar-input {
  background: var(--surface);
  color: var(--gray-900);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: .85rem;
  font-family: var(--font);
  min-width: 220px;
}
.toolbar-input:focus { outline: 2px solid var(--indigo-mid); border-color: var(--indigo); }

.toggle-row { display: flex; align-items: center; gap: 8px; }
.toggle-row label { font-size: .85rem; color: var(--gray-700); cursor: pointer; }
.toggle-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--indigo); cursor: pointer; }

.btn {
  font-size: .82rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  color: var(--white);
  transition: filter .15s;
}
.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-success  { background: var(--green); }
.btn-warning  { background: var(--amber); }
.btn-secondary{ background: var(--violet); }
.btn-primary  { background: var(--indigo); }
.btn-neutral  { background: var(--gray-600); }

/* ── Feed cards ─────────────────────────────────────────────────── */
.feed-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}
.feed-card {
  background: var(--surface);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px 18px;
  flex: 1 1 380px;
  max-width: 460px;
  box-shadow: var(--shadow-card);
}
.feed-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.feed-name { font-size: 1.05rem; font-weight: 700; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.status-dot.active   { background: var(--green); }
.status-dot.inactive { background: var(--red); }

.feed-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: .82rem;
  color: var(--gray-600);
  margin-bottom: 8px;
}
.feed-source { font-weight: 700; }
.feed-source.virtual { color: var(--red-text); }
.icon-btn {
  border: none;
  background: var(--gray-100);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: .8rem;
}
.icon-btn:hover { background: var(--gray-200); }

.price-badge {
  display: inline-block;
  font-size: .78rem;
  font-weight: 700;
  color: var(--green-text);
  background: var(--green-lt);
  padding: 3px 9px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.feed-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: .8rem;
  color: var(--gray-600);
  margin-bottom: 12px;
}

.feed-note {
  font-size: .82rem;
  color: var(--gray-600);
  line-height: 1.6;
  margin-bottom: 10px;
}
.feed-note a { color: var(--indigo-text); }

.feed-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.feed-missing { color: var(--gray-400); font-size: .85rem; padding: 16px; }

/* ── Popup toast ────────────────────────────────────────────────── */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 90px;
  z-index: 50;
}
.popup-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-popup);
}
.popup-title { font-weight: 700; font-size: .95rem; margin-bottom: 6px; }
.popup-body { font-size: .85rem; color: var(--gray-600); line-height: 1.5; white-space: pre-line; }
.popup-close {
  margin-top: 14px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--white);
  background: var(--indigo);
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
}

.empty-state { color: var(--gray-400); font-size: .9rem; padding: 20px 0; }
.loading-state { color: var(--gray-500); font-size: .9rem; padding: 20px 0; }

/* ── Login page (shared with the rest of the KG app family) ───────── */
.login-body { background: var(--gray-50); align-items: center; justify-content: center; }
.login-page { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 32px 30px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-login);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-brand-name { font-weight: 700; font-size: 1rem; letter-spacing: -.01em; }
.login-title { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; margin-bottom: 4px; }
.login-sub { font-size: .85rem; color: var(--gray-500); margin-bottom: 20px; line-height: 1.5; }
.login-field { margin-bottom: 16px; }
.login-field label {
  display: block;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray-500);
  margin-bottom: 6px;
}
.login-input {
  background: var(--surface);
  color: var(--gray-900);
  width: 100%;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: .9rem;
  font-family: var(--font);
}
.login-input:focus { outline: 2px solid var(--indigo-mid); border-color: var(--indigo); }
.login-pw-wrap { position: relative; }
.login-eye-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 4px;
}
.login-submit {
  width: 100%;
  background: var(--indigo);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.login-submit:disabled { opacity: .7; cursor: not-allowed; }
.login-spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--spinner-track);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--red-lt);
  color: var(--red-text);
  font-size: .82rem;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 16px;
}
