:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --fg: #1c1e21;
  --muted: #65676b;
  --border: #e4e6eb;
  --primary: #1877f2;
  --primary-hover: #166fe5;
  --primary-soft: #e7f0ff;
  --danger: #e41e3f;
  --danger-soft: #ffe5ea;
  --success: #31a24c;
  --success-soft: #e3f5e7;
  --warning: #f5a623;
  --warning-soft: #fff4e0;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  width: 640px;
  min-height: 760px;
}

/* ===== Login screen ===== */

.login-screen {
  min-height: 760px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #e7f0ff 0%, #f7f8fa 100%);
}

/* Browser default `[hidden] { display: none }` is overridden by display: flex
   above. Re-assert it so toggling .hidden actually hides the login screen. */
.login-screen[hidden] { display: none !important; }

/* Section dividers inside cards — extend to full card width */
.card hr {
  margin-left: -18px;
  margin-right: -18px;
  width: calc(100% + 36px);
}

/* Tighter spacing for "h3 followed by descriptive paragraph" */
h3 + p.muted {
  margin-top: -8px;
  margin-bottom: 12px;
}

.login-box {
  width: 100%;
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
}

.login-box h1 {
  font-size: 18px;
  margin: 0 0 4px;
  text-align: center;
}

.login-box .muted {
  text-align: center;
  display: block;
  margin-bottom: 18px;
}

.login-submit {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  font-size: 13px;
}

.login-error {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
}

/* ===== Header ===== */

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand-row {
  display: flex;
  align-items: center;
  padding: 14px 18px 8px;
  gap: 10px;
}

h1 {
  font-size: 16px;
  margin: 0;
  flex: 1;
  font-weight: 600;
  letter-spacing: -0.2px;
}

