/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Prevent author styles from overriding the hidden attribute */
[hidden] { display: none !important; }

:root {
  --bg:            #f0f2f5;
  --surface:       #ffffff;
  --surface-raised:#ffffff;
  --text:          #111827;
  --text-2:        #6b7280;
  --text-3:        #9ca3af;
  --border:        #e5e7eb;
  --border-focus:  #6366f1;
  --primary:       #6366f1;
  --primary-dark:  #4f46e5;
  --primary-tint:  #eef2ff;
  --danger:        #ef4444;
  --danger-tint:   #fef2f2;
  --success:       #22c55e;
  --radius-sm:     6px;
  --radius:        12px;
  --radius-lg:     16px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow:        0 4px 12px rgba(0,0,0,.08);
  --shadow-lg:     0 8px 30px rgba(0,0,0,.12);
  --sidebar-w:     228px;
  --header-h:      58px;
  --transition:    .15s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── Auth error (used inside login modal) ────────────────────── */
.auth-error {
  background: var(--danger-tint);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: .8375rem;
  margin-bottom: 14px;
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: .95rem;
  color: var(--primary);
  letter-spacing: -.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 2px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .8rem;
  color: var(--text-2);
  background: var(--bg);
  border-radius: 20px;
  padding: 4px 10px 4px 8px;
  max-width: 200px;
  overflow: hidden;
}

.user-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: .8375rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

.btn-icon-only {
  padding: 7px;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-2);
  font-size: .875rem;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-tint); color: var(--danger); }

#refresh-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Layout ─────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
}

.sidebar-section { margin-bottom: 24px; }

.sidebar-title {
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  padding: 0 8px;
  margin-bottom: 4px;
}

