:root {
  /* Pinned to light - this page's colors are hand-picked for light mode
     only. "light dark" here would let the browser render native controls
     (buttons, selects) with dark-mode UA colors while our custom
     backgrounds stayed light, causing white-on-white text. */
  color-scheme: light;
  --bg: #f7f7f5;
  --card: #ffffff;
  --border: #e2e2df;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --accent: #2e8b57;
}

* { box-sizing: border-box; }

/* Leads/Settings/Users are genuinely separate pages (not a single-page
   app), so switching between them is a real navigation - this asks
   supporting browsers (Chromium-based, as of writing) to cross-fade
   between them automatically instead of a hard flash/reload. No JS, no
   restructuring, and it's a no-op (plain instant navigation, same as now)
   in browsers that don't support it yet - purely additive. */
@view-transition {
  navigation: auto;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
}

h1 {
  margin: 0;
  font-size: 18px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}

.user-bar button {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.main-nav {
  display: flex;
  gap: 4px;
}

.main-nav a {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  border: 1px solid transparent;
}

.main-nav a.active {
  color: var(--text);
  font-weight: 600;
  background: var(--bg);
  border-color: var(--border);
  border-bottom-color: var(--bg);
  margin-bottom: -1px;
}

.filters {
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.filters-status {
  display: flex;
  flex-wrap: wrap;
}

.filters button {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  margin-right: 8px;
  font-size: 13px;
}

.filters button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.sort-select-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.sort-select-label select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: var(--card);
}

main {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.reply-style-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 4px;
}

.reply-style-label select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  background: var(--card);
}

.post {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.post.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
  animation: highlight-fade 2.5s ease-out 1;
}

@keyframes highlight-fade {
  from { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 40%, transparent); }
  to { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
}

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

.title {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  flex: 1 1 auto;
}

.title:hover { text-decoration: underline; }

.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eee;
  color: var(--muted);
  white-space: nowrap;
}

.badge.promo.yes { background: #dff3e6; color: #1d6b3f; }
.badge.promo.no { background: #fdeeda; color: #96601b; }

.badge.lead-quality.lead-high { background: #dff3e6; color: #1d6b3f; }
.badge.lead-quality.lead-mid { background: #fdeeda; color: #96601b; }
.badge.lead-quality.lead-low { background: #eee; color: var(--muted); }

.summary, .angle {
  font-size: 14px;
  color: var(--muted);
  margin: 4px 0;
}

.professional-lead {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #f2b872;
  background: #fdeeda;
  border-radius: 8px;
}

.professional-lead-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #96601b;
  margin-bottom: 6px;
}

.professional-username {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.professional-note-text, .professional-action {
  font-size: 13px;
  color: #7a4d15;
  margin: 4px 0;
}

.professional-draft {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 14px;
  background: var(--card);
  border: 1px solid #f2b872;
  border-radius: 8px;
  padding: 10px;
  margin: 8px 0;
}

.copy-professional-draft {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #f2b872;
  background: var(--card);
  color: #96601b;
  cursor: pointer;
  font-size: 13px;
}

.draft {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin: 8px 0;
}

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

.actions button, .actions select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.updated-by {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

/* --- Activity panel --- */

#activity-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 100vw);
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
  z-index: 10;
  flex-direction: column;
}

/* An ID selector beats the browser's built-in [hidden]{display:none} rule,
   so "display: flex" above must NOT be unconditional - that was the actual
   bug (panel visible from page load, before any toggle click, hence always
   open and blank since loadActivity() had never been triggered yet). */
#activity-panel[hidden] {
  display: none;
}

#activity-panel:not([hidden]) {
  display: flex;
}

.activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.activity-header h2 {
  margin: 0;
  font-size: 15px;
}

#activity-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

#activity-list {
  list-style: none;
  margin: 0;
  padding: 8px 16px;
  overflow-y: auto;
}

#activity-list li {
  font-size: 13px;
  color: var(--text);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

#activity-list li a {
  color: var(--accent);
}

/* --- Login page --- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  width: min(360px, calc(100vw - 32px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}

.login-card h1 {
  font-size: 17px;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}

.login-error {
  background: #fdeeda;
  color: #96601b;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 16px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.login-card input {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
}

.login-card button {
  margin-top: 4px;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 14px;
  cursor: pointer;
}

/* --- Settings / Users pages --- */

.settings-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.settings-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
}

.settings-section h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

.settings-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 16px;
}

.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.add-form-wide {
  flex-wrap: wrap;
}

.add-form input {
  flex: 1 1 160px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
}

.add-form button {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.settings-error {
  background: #fdeeda;
  color: #96601b;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  margin: 0 0 12px;
}

.settings-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.settings-item:last-child {
  border-bottom: none;
}

.inactive-label {
  color: var(--muted);
  text-decoration: line-through;
}

.settings-item-controls {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.settings-item-controls button {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
}

.toggle-on {
  background: #dff3e6 !important;
  color: #1d6b3f !important;
  border-color: #dff3e6 !important;
}

.toggle-off {
  background: #f0f0ee !important;
  color: var(--muted) !important;
}

.remove-btn {
  color: #b3261e !important;
}

/* --- Monitor log page --- */

.log-main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 130px);
}

.log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
}

.log-autoscroll {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.log-output {
  flex: 1;
  overflow-y: auto;
  background: #1c1c1a;
  color: #e6e6e3;
  border-radius: 10px;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-output div {
  padding: 1px 0;
}

.log-line-success { color: #7fd99b; }
.log-line-flagged { color: #8fc9ff; }
.log-line-warn { color: #f2b872; }
