/* Forum Monitor — minimal, dependency-free stylesheet.
   Kept intentionally small; no CSS framework (footprint matters). */

:root {
  --bg: #0f1216;
  --surface: #181d24;
  --surface-2: #1f2630;
  --border: #616870;
  --text: #e7ecf2;
  --muted: #9aa6b2;
  --accent: #4f8cff;
  --accent-hover: #3f78e0;
  --danger: #ff6b6b;
  --danger-bg: #3a1d22;
  --success: #4ade80;
  --success-bg: #16301f;
  --radius: 10px;
  --maxw: 960px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700;
  color: var(--text);
  font-size: 1.1rem;
}
.nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

/* App shell: left sidebar + content */
.app-shell {
  display: flex;
  align-items: stretch;
}
.sidebar {
  flex: 0 0 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0.75rem;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: sticky;
  top: 1.5rem;
}
.side-nav a {
  color: var(--muted);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.95rem;
}
.side-nav a:hover {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}
.side-nav a.is-active {
  color: var(--text);
  background: var(--surface-2);
  font-weight: 600;
}

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}
.app-shell .container {
  flex: 1 1 auto;
  margin: 0;
}

/* Right rail for live background-task panels. Reserves no space when empty. */
.sidebar-right {
  flex: 0 0 560px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: 1.25rem 1rem;
}
.sidebar-right:empty {
  display: none;
}

/* Live discovery log — a small terminal-like console. */
.discovery-log {
  position: sticky;
  top: 1.5rem;
  font-size: 0.85rem;
}
.discovery-log__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.discovery-log__spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: discovery-spin 0.8s linear infinite;
  flex: 0 0 auto;
}
.discovery-log__spinner.is-done {
  border-color: var(--success);
  border-top-color: var(--success);
  animation: none;
}
@keyframes discovery-spin {
  to {
    transform: rotate(360deg);
  }
}
.discovery-log__lines {
  display: flex;
  flex-direction: column-reverse; /* newest line pinned to the bottom */
  list-style: none;
  margin: 0;
  padding: 0.6rem;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.logline {
  padding: 0.15rem 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}
.logline::before {
  margin-right: 0.4rem;
  color: var(--muted);
  content: "›";
}
.logline--ok {
  color: var(--text);
}
.logline--ok::before {
  content: "✓";
  color: var(--success);
}
.logline--drop::before {
  content: "✗";
  color: var(--danger);
}
.discovery-log__result {
  margin: 0.75rem 0 0.5rem;
  font-weight: 600;
  color: var(--success);
}
.discovery-log__result.is-error {
  color: var(--danger);
}

@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    flex-basis: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem;
  }
  .side-nav {
    flex-direction: row;
    flex-wrap: wrap;
    position: static;
  }
  .sidebar-right {
    flex-basis: auto;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .discovery-log {
    position: static;
  }
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 1rem;
}
.muted {
  color: var(--muted);
}
.text-small {
  font-size: 0.8rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 380px;
}
.form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="url"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
}
button:hover {
  background: var(--accent-hover);
}

button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover {
  background: var(--border);
}

.linklike {
  background: none;
  color: var(--muted);
  padding: 0;
  border: none;
}
.linklike:hover {
  color: var(--text);
  background: none;
  text-decoration: underline;
}
.logout-form {
  margin: 0;
}

.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 3rem;
}
.auth h1 {
  margin-bottom: 1.25rem;
}

.flash {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
}
.flash-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}
.flash-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success);
}

h2.card-title {
  font-size: 1.05rem;
  margin: 0 0 0.9rem;
}
.breadcrumb {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}
button.danger {
  background: var(--danger);
}
button.danger:hover {
  background: #e05555;
}
/* Link-style delete: red text, never a red fill (overrides button.danger). */
.linklike.danger,
.linklike.danger:hover {
  color: var(--danger);
  background: none;
}

/* Project list */
.project-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.75rem;
}
.project-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}
/* Pending-lead badge: a grey circle pinned to the card's top-right corner,
   sized for up to two digits. */
.pending-badge {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: #6b7280;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
}
.project-link {
  font-weight: 600;
  font-size: 1.05rem;
}
.project-desc {
  width: 100%;
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
}

/* Inline add form (phrases) */
.inline-form {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.inline-form input[type="text"] {
  flex: 1;
}
.inline-form button {
  white-space: nowrap;
}
/* Phrase form: widen the phrase text, keep the match-mode select compact. */
.phrase-form input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
}
.phrase-form select {
  flex: 0 0 auto;
  width: auto;
  min-width: 9.5rem;
}

