/* ---------- Reset + tokens ---------- */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-soft: #475569;
  --text-mute: #94a3b8;

  --sidebar-bg: #0f172a;
  --sidebar-surface: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-text-mute: #94a3b8;
  --sidebar-active-bg: #312e81;
  --sidebar-active-text: #ffffff;

  --primary: #6366f1;
  --primary-soft: #eef2ff;
  --primary-text: #4338ca;

  --cta: #e05d38;
  --cta-hover: #c84d2c;
  --success: #10b981;
  --success-soft: #d1fae5;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-soft: #fee2e2;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.06);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --sidebar-w: 240px;
  --topbar-h: 68px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
code, pre, .mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Layout ---------- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  z-index: 30;
  transition: transform 0.2s ease;
}
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.content {
  padding: 24px 32px 40px;
  flex: 1;
  max-width: 100%;
}
.footer {
  padding: 16px 32px;
  border-top: 1px solid var(--border);
  color: var(--text-mute);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  background: var(--surface);
}
.footer code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; color: var(--text-soft); }

/* ---------- Sidebar ---------- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px 24px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-mark {
  width: 38px; height: 38px;
  background: var(--primary);
  color: white;
  border-radius: 10px;
  display: grid; place-items: center;
}
.brand-name { color: white; font-weight: 700; font-size: 22px; letter-spacing: -0.02em; line-height: 1; }
.brand-sub { color: var(--sidebar-text-mute); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  position: relative;
}
.sidebar-nav a:hover {
  background: var(--sidebar-surface);
  color: white;
  text-decoration: none;
}
.sidebar-nav a.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}
.sidebar-nav a svg { opacity: 0.85; flex-shrink: 0; }
.sidebar-nav .badge {
  margin-left: auto;
  background: rgba(255,255,255,0.1);
  color: white;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.sidebar-nav .badge-accent { background: var(--cta); color: white; }

.portal-switcher {
  position: relative;
  margin-bottom: 14px;
}
.portal-current {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--sidebar-surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
}
.portal-current:hover {
  background: #273346;
  text-decoration: none;
  color: white;
}
.portal-current.portal-empty {
  border: 1px dashed rgba(255,255,255,0.2);
  background: transparent;
}
.portal-current-name {
  font-size: 13px;
  font-weight: 600;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}
.portal-current-blog {
  font-size: 11px;
  color: var(--sidebar-text-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
  margin-top: 1px;
}
.portal-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--sidebar-surface);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 24px rgba(0,0,0,0.4);
  padding: 4px;
  display: none;
  z-index: 50;
  max-height: 360px;
  overflow-y: auto;
}
.portal-menu.open { display: block; }
.portal-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
}
.portal-menu-item:hover {
  background: rgba(255,255,255,0.06);
  color: white;
  text-decoration: none;
}
.portal-menu-item.active { background: var(--sidebar-active-bg); color: white; }
.portal-menu-name { font-size: 13px; font-weight: 600; color: white; }
.portal-menu-blog { font-size: 11px; color: var(--sidebar-text-mute); margin-top: 1px; }
.portal-menu-manage {
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 4px;
  padding-top: 10px;
  color: var(--sidebar-text-mute);
  font-size: 12px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.run-status {
  background: var(--sidebar-surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.run-status-label { font-size: 10.5px; color: var(--sidebar-text-mute); text-transform: uppercase; letter-spacing: 0.04em; }
.run-status-value { font-size: 13px; color: white; font-weight: 500; margin-top: 2px; }

/* ---------- User menu ---------- */
.user-menu {
  position: relative;
  margin-top: 12px;
}
.user-current {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--sidebar-surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.user-current:hover {
  background: #273346;
  color: white;
}
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
.user-info {
  flex: 1;
  min-width: 0;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-team {
  font-size: 11px;
  color: var(--sidebar-text-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.user-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--sidebar-surface);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 24px rgba(0,0,0,0.4);
  padding: 4px;
  display: none;
  z-index: 50;
  max-height: 360px;
  overflow-y: auto;
}
.user-dropdown.open { display: block; }
.user-dropdown-header {
  font-size: 10.5px;
  color: var(--sidebar-text-mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px 4px;
}
.user-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  text-decoration: none;
}
.user-dropdown-item:hover {
  background: rgba(255,255,255,0.06);
  color: white;
  text-decoration: none;
}
.user-dropdown-item.active {
  background: var(--sidebar-active-bg);
  color: white;
}
.user-dropdown-sep {
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 4px 0;
}
.user-dropdown-danger {
  color: #fca5a5;
}
.user-dropdown-danger:hover {
  color: #fecaca;
  background: rgba(239,68,68,0.1);
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.page-title { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.page-sub { font-size: 13px; color: var(--text-soft); margin-top: 2px; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: all 0.1s ease;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--cta); color: white; border-color: var(--cta); }
.btn-primary:hover { background: var(--cta-hover); border-color: var(--cta-hover); color: white; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Cards / grids ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px 20px; }
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { margin: 0; font-size: 14px; font-weight: 600; }

.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Stat card ---------- */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-label { font-size: 12px; color: var(--text-soft); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 30px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }
.stat-delta { font-size: 12px; color: var(--text-mute); margin-top: 4px; }
.stat-accent::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
}
.stat-cta::before { background: var(--cta); }
.stat-success::before { background: var(--success); }
.stat-warn::before { background: var(--warning); }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.table th { background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-link { color: var(--text); font-weight: 500; }
.table-link:hover { color: var(--primary); }

/* Sortable table headers - whole header becomes a clickable link */
.th-sort {
  color: var(--text-soft);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 4px;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}
.th-sort:hover {
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
}
.th-sort.active {
  color: var(--primary);
  background: var(--primary-soft);
}
.sort-caret {
  font-size: 11px;
  opacity: 0.8;
}

/* ---------- Suggestion card ---------- */
.sugg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  transition: border-color 0.15s;
}
.sugg.is-approved { border-color: var(--success); background: linear-gradient(180deg, #f0fdf4 0%, white 30%); }
.sugg.is-rejected { opacity: 0.55; background: var(--surface-2); }
.sugg-meta { font-size: 11.5px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.sugg-target { font-weight: 600; font-size: 14px; margin: 0 0 8px; }
.sugg-target a { color: var(--text); }
.sugg-anchor {
  display: inline-block;
  background: var(--primary-soft);
  color: var(--primary-text);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 13px;
}
.sugg-context {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-left: 3px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.55;
}
.sugg-context mark { background: #fef08a; padding: 1px 3px; border-radius: 2px; color: var(--text); font-weight: 600; }
.sugg-score { font-size: 11px; color: var(--text-mute); margin-top: 8px; }
.sugg-actions { display: flex; flex-direction: column; gap: 6px; align-items: end; }

/* ---------- Toggle ---------- */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
}
.toggle input { opacity: 0; position: absolute; pointer-events: none; }
.toggle-track {
  width: 36px; height: 20px;
  background: var(--border-strong);
  border-radius: 999px;
  position: relative;
  transition: background 0.15s;
  margin-right: 8px;
}
.toggle-track::after {
  content: ''; position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-track { background: var(--success); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-soft);
}
.badge-primary { background: var(--primary-soft); color: var(--primary-text); }
.badge-success { background: var(--success-soft); color: #047857; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* ---------- Activity log ---------- */
.activity { display: flex; flex-direction: column; gap: 4px; }
.activity-item {
  display: flex;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.activity-item:hover { background: var(--surface-2); }
.activity-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  margin-top: 6px;
  flex-shrink: 0;
}
.activity-dot.kind-apply { background: var(--success); }
.activity-dot.kind-error { background: var(--danger); }
.activity-time { font-size: 11px; color: var(--text-mute); margin-top: 2px; }

/* ---------- Empty state ---------- */
.empty {
  padding: 60px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty h3 { margin: 0 0 8px; font-size: 16px; }
.empty p { margin: 0 0 16px; color: var(--text-soft); }
.empty-icon {
  width: 56px; height: 56px;
  margin: 0 auto 16px;
  background: var(--primary-soft);
  color: var(--primary-text);
  border-radius: 50%;
  display: grid; place-items: center;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96);
  transition: transform 0.15s;
}
.modal-backdrop.open .modal { transform: scale(1); }
.modal-header {
  padding: 18px 22px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 18px; color: var(--text-mute); }
.modal-body { padding: 20px 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  padding: 12px 16px;
  background: var(--surface);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  min-width: 240px;
  max-width: 360px;
  animation: toastIn 0.15s ease;
}
.toast.success { border-color: var(--success); }
.toast.danger { border-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.form-input, .form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13.5px;
  font-family: inherit;
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15); }
.form-help { font-size: 12px; color: var(--text-mute); margin-top: 4px; }
.radio-row { display: flex; gap: 12px; flex-wrap: wrap; }
.radio-card {
  flex: 1;
  min-width: 140px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  display: flex; gap: 8px; align-items: start;
}
.radio-card input { margin-top: 2px; }
.radio-card.checked { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- Mobile toggle ---------- */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px; left: 16px;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 25;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; --topbar-h: 60px; }
  .sidebar { transform: translateX(-100%); width: 260px; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .sidebar-toggle {
    display: flex;
    /* iOS notch safe-area support */
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    transition: opacity 0.18s, transform 0.18s;
  }
  /* Hide hamburger when sidebar is open so it doesn't overlap the brand mark */
  body:has(.sidebar.open) .sidebar-toggle {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-12px);
  }
  .sidebar-backdrop.open { display: block; }

  /* Topbar grows to fit content - page actions wrap to a second row below title */
  .topbar {
    height: auto;
    min-height: 60px;
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 12px 16px 12px 64px;
    gap: 8px;
  }
  .topbar-left {
    flex: 1 1 auto;
    min-width: 0;
  }
  .topbar-right {
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-start;
    width: 100%;
  }
  .topbar-right .btn {
    flex: 0 0 auto;
  }

  .content { padding: 16px; }
  .footer { padding: 16px; flex-direction: column; gap: 4px; text-align: center; }
  .page-title { font-size: 17px; line-height: 1.3; }
  .page-sub { font-size: 12px; }

  /* Sidebar brand respects iOS notch */
  .sidebar { padding-top: calc(20px + env(safe-area-inset-top, 0px)); }

  /* Suggestion cards stack on mobile */
  .sugg { grid-template-columns: 1fr; }
  .sugg-actions { flex-direction: row; align-items: center; justify-content: space-between; }

  /* Stat grids breathe better at mobile widths */
  .grid-stats { grid-template-columns: repeat(2, 1fr); }

  /* Wrapped tables get horizontal scroll on mobile. Title column gets
     dedicated room (so titles wrap at word boundaries, not character-by-
     character) and the long URL below the title gets ellipsis-truncated
     so it can't blow out the cell height. */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    overscroll-behavior-x: contain;
  }
  /* width: max-content sizes the table exactly to the sum of its column
     natural widths (driven by header text + the title column's min-width).
     No trailing blank space, still wider than viewport so horizontal scroll
     remains active inside the wrapper. */
  .table-wrap > .table { width: max-content; min-width: 100%; font-size: 13px; }
  .table-wrap > .table th {
    white-space: nowrap;
    padding: 12px 16px;
    font-size: 12px;
  }
  .table-wrap > .table td {
    /* break-word only kicks in when a long token (like a URL) has no
       other break-point - normal words/spaces still wrap at boundaries */
    overflow-wrap: break-word;
    padding: 14px 16px;
    vertical-align: top;
  }
  /* Title column gets meaningful width on mobile - enough for ~2 lines of
     a typical post title at the current font size */
  .table-wrap > .table td:first-child,
  .table-wrap > .table th:first-child { width: 340px; min-width: 340px; }
  /* URL display under title: truncate with ellipsis instead of breaking
     every 4 chars into its own line */
  .table-wrap > .table td:first-child .small a {
    display: inline-block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
  }

  /* GSC block actions stack below the label on mobile - no more 260px floor */
  .gsc-block-header { flex-wrap: wrap; }
  .gsc-actions {
    min-width: 0;
    width: 100%;
    margin-top: 8px;
    justify-content: flex-start;
  }
  .gsc-actions .btn-property,
  .gsc-actions .btn-disconnect,
  .gsc-actions .btn-connect { min-width: 0; }

  /* Portal row + its action area stack vertically so buttons no longer
     fight with the GSC block underneath. The "Switch to" placeholder
     spacer becomes useless on mobile - hide it. */
  .portal-row { flex-direction: column; gap: 14px; }
  .portal-row-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .switch-spacer { display: none; }

  /* Suggestion cards: prevent runaway titles + anchors from forcing the
     card wider than the viewport */
  .sugg { padding: 14px; }
  .sugg-target, .sugg-meta, .sugg-anchor, .sugg-context {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .sugg-meta { white-space: normal; }
  .sugg-context { font-size: 12.5px; }

  /* Cards get smaller padding */
  .card-pad { padding: 14px 16px; }
  .card-header { padding: 12px 16px; }
}

@media (max-width: 480px) {
  /* Even tighter on phones */
  .topbar { padding: 10px 12px 10px 56px; }
  .sidebar-toggle { width: 36px; height: 36px; }
  .content { padding: 12px; }
  .grid-stats { grid-template-columns: 1fr; }
  .page-title { font-size: 16px; }
}

/* ---------- Graph ---------- */
.graph-wrap {
  height: calc(100vh - var(--topbar-h) - 80px - 60px);
  min-height: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}
.graph-legend {
  position: absolute;
  top: 12px; right: 12px;
  background: rgba(255,255,255,0.95);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 4px;
}
.graph-legend-row { display: flex; align-items: center; gap: 8px; }
.graph-legend-dot { width: 12px; height: 3px; border-radius: 2px; }

/* ---------- Tooltips ---------- */
[data-tooltip] {
  position: relative;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--sidebar-bg);
  color: white;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  white-space: normal;
  width: max-content;
  max-width: 260px;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s;
  z-index: 80;
  box-shadow: var(--shadow-md);
}
[data-tooltip]::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  border: 5px solid transparent;
  border-top-color: var(--sidebar-bg);
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s;
  z-index: 80;
  pointer-events: none;
}
[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
[data-tooltip-side="bottom"]::after {
  bottom: auto;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-4px);
}
[data-tooltip-side="bottom"]::before {
  bottom: auto;
  top: 100%;
  border-top-color: transparent;
  border-bottom-color: var(--sidebar-bg);
  transform: translateX(-50%) translateY(-4px);
}

/* ---------- Misc ---------- */
.muted { color: var(--text-mute); }
.small { font-size: 12px; }
.flex { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.sticky-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 32px;
  margin: 24px -32px 0;
  display: flex; gap: 12px; align-items: center;
}
.log-stream {
  background: #0f172a;
  color: #d1d5db;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  max-height: 360px;
  overflow-y: auto;
  line-height: 1.55;
}
.log-stream .log-line { margin: 0; padding: 1px 0; }
.log-stream .log-line.error { color: #fca5a5; }
.log-stream .log-line.success { color: #6ee7b7; }
.log-stream .log-line.muted { color: #6b7280; }
