/* =============================================
   Chronica Admin Portal Styles
   Mirrors app design tokens (DM Sans, editorial colours)
============================================= */

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

:root {
  /* Fonts */
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans: 'DM Sans', system-ui, sans-serif;

  /* Colours (editorial palette) */
  --color-black:       #1A1A1A;
  --color-charcoal:    #2D2D2D;
  --color-warm-white:  #FDFBF7;
  --color-warm-grey:   #E8E6E1;
  --color-medium-grey: #A8A5A0;
  --color-bg-card:     #F5F3EF;
  --color-burgundy:    #8B2635;
  --color-forest:      #2C5F2D;
  --color-navy:        #1E3A5F;

  /* Spacing */
  --space-xs: 8px;
  --space-sm: 16px;
  --space-md: 24px;
  --space-lg: 32px;
  --space-xl: 48px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
}

html, body {
  height: 100%;
  background: var(--color-warm-white);
  color: var(--color-charcoal);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.admin-wrapper {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-md) var(--space-sm);
  /* Leave room for the fixed footer */
  padding-bottom: calc(var(--space-md) + 60px);
}

/* ---- Footer nav ---- */

.admin-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: rgba(253, 251, 247, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-warm-grey);
  display: flex;
  align-items: center;
  justify-content: center;
}

.admin-footer-home {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--color-charcoal);
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  padding: 8px 24px;
  border-radius: var(--radius-sm);
  transition: color 150ms ease;
}

.admin-footer-home:hover {
  color: var(--color-black);
}

/* ---- Header ---- */

.admin-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: var(--space-md);
  border-bottom: 2px solid var(--color-black);
  margin-bottom: var(--space-lg);
}

.admin-header-title {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 700;
  color: var(--color-black);
  letter-spacing: -0.5px;
}

.admin-header-sub {
  font-size: 13px;
  color: var(--color-medium-grey);
  margin-left: var(--space-xs);
}

.admin-signout-btn {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-medium-grey);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 150ms ease, background 150ms ease;
  text-decoration: none;
}

.admin-signout-btn:hover {
  color: var(--color-burgundy);
  background: rgba(139, 38, 53, 0.06);
}

/* ---- Section headings ---- */

.admin-section {
  margin-bottom: var(--space-xl);
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.admin-section-title {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--color-black);
}

/* ---- Add Publisher Form ---- */

.add-publisher-form {
  background: var(--color-bg-card);
  border: 1px solid var(--color-warm-grey);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

.form-row {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-medium-grey);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.label-optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}

.form-field input,
.form-field select {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--color-warm-grey);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--color-charcoal);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--color-charcoal);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

.form-field.name-field  { flex: 1 1 160px; min-width: 140px; }
.form-field.url-field   { flex: 3 1 280px; min-width: 200px; }
.form-field.cat-field   { flex: 1 1 180px; min-width: 160px; }
.form-field.type-field  { flex: 1 1 170px; min-width: 150px; }
.form-field.lang-field  { flex: 1 1 130px; min-width: 120px; }

/* Source URL input with the Discover probe button alongside */
.url-input-row {
  display: flex;
  gap: 8px;
}

.url-input-row input {
  flex: 1;
  min-width: 0;
}

.discover-btn {
  height: 42px;
  padding: 0 14px;
  background: #fff;
  color: var(--color-charcoal);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--color-warm-grey);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.discover-btn:hover:not(:disabled) {
  border-color: var(--color-charcoal);
  background: var(--color-bg-card);
}

.discover-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Source type badge shown before the URL in the publishers table */
.source-type-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.source-type-rss         { background: var(--color-warm-grey); color: var(--color-charcoal); }
.source-type-sitemap     { background: rgba(30, 58, 95, 0.12);  color: var(--color-navy); }
.source-type-google-news { background: rgba(44, 95, 45, 0.12);  color: var(--color-forest); }
/* Publisher has a live_index_url — refresh-live scans it for live blogs. */
.source-type-live        { background: rgba(139, 38, 53, 0.12); color: var(--color-burgundy, #8B2635); }

.form-submit-btn {
  height: 42px;
  padding: 0 var(--space-md);
  background: var(--color-black);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 150ms ease, transform 150ms ease;
  align-self: flex-end;
}

.form-submit-btn:hover { opacity: 0.85; }
.form-submit-btn:active { transform: scale(0.98); }
.form-submit-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.form-error {
  margin-top: var(--space-xs);
  font-size: 13px;
  color: var(--color-burgundy);
  display: none;
}

.form-error.visible { display: block; }

/* ---- Fetch All button ---- */

.fetch-all-btn {
  height: 38px;
  padding: 0 var(--space-sm);
  background: #fff;
  color: var(--color-charcoal);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--color-warm-grey);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.fetch-all-btn:hover {
  border-color: var(--color-charcoal);
  box-shadow: var(--shadow-sm);
}

.fetch-all-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.fetch-all-btn svg { flex-shrink: 0; }

/* ---- Publishers Table ---- */

.publishers-table-wrap {
  border: 1px solid var(--color-warm-grey);
  border-radius: var(--radius-md);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-sm);
}

.publishers-table {
  width: 100%;
  min-width: 920px; /* keep row actions usable; wrapper scrolls horizontally */
  border-collapse: collapse;
  font-size: 14px;
}

.publishers-table thead {
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-warm-grey);
}

.publishers-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-medium-grey);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.publishers-table td {
  padding: 12px 14px;
  vertical-align: middle;
  border-bottom: 1px solid var(--color-warm-grey);
}

.publishers-table tbody tr:last-child td {
  border-bottom: none;
}

.publishers-table tbody tr:hover {
  background: rgba(0,0,0,0.02);
}

.pub-name {
  font-weight: 600;
  color: var(--color-black);
}

