/* ═══════════════════════════════════════════════
   base.css — shared design tokens, typography,
   layout primitives, buttons, forms, modals,
   and utility classes.

   Panel-specific styles live in:
     brief.css, sources.css, catalogue.css
   ═══════════════════════════════════════════════ */

/* ── Design tokens ── */
:root {
  --bg: #0e1117;
  --surface: #161b22;
  --surface-hover: #1c2129;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #484f58;
  --accent: #58a6ff;
  --positive: #3fb950;
  --negative: #f85149;
  --warning: #d29922;
  --radius: 8px;
}

/* ── Reset ── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  height: 100vh;
  overflow: hidden; /* page itself never scrolls — panels scroll internally */
  display: flex;
  flex-direction: column;
}

/* ── SPA shell ── */
#app {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 0; /* bottom padding handled by bottom-nav */
  flex: 1; /* fill remaining viewport height */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ── Shared header ── */
header {
  display: block;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  position: relative;
  padding: 0 5px;
}

/* Left section: newsy title + tagline */
.header-left {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}

/* Right section: nav links + controls */
.header-right {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  flex-shrink: 0;
}

header h1 {
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  flex-shrink: 0;
}

.tagline {
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  object-fit: contain;
  opacity: 0.92;
  z-index: 1;
}

.nav-link {
  color: var(--text);
  text-decoration: none;
}
.nav-link:hover {
  color: var(--accent);
}

.header-link {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.header-link:hover {
  color: var(--text);
}

.header-link.active {
  color: var(--accent);
}

/* ── Refresh button ── */
#refresh-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1.05rem;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#refresh-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
#refresh-btn.spinning {
  animation: spin-shrink 0.8s ease-in-out infinite;
}
@keyframes spin-shrink {
  0%   { transform: rotate(0deg)   scale(1); }
  50%  { transform: rotate(180deg) scale(0.65); }
  100% { transform: rotate(360deg) scale(1); }
}

.brief-age {
  font-size: 0.76rem;
  color: var(--text-dim);
  white-space: nowrap;
  opacity: 0.8;
  flex-shrink: 0;
}
.brief-age--stale {
  color: var(--accent, #e07b54);
  opacity: 1;
}

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  background: var(--surface);
  color: var(--text-muted);
}
.btn-secondary:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--text-muted); }

.btn-sm {
  padding: 4px 10px;
  font-size: 0.72rem;
}

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

.btn-danger-text { color: var(--negative); }
.btn-danger-text:hover { color: var(--negative); opacity: 0.8; }

/* ── Icon buttons ── */
.btn-icon {
  min-width: 28px;
  padding: 3px 7px;
  font-size: 0.68rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 5px;
}
.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.btn-icon-danger {
  min-width: 32px;
  padding: 4px 8px;
  color: var(--text-dim);
}
.btn-icon-danger:hover {
  color: var(--negative);
  background: rgba(248, 81, 73, 0.08);
  border-color: rgba(248, 81, 73, 0.2);
}

.btn-icon-curate:hover {
  color: var(--positive);
  background: rgba(63, 185, 80, 0.08);
}

/* ── Forms ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.panel h3 {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 12px;
  color: var(--text);
}

.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.form-or {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.8rem;
  flex: 1;
  min-width: 100px;
}

.input-wide { flex: 3; }

.input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row-actions {
  display: flex;
  gap: 8px;
}

.btn-add-confirm {
  flex: 2;
}

.form-row-actions .btn:not(.btn-add-confirm) {
  flex: 1;
}

.test-result {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.78rem;
  line-height: 1.5;
  font-family: monospace;
  white-space: pre-wrap;
}
.test-result.pass { background: rgba(63, 185, 80, 0.1); border: 1px solid var(--positive); color: var(--positive); }
.test-result.warn { background: rgba(210, 153, 34, 0.1); border: 1px solid var(--warning); color: var(--warning); }
.test-result.fail { background: rgba(248, 81, 73, 0.1); border: 1px solid var(--negative); color: var(--negative); }

/* ── Toolbar / filter row (shared between sources + catalogue) ── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: var(--radius);
}

.filter-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-right: 24px; /* gap before source-stats */
}

