/* ── Reset ───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
ul { list-style: none; }
input, textarea, button { font: inherit; }

/* ── Tokens + light theme (default) ─────────── */
:root {
    color-scheme: light;
    --card-gap: 1rem;
    --radius: 10px;
    --radius-sm: 6px;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.02);
    --shadow-md: 0 4px 12px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
    --accent: #7c3aed;
    --accent-hover: #6d28d9;
    --accent-light: #ede9fe;
    --surface: #ffffff;
    --surface-hover: #fafafa;
    --bg: #f4f4f5;
    --border: #e4e4e7;
    --border-light: #f4f4f5;
    --border-hover: #d4d4d8;
    --text-primary: #18181b;
    --text-secondary: #52525b;
    --text-muted: #a1a1aa;
    --tag-bg: #f0fdfa;
    --tag-text: #0d9488;
    --tag-border: #99f6e4;
    --tag-bg-hover: #ccfbf1;
    --tag-border-hover: #5eead4;
    --tag-text-hover: #0f766e;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --success: #22c55e;
    --success-bg: #f0fdf4;
    --focus-ring: rgba(124,58,237,.12);
}

/* ── Dark theme override ────────────────────── */
[data-theme="dark"] {
    color-scheme: dark;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,.4), 0 1px 3px rgba(0,0,0,.25);
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --accent-light: rgba(167,139,250,.12);
    --surface: #18181b;
    --surface-hover: #202023;
    --bg: #09090b;
    --border: #27272a;
    --border-light: #1f1f22;
    --border-hover: #3f3f46;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --tag-bg: rgba(45,212,191,.1);
    --tag-text: #5eead4;
    --tag-border: rgba(45,212,191,.2);
    --tag-bg-hover: rgba(45,212,191,.18);
    --tag-border-hover: rgba(45,212,191,.35);
    --tag-text-hover: #99f6e4;
    --danger: #f87171;
    --danger-bg: rgba(239,68,68,.12);
    --success: #4ade80;
    --success-bg: rgba(34,197,94,.12);
    --focus-ring: rgba(167,139,250,.25);
}

/* ── Base ───────────────────────────────────── */
html, body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 15px;
}

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

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0.6rem 1.5rem;
    gap: 1rem;
}

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

.logo {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.search-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Theme toggle ───────────────────────────── */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.35rem;
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.icon-sun, .icon-moon { display: block; }
[data-theme="light"] .icon-sun,
[data-theme="dark"] .icon-moon { display: none; }

/* ── Search ─────────────────────────────────── */
.search-bar {
    width: 300px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.45rem 0.875rem;
    font-size: 0.8125rem;
    background: var(--bg);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.search-bar::placeholder { color: var(--text-muted); }

.search-bar:focus {
    background: var(--surface);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ── Sort select ───────────────────────────── */
.sort-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.35rem 1.75rem 0.35rem 0.5rem;
    font-size: 0.8125rem;
    background: var(--bg);
    color: var(--text-secondary);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.sort-select:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.sort-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ── Memory view (single) ──────────────────── */
.memory-view-layout {
    max-width: 700px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.memory-view-layout .memory-card .content {
    max-height: none;
}

/* ── Layout ─────────────────────────────────── */
.layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1.5rem;
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem;
}

@media (max-width: 768px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: static; max-height: none; }
    .search-bar { width: 180px; }
}

/* ── Sidebar ────────────────────────────────── */
.sidebar {
    position: sticky;
    top: 1.5rem;
    align-self: start;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem;
    box-shadow: var(--shadow-sm);
}

.sidebar ul {
    display: flex;
    flex-direction: column;
}

.sidebar li a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    white-space: nowrap;
    gap: 0.5rem;
    overflow: hidden;
}

.sidebar li a .tag-name {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.sidebar li a .tag-count {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--border-light);
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.sidebar li a:hover {
    background: var(--accent-light);
    color: var(--accent-hover);
}

.sidebar li a.active {
    background: var(--accent-light);
    color: var(--accent-hover);
    font-weight: 600;
}

.sidebar li a.active .tag-count {
    background: var(--accent);
    color: white;
}

/* ── Tag header ────────────────────────────── */
.tag-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.65rem;
    margin-bottom: 0.25rem;
}

.tag-all {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.15rem 0.35rem;
    transition: all 0.15s ease;
}

.tag-all:hover {
    background: var(--accent-light);
    color: var(--accent-hover);
}

.tag-all.active {
    color: var(--accent-hover);
    font-weight: 600;
}

.tag-all .tag-count {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--border-light);
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.tag-all.active .tag-count {
    background: var(--accent);
    color: white;
}

.tag-view-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease;
}