.pub-url {
  font-size: 12px;
  color: var(--color-medium-grey);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pub-url a {
  color: inherit;
  text-decoration: none;
}

.pub-url a:hover { text-decoration: underline; }

/* Fetch-health badge (OK / n fails / Paused) — hover for the last error */
.health-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  cursor: default;
}

.health-ok {
  background: rgba(44, 95, 45, 0.12);
  color: var(--color-forest);
}

.health-warn {
  background: rgba(255, 107, 0, 0.14);
  color: #A65B00;
}

.health-paused {
  background: rgba(139, 38, 53, 0.12);
  color: var(--color-burgundy);
}

.pub-category {
  display: inline-block;
  padding: 3px 8px;
  background: var(--color-warm-grey);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-charcoal);
  white-space: nowrap;
}

.pub-last-fetched,
.pub-article-count {
  font-size: 13px;
  color: var(--color-medium-grey);
  white-space: nowrap;
}

.pub-article-count { font-variant-numeric: tabular-nums; }

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 40px;
  height: 22px;
  background: var(--color-warm-grey);
  border-radius: var(--radius-full);
  transition: background 200ms ease;
  position: relative;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 200ms ease;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--color-forest);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(18px);
}

/* Row action buttons */
.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-btn {
  height: 32px;
  padding: 0 10px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all 150ms ease;
  white-space: nowrap;
}

.action-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.edit-btn {
  background: #fff;
  color: var(--color-charcoal);
  border-color: var(--color-warm-grey);
}

.edit-btn:not(:disabled):hover {
  border-color: var(--color-charcoal);
  background: rgba(0,0,0,0.03);
}

/* Inline edit row */
.edit-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
  flex-wrap: wrap;
}

.edit-row-fields {
  display: flex;
  gap: var(--space-xs);
  flex: 1;
  flex-wrap: wrap;
  align-items: flex-end;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}

.edit-field-url { flex: 2 1 200px; }

.edit-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-medium-grey);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.edit-input,
.edit-select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--color-warm-grey);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--color-charcoal);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.edit-input:focus,
.edit-select:focus {
  border-color: var(--color-charcoal);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

.edit-row-actions {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  padding-bottom: 1px;
}

.save-btn {
  background: var(--color-black);
  color: #fff;
  border-color: var(--color-black);
}

.save-btn:not(:disabled):hover { opacity: 0.85; }

.cancel-btn {
  background: #fff;
  color: var(--color-charcoal);
  border-color: var(--color-warm-grey);
}

.cancel-btn:not(:disabled):hover {
  border-color: var(--color-charcoal);
}

.fetch-btn {
  background: #fff;
  color: var(--color-navy);
  border-color: var(--color-warm-grey);
}

.fetch-btn:not(:disabled):hover {
  border-color: var(--color-navy);
  background: rgba(30, 58, 95, 0.05);
}

.delete-btn {
  background: #fff;
  color: var(--color-burgundy);
  border-color: var(--color-warm-grey);
}

.delete-btn:not(:disabled):hover {
  border-color: var(--color-burgundy);
  background: rgba(139, 38, 53, 0.05);
}

/* Armed state: first click turned the button into "Confirm?" */
.delete-btn.delete-armed {
  background: var(--color-burgundy);
  color: #fff;
  border-color: var(--color-burgundy);
}

.delete-btn.delete-armed:not(:disabled):hover {
  background: var(--color-burgundy);
  opacity: 0.9;
}

/* Loading spinner on buttons */
.btn-loading::after {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-left: 6px;
}

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

/* ---- Empty state ---- */

.publishers-empty {
  padding: var(--space-lg);
  text-align: center;
  color: var(--color-medium-grey);
  font-size: 14px;
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  bottom: var(--space-md);
  right: var(--space-md);
  z-index: 9999;
  padding: 12px var(--space-sm);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 250ms ease, transform 250ms ease;
  pointer-events: none;
  max-width: 320px;
}

.toast.toast-success { background: var(--color-forest); }
.toast.toast-error   { background: var(--color-burgundy); }

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---- Auth redirect overlay ---- */

.auth-check {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: var(--space-sm);
  color: var(--color-medium-grey);
  font-size: 14px;
}

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

@media (max-width: 640px) {
  .form-row { flex-direction: column; }
  .form-field { width: 100% !important; }
  .publishers-table { min-width: 720px; }
  .publishers-table th:nth-child(5),
  .publishers-table td:nth-child(5),
  .publishers-table th:nth-child(6),
  .publishers-table td:nth-child(6) { display: none; }
}

/* =============================================
   Pipeline health panel
   ============================================= */

.health-banner {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.health-banner-ok {
  background: rgba(44, 95, 45, 0.08);
  color: var(--color-forest, #2C5F2D);
}

.health-banner-warning {
  background: rgba(212, 113, 26, 0.1);
  color: #8A4A0F;
}

.health-banner-critical {
  background: rgba(139, 38, 53, 0.1);
  color: var(--color-burgundy, #8B2635);
}

.health-banner-kind {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  opacity: 0.75;
}

.health-banner-detail {
  color: inherit;
  opacity: 0.85;
}

/* Secondary line under a publisher name: category, card style, access. */
.health-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--color-medium-grey, #A8A5A0);
}

.health-cell-ok   { color: var(--color-forest, #2C5F2D); font-weight: 600; }
.health-cell-warn { color: #8A4A0F; font-weight: 600; }
.health-cell-bad  { color: var(--color-burgundy, #8B2635); font-weight: 700; }

/* last_error used to be a title tooltip only, which meant nobody read it. */
.health-error {
  max-width: 260px;
  font-size: 11px;
  color: var(--color-medium-grey, #A8A5A0);
  word-break: break-word;
}