.filter-group select {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  font-size: 0.75rem;
  min-width: 120px; /* narrower than flex: 1 */
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.filter-group .input-search {
  flex: 2;
  min-width: 0;
}

/* ── Tags ── */
.tag {
  font-size: 0.65rem;
  padding: 1px 7px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.tag-category { border-color: var(--accent); color: var(--accent); }
.tag-country { border-color: var(--text-dim); }
.tag-language { border-color: var(--warning); color: var(--warning); }
.tag-curated { border-color: var(--positive); color: var(--positive); }
.tag-multi-src { border-color: var(--accent); color: var(--accent); opacity: 0.7; }

/* ── Verdict badge ── */
.verdict-badge {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.verdict-pass { background: rgba(63, 185, 80, 0.15); color: var(--positive); }
.verdict-warn { background: rgba(210, 153, 34, 0.15); color: var(--warning); }
.verdict-fail { background: rgba(248, 81, 73, 0.15); color: var(--negative); }
.verdict-untested { background: var(--bg); color: var(--text-dim); }

/* ── Test detail inline ── */
.test-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 8px;
  font-size: 0.68rem;
  color: var(--text-dim);
  padding-top: 2px;
}
.test-detail span {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  line-height: 1.25;
  max-width: 100%;
}

/* ── Diff / confirmation modals ── */
.diff-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.diff-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(640px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.diff-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.diff-modal-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.diff-close {
  font-size: 1.3rem;
  line-height: 1;
  padding: 2px 6px;
  color: var(--text-dim);
  background: transparent;
  border: none;
  cursor: pointer;
}

.diff-modal-body {
  overflow-y: auto;
  padding: 16px 20px;
  flex: 1;
}

.diff-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 14px 0 6px;
}
.diff-section-label:first-child { margin-top: 0; }

.diff-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 0.78rem;
  margin-bottom: 3px;
}

.diff-row-name {
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diff-row-detail {
  font-size: 0.7rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.diff-added    { background: rgba(63,185,80,0.10); color: var(--positive); }
.diff-removed  { background: rgba(248,81,73,0.10);  color: var(--negative); }
.diff-changed  { background: rgba(210,153,34,0.10); color: var(--warning); }
.diff-same     { color: var(--text-dim); }

.diff-prefix {
  font-weight: 700;
  font-size: 0.8rem;
  width: 14px;
  flex-shrink: 0;
}

.diff-empty {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
}

.diff-modal-footer {
  display: flex;
  gap: 18px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.diff-mode-toggle {
  display: flex;
  gap: 14px;
  font-size: 0.78rem;
  color: var(--text-dim);
  align-items: center;
}
.diff-mode-toggle label {
  display: flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
}
.diff-mode-toggle input[type="radio"] {
  accent-color: var(--accent);
}

.diff-footer-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

/* ── Status messages ── */
.status-message {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-dim);
  font-size: 0.95rem;
}
.status-message.error {
  color: var(--negative);
}

/* ── Footer ── */
footer {
  text-align: center;
  margin-top: 32px;
  padding: 24px 16px;
  border-top: 1px solid var(--border);
}
footer p {
  color: var(--text-dim);
  font-size: 0.85rem;
  font-style: italic;
}

/* ── Spinner ── */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.testing { animation: spin 0.8s linear infinite; display: inline-block; }

/* ── SPA panel viewport ── */
:root {
  --panel-gap: 12px;
}

.panel-viewport {
  overflow: hidden;
  width: 100%;
  flex: 1; /* fill all space between header and bottom-nav */
  min-height: 0;
  position: relative;
}

.panel-track {
  display: flex;
  column-gap: var(--panel-gap);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  height: 100%;
}

.panel-slide {
  flex: 0 0 100%;
  max-width: 100%;
  height: 100%;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding-bottom: 8px;
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
}

/* ── Pager dots ── */
.pager-dots {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 20px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 20px;
  transition: background 0.15s;
}

.pager-dots:hover {
  background: var(--surface-hover);
}

.pager-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.2s, transform 0.2s, width 0.2s;
  display: block;
}

.pager-dot.active {
  background: var(--accent);
  transform: scale(1.35);
  width: 14px;
  border-radius: 3px;
}

/* ── Bottom navigation bar ── */
.bottom-nav {
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  width: calc(100% - 48px);
  max-width: 480px;
  margin: 0 auto 6px;
  background: rgba(22, 27, 34, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(48, 54, 61, 0.7);
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35), 0 1px 0 rgba(255,255,255,0.04) inset;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  will-change: transform, opacity;
}

.bottom-nav.is-hidden {
  transform: translateY(calc(100% + 18px));
  opacity: 0;
  pointer-events: none;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 11px 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  border-radius: 13px;
  transition: color 0.15s, background 0.15s;
  position: relative;
}

.bottom-nav-item:hover {
  color: var(--text);
}

.bottom-nav-item.active {
  color: var(--accent);
  background: linear-gradient(
    160deg,
    rgba(88, 166, 255, 0.13) 0%,
    rgba(88, 166, 255, 0.05) 100%
  );
  box-shadow: inset 0 1px 0 rgba(88, 166, 255, 0.18);
}

.bottom-nav-label {
  position: relative;
  z-index: 1;
}

/* Active nav link highlight */
.header-link.active,
.nav-link.active {
  color: var(--accent);
}

.hidden {
  display: none !important;
}

/* ── Responsive base ── */
@media (max-width: 600px) {
  .bottom-nav { display: none; }
  .bottom-nav.is-peek { display: flex; }

  #app { padding: 16px 12px; }

  .header-row {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 8px;
    padding: 0 8px;
  }

  .header-left {
    gap: 4px;
  }
  .header-right {
    gap: 6px;
  }
  header h1 { font-size: 1.3rem; }
  .tagline { font-size: 0.74rem; }
  .header-logo {
    width: 32px;
    height: 32px;
  }
  .brief-age { font-size: 0.7rem; }
  #refresh-btn {
    width: 28px;
    height: 28px;
    font-size: 0.95rem;
  }

  .panel { padding: 12px 14px; }
  .form-row { flex-direction: column; gap: 8px; }
  .input, .input-wide { width: 100%; flex: unset; }
  .form-row-actions { flex-direction: row; }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .filter-group {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    margin-right: 0; /* remove gap on mobile */
  }
  .filter-group select { 
    flex: 1; 
    min-width: 0; 
    max-width: calc(33.33% - 4px); /* 3 per row on mobile */
  }

  .diff-modal-footer { flex-direction: column; gap: 12px; }
  .diff-mode-toggle { flex-direction: column; align-items: flex-start; gap: 8px; }
  .diff-footer-actions { margin-left: 0; width: 100%; }
  .diff-footer-actions .btn { flex: 1; }
}