.tag-view-toggle:hover {
    color: var(--text-primary);
}

/* ── Tag cloud ─────────────────────────────── */
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.5rem;
    align-items: baseline;
    justify-content: center;
}

.tag-cloud a {
    display: inline-block;
    color: var(--tag-text);
    transition: all 0.15s ease;
    line-height: 1.4;
    padding: 0.1rem 0.25rem;
    border-radius: var(--radius-sm);
}

.tag-cloud a:hover {
    color: var(--accent-hover);
    background: var(--accent-light);
}

.tag-cloud a.active {
    color: var(--accent-hover);
    background: var(--accent-light);
    font-weight: 600;
}

.tag-cloud a[data-weight="1"] { font-size: 0.65rem; opacity: 0.65; }
.tag-cloud a[data-weight="2"] { font-size: 0.75rem; opacity: 0.75; }
.tag-cloud a[data-weight="3"] { font-size: 0.875rem; opacity: 0.85; }
.tag-cloud a[data-weight="4"] { font-size: 1.05rem; opacity: 0.95; }
.tag-cloud a[data-weight="5"] { font-size: 1.25rem; opacity: 1; }

/* ── Card grid ──────────────────────────────── */
#card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--card-gap);
    align-content: start;
}

/* ── Memory card ────────────────────────────── */
.memory-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.memory-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.memory-card .content {
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.9375rem;
    line-height: 1.65;
    color: var(--text-primary);
}

.memory-card .content.expanded {
    max-height: none;
}

/* ── Tags ───────────────────────────────────── */
.memory-card .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: auto;
    margin-bottom: 0.75rem;
    padding-top: 0.875rem;
}

.memory-card .tag,
.suggestion-card .tag {
    font-size: 0.7rem;
    padding: 0.2rem 0.55rem;
    border-radius: 99px;
    background: var(--tag-bg);
    color: var(--tag-text);
    border: 1px solid var(--tag-border);
    transition: all 0.15s ease;
    font-weight: 550;
    letter-spacing: 0.01em;
}

.memory-card .tag:hover,
.suggestion-card .tag:hover {
    background: var(--tag-bg-hover);
    border-color: var(--tag-border-hover);
    color: var(--tag-text-hover);
}

/* ── Actions row ────────────────────────────── */
.memory-card .actions {
    display: flex;
    gap: 0.375rem;
    align-items: center;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-light);
}

.memory-card .actions button {
    padding: 0.2rem 0.55rem;
    font-size: 0.7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    line-height: 1.5;
    font-weight: 450;
}

.memory-card .actions button:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

/* ── Vote buttons ───────────────────────────── */
.vote-section {
    display: inline-flex;
    gap: 0.15rem;
    align-items: center;
    margin-right: auto;
}

.vote-section button {
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 5px;
    font-size: 0.7rem;
    line-height: 1;
}

.vote-section button:first-child:hover {
    background: var(--success-bg);
    border-color: var(--success);
    color: var(--success);
}

.vote-section button:nth-of-type(2):hover {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
}

.vote-section .count {
    font-size: 0.7rem;
    min-width: 1.25rem;
    text-align: center;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.vote-flash .count {
    animation: flash 0.3s ease;
}

@keyframes flash {
    0% { color: var(--accent); transform: scale(1.3); }
    100% { color: var(--text-muted); transform: scale(1); }
}

/* ── Meta ───────────────────────────────────── */
.memory-card .meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    letter-spacing: 0.01em;
}


/* ── HTMX indicators ───────────────────────── */
.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator {
    opacity: 1;
}

.htmx-swapping {
    opacity: 0;
    transition: opacity 150ms ease-out;
}

/* ── Load more ──────────────────────────────── */
#load-more {
    grid-column: 1 / -1;
    text-align: center;
    padding: 0.5rem 0;
}