/* Phrase list */
.phrase-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.phrase-list:empty::after {
  content: attr(data-empty);
  color: var(--muted);
  font-size: 0.9rem;
}
.phrase-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.phrase-row.inactive .phrase-text {
  color: var(--muted);
  text-decoration: line-through;
}
.phrase-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.badge {
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
  display: inline-block;
}

.project-settings {
  margin-top: 1.5rem;
}
.project-settings summary {
  cursor: pointer;
  color: var(--muted);
}
.project-settings summary:hover {
  color: var(--text);
}

/* Sources */
.source-form select {
  flex: 0 0 auto;
  width: auto;
}
.source-form input[type="url"] {
  flex: 2;
}
.source-form input[type="text"] {
  flex: 1;
}
.source-list {
  list-style: none;
  padding: 0;
  margin: 18px 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.source-list:empty::after {
  content: attr(data-empty);
  color: var(--muted);
  font-size: 0.9rem;
}
.source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.source-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  min-width: 0;
}
.source-url {
  overflow-wrap: anywhere;
}
.source-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  white-space: nowrap;
}
.type-badge {
  color: var(--text);
}
.block-reason {
  color: var(--danger);
  font-size: 0.82rem;
}
.source-row.status-ignored {
  opacity: 0.6;
}

/* Status badge colors */
.status-badge.status-active {
  color: #69d28a;
  border-color: #2f6b45;
}
.status-badge.status-pending {
  color: #e0b34f;
  border-color: #6b5a2f;
}
.status-badge.status-ignored {
  color: var(--muted);
}
.status-badge.status-needs_attention {
  color: var(--danger);
  border-color: var(--danger);
}

/* Project page head + scan */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.head-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.scan-form {
  margin: 0;
}

/* Source action buttons side by side */
.source-buttons {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}
.source-buttons form {
  margin: 0;
}

/* Lead pager */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.9rem;
}
.pager .muted {
  font-size: 0.85rem;
}

/* Result tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.tab {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
}
.tab:hover {
  background: var(--surface-2);
  color: var(--text);
}
.tab.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.strategy-badge {
  color: var(--muted);
}

/* Edit modal (phrases / sources) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.modal-overlay[hidden] {
  display: none;
}
.modal-title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}
.modal-form {
  max-width: none;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.modal-danger {
  margin: 1rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.field-hint {
  display: block;
  margin-top: -0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Match list */
.match-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.match-list:empty::after {
  content: attr(data-empty);
  color: var(--muted);
  font-size: 0.9rem;
}
.match-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.match-main {
  min-width: 0;
}
.match-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.match-meta {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}
.match-excerpt {
  margin: 0.45rem 0 0;
  font-size: 0.9rem;
  color: var(--text);
  overflow-wrap: anywhere;
}
.match-actions {
  display: flex;
  gap: 0.85rem;
  white-space: nowrap;
}

/* Project monitoring status dot (green = active, grey = paused). */
.status-dot {
  display: inline-block;
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: var(--muted);
  vertical-align: middle;
  margin-right: 0.1rem;
}
.status-dot.is-on {
  background: #36c08a;
}
.status-dot.is-off {
  background: var(--muted);
}
.project-meta {
  width: 100%;
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
}

/* Checkbox row in the project settings modal. */
/* Override .form label (column, centered) so the checkbox sits inline, left. */
.form .checkbox-label,
.checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  align-self: flex-start;
  justify-content: flex-start;
  gap: 0.5rem;
  font-size: 0.92rem;
  color: var(--text);
}
.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* Cron jobs table. */
.jobs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.jobs-table th,
.jobs-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.jobs-table th {
  color: var(--muted);
  font-weight: 600;
}
.job-empty-note {
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
  max-width: 16rem;
}
.badge-ok {
  color: #36c08a;
  border-color: #36c08a;
}
.badge-error {
  color: var(--danger);
  border-color: var(--danger);
}
.badge-running {
  color: var(--accent);
  border-color: var(--accent);
}
.job-error summary {
  cursor: pointer;
  list-style: none;
}
.job-error-text {
  margin: 0.4rem 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--danger);
  font-size: 0.8rem;
}

/* Backups: kebab (three-dots) action menu. */
.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}
.kebab {
  position: relative;
  display: inline-block;
}
.kebab > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.1rem 0.55rem;
  border-radius: 6px;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--muted);
  user-select: none;
}
.kebab > summary::-webkit-details-marker {
  display: none;
}
.kebab > summary:hover {
  background: var(--surface-2);
  color: var(--text);
}
.kebab-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  z-index: 50;
  min-width: 9rem;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  padding: 0.3rem;
}
.kebab-menu a,
.kebab-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}
.kebab-menu a:hover,
.kebab-menu button:hover {
  background: var(--surface-2);
}
.kebab-menu .danger {
  color: var(--danger);
}