.filter-list { list-style: none; }

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .8375rem;
  color: var(--text);
  text-decoration: none;
  transition: background var(--transition);
  user-select: none;
  min-width: 0;
}
.filter-item:hover { background: var(--bg); }
.filter-item.active { background: var(--primary-tint); color: var(--primary); font-weight: 500; }
.filter-item.feed-error .filter-count { color: #d97706; }

.filter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.filter-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-count {
  font-size: .75rem;
  color: var(--text-3);
  flex-shrink: 0;
  min-width: 16px;
  text-align: right;
}
.filter-item.active .filter-count { color: var(--primary); opacity: .7; }

/* Mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 39;
}

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.mobile-menu-btn:hover { background: var(--bg); }

/* ── Main ────────────────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  padding: 20px 24px 40px;
}

/* ── Toolbar ─────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-left  { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.active-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 12px;
  background: var(--primary-tint);
  color: var(--primary);
  border-radius: 20px;
  font-size: .8125rem;
  font-weight: 500;
}
.active-badge button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--primary);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  opacity: .7;
}
.active-badge button:hover { opacity: 1; }

.status-text {
  font-size: .8125rem;
  color: var(--text-3);
  white-space: nowrap;
}

/* ── View toggle ─────────────────────────────────────────────── */
.view-toggle {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.view-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 30px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  transition: background var(--transition), color var(--transition);
}
.view-btn:first-child { border-right: 1.5px solid var(--border); }
.view-btn:hover { background: var(--bg); color: var(--text); }
.view-btn.active { background: var(--primary-tint); color: var(--primary); }

/* ── Masonry ─────────────────────────────────────────────────── */
.masonry {
  columns: 4 260px;
  column-gap: 16px;
}

/* ── List feed ───────────────────────────────────────────────── */
.list-feed {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.list-feed .card {
  width: 65%;
  flex-direction: row;
  align-items: stretch;
}

.list-feed .card-img {
  width: 180px;
  min-width: 180px;
  max-height: none;
  aspect-ratio: unset;
  object-fit: cover;
  flex-shrink: 0;
  border-radius: 0;
}

.list-feed .card-body {
  flex: 1;
  min-width: 0;
}

@media (max-width: 900px) {
  .list-feed .card { width: 85%; }
}

@media (max-width: 600px) {
  .list-feed .card {
    width: 100%;
    flex-direction: column;
  }
  .list-feed .card-img {
    width: 100%;
    min-width: unset;
    max-height: 200px;
    aspect-ratio: 16/9;
  }
}

/* ── Card ────────────────────────────────────────────────────── */
.card {
  break-inside: avoid;
  margin-bottom: 16px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  background: var(--surface);
  transition: box-shadow .2s, transform .2s;
  display: flex;
  flex-direction: column;
}
.card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.card-img {
  width: 100%;
  display: block;
  object-fit: cover;
  max-height: 220px;
}

.card-body {
  padding: 14px 16px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-feed-tag {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  opacity: .65;
  margin-bottom: 7px;
}

.card-title {
  font-size: .9125rem;
  font-weight: 600;
  line-height: 1.38;
  margin-bottom: 8px;
}

.card-excerpt {
  font-size: .8125rem;
  opacity: .75;
  line-height: 1.55;
  flex: 1;
  margin-bottom: 14px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .75rem;
  gap: 8px;
}

.card-date { opacity: .6; white-space: nowrap; }

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  font-weight: 600;
  font-size: .75rem;
  opacity: .85;
  white-space: nowrap;
  flex-shrink: 0;
}
.card-link:hover { opacity: 1; }

/* ── Skeleton loader ─────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position: 600px 0; }
}

.skeleton-card {
  break-inside: avoid;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.skeleton-line {
  border-radius: 4px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 600px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-2);
  grid-column: 1 / -1;
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h2 { font-size: 1.2rem; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p { margin-bottom: 20px; font-size: .9rem; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in .18s ease;
}
.modal-wide { max-width: 560px; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-title { font-size: 1.05rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 20px 24px; }

.modal-footer {
  padding: 14px 24px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

/* ── Form ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: .8375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-label-small {
  display: block;
  font-size: .8rem;
  color: var(--text-2);
  margin-bottom: 5px;
}
.required { color: var(--danger); }

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}
.form-input::placeholder { color: var(--text-3); }

.color-input {
  padding: 4px 6px;
  height: 42px;
  cursor: pointer;
}

.color-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.color-preview {
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  transition: background .15s, color .15s;
}
.color-preview-label {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  opacity: .65;
  margin-bottom: 5px;
}
.color-preview-title {
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.color-preview-excerpt {
  font-size: .8rem;
  opacity: .75;
}

.form-hint {
  font-size: .75rem;
  color: var(--text-3);
  margin-top: 5px;
}

/* ── Manage feeds list ───────────────────────────────────────── */
.feed-manage-list { list-style: none; }

.feed-manage-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.feed-manage-item:last-child { border-bottom: none; }

.feed-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.08);
}

.feed-info { flex: 1; min-width: 0; }
.feed-info-name {
  font-size: .875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feed-info-meta {
  font-size: .75rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.feed-info-cat {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  background: var(--primary-tint);
  color: var(--primary);
  border-radius: 4px;
  padding: 1px 6px;
  margin-top: 3px;
}

.feed-manage-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ── Toasts ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow);
  animation: toast-in .22s ease;
  pointer-events: auto;
}
.toast.success { background: #15803d; }
.toast.error   { background: var(--danger); }
.toast.info    { background: var(--primary); }
.toast.warning { background: #d97706; }

@keyframes toast-in {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .btn-label { display: none; }
  .masonry { columns: 3 220px; }
}

@media (max-width: 700px) {
  .mobile-menu-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    height: calc(100vh - var(--header-h));
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main { padding: 16px; }
  .masonry { columns: 2 180px; }

  .user-chip { display: none; }
}

@media (max-width: 480px) {
  .masonry { columns: 1; }
  .header { padding: 0 14px; }
  .modal { border-radius: var(--radius) var(--radius) 0 0; }
  .modal-overlay { align-items: flex-end; padding: 0; }

  .auth-card { padding: 28px 20px 24px; }
}