#load-more button {
    font-size: 0.8125rem;
    padding: 0.45rem 1.25rem;
    border-radius: var(--radius);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

#load-more button:hover {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Edit form ──────────────────────────────── */
.memory-card form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.memory-card form label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.memory-card form textarea,
.memory-card form input[type="text"] {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: var(--bg);
    color: var(--text-primary);
    outline: none;
}

.memory-card form textarea {
    padding: 0.75rem;
    resize: vertical;
    font-family: var(--font);
}

.memory-card form input[type="text"] {
    padding: 0.5rem 0.75rem;
}

.memory-card form textarea:focus,
.memory-card form input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.memory-card form .grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.memory-card form button[type="submit"] {
    background: var(--accent);
    color: white;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    transition: background 0.15s ease;
}

.memory-card form button[type="submit"]:hover {
    background: var(--accent-hover);
}

.memory-card form button[type="button"] {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    transition: all 0.15s ease;
}

.memory-card form button[type="button"]:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}
.login-card {
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    max-width: 400px;
    width: 100%;
}
.login-card h1 { margin: 0 0 1.5rem; text-align: center; }
.login-card input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-primary);
    font-family: inherit;
    box-sizing: border-box;
}
.login-card button {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    cursor: pointer;
    font-family: inherit;
}
.login-card button:hover { background: var(--accent-hover); }
.login-card .error { color: var(--danger); margin-top: 0.5rem; font-size: 0.8125rem; }
.admin-btn, .logout-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8125rem;
    text-decoration: none;
}
.admin-btn:hover, .logout-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.admin-badge {
    background: var(--accent);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}