h3 {
  font-size: 13px;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.pill.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.pill.warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.pill.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ── Self-test panel (shows on first open after install) ── */
.self-test {
  margin: 8px 0;
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(16,185,129,.08), rgba(16,185,129,.02));
  border: 1px solid rgba(16,185,129,.2);
  border-radius: 10px;
  font-size: 12px;
}
.self-test__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12.5px;
}
.self-test__title strong { flex: 1; }
.self-test__close {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--text-mute, #888);
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
}
.self-test__close:hover { background: rgba(255,255,255,.08); color: var(--text); }
.self-test__rows { display: flex; flex-direction: column; gap: 4px; }
.self-test__row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 11.5px;
}
.self-test__row .dot {
  font-size: 9px;
  width: 12px;
  text-align: center;
}
.self-test__row.ok .dot { color: var(--success, #10b981); }
.self-test__row.ok .dot::before { content: '✓'; }
.self-test__row.err .dot { color: var(--danger, #ef4444); }
.self-test__row.err .dot::before { content: '✗'; }
.self-test__row.warn .dot { color: var(--warning, #f59e0b); }
.self-test__row.warn .dot::before { content: '!'; }
.self-test__row .label { flex: 1; color: var(--text); }
.self-test__row .info { color: var(--text-mute, #888); font-family: var(--mono, monospace); font-size: 10.5px; }
.self-test__row.err .info { color: var(--danger, #ef4444); }

/* Dashboard */

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 10px 18px 16px;
}

.stat {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform .12s ease, box-shadow .12s ease;
}
.stat:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.stat b {
  font-size: 22px;
  font-weight: 600;
  color: var(--primary);
}
.stat span {
  font-size: 11px;
  color: var(--muted);
}

/* Tabs */

/* Tabs — segmented-control style. Active = full color fill, not underline. */
.tabs {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 6px;
  gap: 4px;
}
.tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  font-family: inherit;
  font-weight: 500;
  text-align: center;
  transition: color .18s ease, background .18s ease, transform .12s ease;
  position: relative;
}
.tab:hover {
  color: var(--fg);
  background: var(--bg);
}
.tab:active {
  transform: scale(.97);
}
.tab.active {
  color: #fff;
  background: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 2px 6px rgba(24,119,242,.22);
  animation: tabFill .22s ease;
}

/* 🤖 AI — the hero feature. Stands out even when inactive. */
.tab--ai {
  color: #fff;
  background: linear-gradient(135deg, #7c3aed, #10b981);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(124,58,237,.35);
  animation: aiPulse 2.4s ease-in-out infinite;
}
.tab--ai:hover {
  color: #fff;
  background: linear-gradient(135deg, #6d28d9, #059669);
  transform: translateY(-1px);
}
.tab--ai.active {
  background: linear-gradient(135deg, #6d28d9, #059669);
  animation: none;
  box-shadow: 0 2px 10px rgba(124,58,237,.5);
}
@keyframes aiPulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(124,58,237,.35); }
  50%      { box-shadow: 0 2px 14px rgba(16,185,129,.6); }
}
.tab.active:hover {
  /* Don't lighten on hover when already active — keeps the solid fill */
  background: var(--primary);
  color: #fff;
}
@keyframes tabFill {
  from { transform: scale(.92); opacity: .7; }
  to { transform: scale(1); opacity: 1; }
}

/* ===== Main ===== */

main {
  padding: 20px 18px;
}
.tab-panel {
  display: none;
  animation: panelEnter .22s ease;
}
.tab-panel.active { display: block; }
@keyframes panelEnter {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s ease, border-color .15s ease;
}
.card:hover { border-color: #d8dadf; }
.card h3 {
  margin-bottom: 12px;
  font-size: 14px;
}

.card.help {
  background: var(--primary-soft);
  border-color: transparent;
}
.card.help p { margin: 4px 0; font-size: 12px; }

.card summary {
  cursor: pointer;
  margin: -12px;
  padding: 12px;
  user-select: none;
}
.card[open] summary { border-bottom: 1px solid var(--border); margin-bottom: 8px; }

/* Editor */

.editor {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 8px;
}

/* Rows + buttons */

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

.row.sticky-bottom {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 8px 0;
  margin-top: 12px;
  border-top: 1px solid var(--border);
  margin-bottom: 0;
}

button {
  padding: 9px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  position: relative;
  transition: background .12s, border-color .12s, transform .08s, box-shadow .12s;
  user-select: none;
}
button:hover { background: var(--bg); border-color: #b0b3b8; }
button:active:not(:disabled) {
  transform: scale(.96);
  box-shadow: 0 0 0 3px rgba(24, 119, 242, .15);
}
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(24, 119, 242, .25);
}
button:disabled { opacity: .55; cursor: not-allowed; }

/* Brief flash animation after click — visible confirmation that click registered */
button.flash { animation: btn-flash .35s ease-out; }
@keyframes btn-flash {
  0% { box-shadow: 0 0 0 0 rgba(24,119,242,.45); }
  100% { box-shadow: 0 0 0 12px rgba(24,119,242,0); }
}

/* Loading spinner inside button when async work is happening */
button.busy { color: transparent !important; pointer-events: none; }
button.busy::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--primary);
  animation: btn-spin .7s linear infinite;
}
button.primary.busy::after { color: white; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

button.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
button.primary:hover { background: var(--primary-hover); }
button.primary:active:not(:disabled) { background: #125dc4; }

button.danger {
  color: var(--danger);
  border-color: var(--danger-soft);
}
button.danger:hover { background: var(--danger-soft); }
button.danger:active:not(:disabled) { background: #fcd2d8; }

/* Inputs */

input, textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
textarea { resize: vertical; }

label {
  display: block;
  margin: 12px 0;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}
label input, label select, label textarea { margin-top: 5px; }
label.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
label.inline input { width: auto; margin: 0; }

.inline-pair {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-top: 3px;
}

/* Lists */

.list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  max-height: 480px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.list.compact { max-height: 320px; }
.list::-webkit-scrollbar { width: 8px; }
.list::-webkit-scrollbar-track { background: transparent; }
.list::-webkit-scrollbar-thumb { background: #d8dadf; border-radius: 4px; }
.list::-webkit-scrollbar-thumb:hover { background: #b0b3b8; }

.list li {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 12.5px;
  flex-wrap: wrap;
  transition: background .12s ease;
}
.list li:last-child { border-bottom: none; }
.list li:hover { background: var(--bg); }

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

/* Rich list items — multi-line layout */
.list .row-main {
  width: 100%;
  display: flex;
  gap: 8px;
  align-items: center;
}
.list .row-meta {
  width: 100%;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 11px;
}
.list .row-preview {
  width: 100%;
  color: var(--muted);
  font-size: 11px;
  background: var(--bg);
  padding: 6px 8px;
  border-radius: 6px;
  max-height: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  white-space: pre-wrap;
}
.list .row-preview.expanded { max-height: none; -webkit-line-clamp: unset; }
.list .row-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-inline-start: auto;
}

/* Group avatar thumbnail */
.group-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.group-avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 16px;
  flex-shrink: 0;
}

/* Restriction badges */
.badge.restr-low    { background: var(--success-soft); color: var(--success); }
.badge.restr-medium { background: var(--warning-soft); color: var(--warning); }
.badge.restr-high   { background: var(--danger-soft);  color: var(--danger); }

.muted { color: var(--muted); font-size: 11px; }

.badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg);
  font-weight: 500;
}
.badge.queued, .badge.draft { background: var(--warning-soft); color: var(--warning); }
.badge.running, .badge.active { background: var(--primary-soft); color: var(--primary); }
.badge.done { background: var(--success-soft); color: var(--success); }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.paused { background: var(--bg); color: var(--muted); }

code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

/* Media attachments */

.media-section {
  margin: 10px 0;
  padding: 10px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.thumbs:empty { display: none; }

.thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
}
.thumb img, .thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumb .remove {
  position: absolute;
  top: 2px;
  inset-inline-end: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.6);
  color: white;
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb .badge-sync {
  position: absolute;
  bottom: 2px;
  inset-inline-start: 2px;
  font-size: 8px;
  padding: 1px 4px;
  border-radius: 6px;
  background: rgba(255,255,255,.9);
  color: var(--muted);
}
.thumb .badge-sync.synced { color: var(--success); }

.media-btn {
  display: inline-block;
  padding: 6px 12px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.media-btn:hover { background: var(--primary); color: white; }

/* Empty state */

.list li.empty-state {
  flex-direction: column;
  text-align: center;
  padding: 24px 12px;
  color: var(--muted);
  gap: 6px;
}
.list li.empty-state .emoji { font-size: 28px; }

.stat-card {
  background: var(--panel, #f7f7f9);
  border: 1px solid var(--border, #e0e0e0);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}
.stat-card .stat-label {
  font-size: 11px;
  color: var(--muted, #888);
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text, #222);
}

/* ===== Context banner (top of popup, shows active platform) ===== */
.context-banner { margin: 8px 0; }
.ctx-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  background: linear-gradient(135deg, rgba(139,92,246,.10), rgba(20,184,166,.08));
  border: 1px solid rgba(139,92,246,.25);
}
.ctx-row--idle { opacity: .7; background: var(--panel, #f7f7f9); border-color: var(--border, #e0e0e0); }
.ctx-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted, #888);
  flex-shrink: 0;
}
.ctx-dot--live {
  background: #14B8A6;
  box-shadow: 0 0 0 3px rgba(20,184,166,.25);
  animation: ctxPulse 2.2s cubic-bezier(.22,.61,.36,1) infinite;
}
@keyframes ctxPulse {
  0%,100%{box-shadow: 0 0 0 3px rgba(20,184,166,.25);}
  50%{box-shadow: 0 0 0 5px rgba(20,184,166,.12);}
}
.ctx-emoji { font-size: 14px; flex-shrink: 0; }
.ctx-text { flex: 1; min-width: 0; }
.ctx-text strong { font-weight: 600; }
.ctx-hint { font-size: 10.5px; color: var(--muted, #888); }
.ctx-action {
  padding: 4px 10px;
  background: #0F172A;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
}
.ctx-action.ghost {
  background: transparent;
  color: var(--text, #222);
  border: 1px solid var(--border, #e0e0e0);
}
.ctx-action:hover { opacity: .88; }

/* ============ Settings 2-pane layout ============ */
.settings-layout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
/* Right (visually): vertical category nav */
.settings-nav {
  flex: 0 0 168px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 4px;
  border-radius: 8px;
  background: var(--bg-soft, #f5f5f7);
}
.settings-nav-btn {
  display: block;
  width: 100%;
  text-align: right;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg, #222);
  transition: background-color .12s ease, color .12s ease;
}
.settings-nav-btn:hover {
  background: var(--bg, #fff);
}
.settings-nav-btn.active {
  background: var(--accent, #4a90e2);
  color: #fff;
  font-weight: 600;
}
/* Left (visually): content area; only the active pane is rendered */
.settings-content {
  flex: 1 1 auto;
  min-width: 0;
}
.settings-pane {
  display: none;
}
.settings-pane.active {
  display: block;
}