.admin-nav { display: flex; gap: 0.5rem; }
.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}
.nav-link:hover { color: var(--text-primary); background: var(--surface-hover); }
.admin-main { max-width: 900px; margin: 0 auto; padding: 1.5rem; }
.admin-section h2 { margin: 0 0 1rem; }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.admin-inline-form { display: flex; gap: 0.5rem; align-items: center; }
.admin-inline-form input {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8125rem;
}
.admin-inline-form button {
    padding: 0.375rem 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8125rem;
    white-space: nowrap;
}
.admin-inline-form button:hover { background: var(--accent-hover); }
.admin-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: var(--surface);
}
.admin-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.admin-card-title { display: flex; align-items: center; gap: 0.5rem; }
.admin-card-actions { display: flex; gap: 0.375rem; }
.admin-card-meta { display: flex; gap: 1rem; margin-bottom: 0.75rem; }
.text-muted { color: var(--text-secondary); font-size: 0.8125rem; }
.admin-keys { border-top: 1px solid var(--border); padding-top: 0.75rem; }
.admin-keys-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.admin-key-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.375rem 0;
    font-size: 0.8125rem;
}
.admin-key-row code { color: var(--text-secondary); font-size: 0.75rem; }
.admin-empty { color: var(--text-secondary); font-style: italic; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.admin-table th { font-weight: 600; font-size: 0.8125rem; color: var(--text-secondary); }
.btn-sm {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.75rem;
}
.btn-sm:hover { background: var(--surface-hover); }
.btn-secondary { border-color: var(--border); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.input-sm {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.75rem;
}

/* Curation */

.curation-main {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.curation-main h1 {
    margin: 0 0 1.5rem;
    font-size: 1.5rem;
    color: var(--text-primary);
}

.curation-section {
    margin-bottom: 2rem;
}

.curation-section h2 {
    font-size: 1.1rem;
    margin: 0 0 0.75rem;
    color: var(--text-secondary);
}

.nav-link {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease, background 0.15s ease;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--surface);
}

.nav-link.active {
    color: var(--accent);
    font-weight: 600;
}

.curation-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

/* Curation indicator dot */

.curation-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    vertical-align: middle;
}

.curation-dot.idle {
    background: var(--text-muted);
    opacity: 0.4;
}

.curation-dot.active {
    background: var(--success);
    animation: curation-pulse 1.5s ease-in-out infinite;
}

.curation-dot.pending {
    background: var(--accent);
    width: auto;
    height: auto;
    padding: 0 0.3rem;
    font-size: 0.65rem;
    line-height: 1.2;
    color: #fff;
    font-weight: 600;
}

@keyframes curation-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Progress bar */

.curation-status {
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
}

.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.progress-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.last-run-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

/* Status badges */

.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-running { background: #dbeafe; color: #1e40af; }
.status-completed { background: #dcfce7; color: #166534; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-cancelled { background: #f3f4f6; color: #6b7280; }

[data-theme="dark"] .status-running { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .status-completed { background: #14532d; color: #86efac; }
[data-theme="dark"] .status-failed { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .status-cancelled { background: #374151; color: #9ca3af; }

/* Action badges */

.action-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.action-merge { background: #dbeafe; color: #1e40af; }
.action-update { background: #fef3c7; color: #92400e; }
.action-delete { background: #fee2e2; color: #991b1b; }
.action-retag { background: #e0e7ff; color: #3730a3; }

[data-theme="dark"] .action-merge { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .action-update { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .action-delete { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .action-retag { background: #312e81; color: #a5b4fc; }

/* Suggestion cards */

.suggestion-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.suggestion-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    transition: border-color 0.15s ease;
}

.suggestion-card:hover {
    border-color: var(--accent);
}

.suggestion-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.suggestion-reasoning {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.suggestion-sources, .suggestion-proposed {
    margin-bottom: 0.75rem;
}

.suggestion-sources h4, .suggestion-proposed h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 0.35rem;
    letter-spacing: 0.05em;
}

.source-memory {
    padding: 0.5rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 0.35rem;
}

.source-content {
    font-size: 0.8rem;
    color: var(--text-primary);
    white-space: pre-wrap;
    margin-bottom: 0.25rem;
}

.source-tags, .proposed-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.proposed-content {
    font-size: 0.85rem;
    color: var(--text-primary);
    white-space: pre-wrap;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 0.35rem;
}

.tag-added {
    background: #dcfce7 !important;
    color: #166534 !important;
    border-color: #86efac !important;
}

.tag-removed {
    background: #fee2e2 !important;
    color: #991b1b !important;
    border-color: #fca5a5 !important;
    text-decoration: line-through;
}

[data-theme="dark"] .tag-added {
    background: #14532d !important;
    color: #86efac !important;
    border-color: #166534 !important;
}

[data-theme="dark"] .tag-removed {
    background: #450a0a !important;
    color: #fca5a5 !important;
    border-color: #991b1b !important;
}

.suggestion-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.curation-error {
    color: var(--danger);
    font-size: 0.85rem;
    padding: 0.5rem;
}

.run-error {
    color: var(--danger);
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
}

/* Settings form */

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 600px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label, .form-group legend {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.model-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.model-row select {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.model-row select:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-check {
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    white-space: nowrap;
    min-width: 4.5rem;
    text-align: center;
}

.btn-check:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.btn-check:disabled {
    opacity: 1;
    cursor: default;
}

.btn-check-valid {
    background: var(--success, #22c55e);
    border-color: var(--success, #22c55e);
    color: #fff;
}

.btn-check-invalid {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.settings-form fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin: 0;
}

.settings-form legend {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0 0.35rem;
}

.schedule-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.day-checkboxes {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.day-check {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.day-check input[type="checkbox"] {
    appearance: none;
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--border-hover);
    border-radius: 3px;
    background: var(--bg);
    cursor: pointer;
    display: grid;
    place-content: center;
}

.day-check input[type="checkbox"]::after {
    content: "✓";
    font-size: 0.7rem;
    color: var(--accent);
    display: none;
}

.day-check input[type="checkbox"]:checked {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.day-check input[type="checkbox"]:checked::after {
    display: block;
}

.time-input {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8rem;
}

.time-input:focus {
    outline: none;
    border-color: var(--accent);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    appearance: none;
    width: 1.1rem;
    height: 1.1rem;
    border: 1px solid var(--border-hover);
    border-radius: 3px;
    background: var(--bg);
    cursor: pointer;
    display: grid;
    place-content: center;
    flex-shrink: 0;
}

.toggle-label input[type="checkbox"]::after {
    content: "✓";
    font-size: 0.75rem;
    color: var(--accent);
    display: none;
}

.toggle-label input[type="checkbox"]:checked {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.toggle-label input[type="checkbox"]:checked::after {
    display: block;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

/* Buttons */

.btn-primary {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-sm {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.btn-sm:hover {
    border-color: var(--text-muted);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
}
