/* ── Reset & Tokens ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:          #f3f4f6;
    --surface:     #ffffff;
    --text:        #111827;
    --text-2:      #6b7280;
    --border:      #e5e7eb;
    --blue:        #3b82f6;
    --blue-dark:   #1d4ed8;
    --green:       #10b981;
    --green-dark:  #065f46;
    --amber:       #f59e0b;
    --amber-dark:  #92400e;
    --gray:        #9ca3af;
    --gray-dark:   #6b7280;
    --primary:     #2563eb;
    --primary-h:   #1d4ed8;
    --shadow-sm:   0 1px 2px rgba(0,0,0,.05);
    --shadow-md:   0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
    --radius:      8px;
    --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; }

/* ── Header ─────────────────────────────────────────────────────────── */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    position: sticky; top: 0; z-index: 100;
}
.header-inner {
    max-width: 1200px; margin: 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    height: 56px;
}
.header-brand h1 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
.header-subtitle { font-size: 12px; color: var(--text-2); margin-left: 8px; }
.header-actions { display: flex; align-items: center; gap: 12px; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 16px; border: none; border-radius: 6px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    font-family: var(--font); transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary svg { flex-shrink: 0; }

/* ── Scan status ────────────────────────────────────────────────────── */
.scan-status {
    font-size: 12px; color: var(--text-2);
    transition: opacity .3s;
}
.scan-status.scan-done { color: var(--green-dark); font-weight: 500; }
.scan-status.scanning { color: var(--blue); }

/* ── Main ───────────────────────────────────────────────────────────── */
.app-main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 40px; }

/* ── Stats bar ──────────────────────────────────────────────────────── */
.stats { display: flex; gap: 12px; margin-bottom: 20px; }
.stat-item {
    background: var(--surface); border-radius: var(--radius);
    padding: 14px 20px; flex: 1; text-align: center;
    box-shadow: var(--shadow-sm); border-top: 3px solid transparent;
    transition: transform .15s;
}
.stat-item:hover { transform: translateY(-1px); }
.stat-count { display: block; font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat-label {
    display: block; font-size: 11px; text-transform: uppercase;
    letter-spacing: .06em; color: var(--text-2); margin-top: 2px;
}
.stat-new        { border-top-color: var(--blue); }
.stat-new .stat-count { color: var(--blue); }
.stat-approved   { border-top-color: var(--green); }
.stat-approved .stat-count { color: var(--green); }
.stat-approved-waiting { border-top-color: #ea580c; }
.stat-approved-waiting .stat-count { color: #ea580c; }
.stat-sent       { border-top-color: #8b5cf6; }
.stat-sent .stat-count { color: #8b5cf6; }
.stat-unknown    { border-top-color: var(--amber); }
.stat-unknown .stat-count { color: var(--amber); }
.stat-cleared    { border-top-color: var(--gray); }
.stat-cleared .stat-count { color: var(--gray); }

/* ── Filter bar ─────────────────────────────────────────────────────── */
.filter-bar {
    background: var(--surface); border-radius: var(--radius);
    padding: 10px 14px; margin-bottom: 16px; box-shadow: var(--shadow-sm);
}
.filter-row-top {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
}
.status-tabs { display: flex; gap: 3px; }
.tab {
    padding: 5px 13px; border: none; background: transparent;
    border-radius: 6px; font-size: 13px; font-weight: 500;
    cursor: pointer; color: var(--text-2); font-family: var(--font);
    transition: all .15s;
}
.tab:hover { background: var(--bg); color: var(--text); }
.tab.active { background: var(--primary); color: #fff; }
.search-filters { display: flex; gap: 8px; align-items: center; }
.search-filters input {
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; font-family: var(--font); color: var(--text);
    transition: border-color .15s;
}
.search-filters input:focus,
.search-filters select:focus { outline: none; border-color: var(--primary); }
.search-filters input[type="text"] { width: 220px; }
.search-filters input[type="date"] { width: 130px; }
.search-filters select {
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; font-family: var(--font); color: var(--text);
    background: var(--surface); cursor: pointer; min-width: 110px;
}

/* ── Incident count ─────────────────────────────────────────────────── */
.incident-count {
    font-size: 12px; color: var(--text-2); margin-bottom: 8px;
    padding-left: 2px;
}

/* ── Incident cards ─────────────────────────────────────────────────── */
.incident-card {
    background: var(--surface); border-radius: var(--radius);
    margin-bottom: 6px; box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--gray); transition: all .15s;
}
.incident-card:hover { box-shadow: var(--shadow-md); }

.incident-card.status-new     { border-left-color: var(--blue); }
.incident-card.status-approved { border-left-color: var(--green); background: #f0fdf4; }
.incident-card.status-approved_waiting { border-left-color: #ea580c; background: #fff7ed; }
.incident-card.status-sent    { border-left-color: #8b5cf6; background: #faf5ff; }
.incident-card.status-unknown  { border-left-color: var(--amber); }
.incident-card.status-cleared  { border-left-color: var(--gray); opacity: .65; }

.card-main {
    display: flex; align-items: center; padding: 12px 14px;
    gap: 14px; cursor: pointer; user-select: none;
}

/* Status + state badges */
.card-badges { flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; align-items: center; min-width: 62px; }
.status-badge {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em; white-space: nowrap;
}
.badge-new     { background: #dbeafe; color: var(--blue-dark); }
.badge-approved { background: #d1fae5; color: var(--green-dark); }
.badge-approved_waiting { background: #ffedd5; color: #9a3412; }
.badge-sent    { background: #ede9fe; color: #5b21b6; }
.badge-unknown  { background: #fef9c3; color: #854d0e; }
.badge-cleared  { background: #f3f4f6; color: var(--gray-dark); }
.state-badge {
    display: inline-block; padding: 1px 6px; border-radius: 3px;
    font-size: 10px; font-weight: 700; letter-spacing: .04em;
    background: #f0f0f0; color: #444; white-space: nowrap;
}

/* Card content */
.card-content { flex: 1; min-width: 0; }
.card-title {
    font-size: 14px; font-weight: 500; line-height: 1.4; margin-bottom: 3px;
    display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.meta-item { white-space: nowrap; }
.meta-location::before { content: "Loc: "; font-weight: 600; }
.meta-date::before     { content: "Date: "; font-weight: 600; }
.meta-sources::before  { content: ""; }

/* Triage action buttons */
.card-actions { display: flex; gap: 4px; flex-shrink: 0; }
.action-btn {
    width: 32px; height: 32px; border: 1px solid var(--border);
    border-radius: 6px; background: var(--surface); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; color: var(--text-2);
    transition: all .15s; font-family: var(--font);
}
.action-btn:hover { background: var(--bg); }
.btn-approve:hover, .btn-approve.active { background: #d1fae5; color: var(--green-dark); border-color: var(--green); }
.btn-unknown:hover, .btn-unknown.active { background: #fef3c7; color: var(--amber-dark); border-color: var(--amber); }
.btn-clear:hover,   .btn-clear.active   { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

/* ── Expanded detail ────────────────────────────────────────────────── */
.card-detail {
    display: none; border-top: 1px solid var(--border);
    padding: 0 14px;
}
.incident-card.expanded .card-detail { display: block; padding: 14px; }

.article-list-header {
    font-size: 12px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .04em; color: var(--text-2); margin-bottom: 10px;
}
.article-item {
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.article-item:last-child { border-bottom: none; }
.article-top {
    display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
    font-size: 12px;
}
.source-type {
    padding: 1px 6px; border-radius: 3px; font-size: 10px;
    font-weight: 700; text-transform: uppercase;
}
.type-news   { background: #dbeafe; color: var(--blue-dark); }
.type-social { background: #ede9fe; color: #5b21b6; }
.type-scrape { background: #fef3c7; color: var(--amber-dark); }
.source-name { color: var(--text-2); }
.article-date { color: var(--text-2); margin-left: auto; }
.article-headline {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 13px; font-weight: 500; color: var(--primary);
    text-decoration: none; line-height: 1.4;
}
.article-headline:hover { text-decoration: underline; }
.external-icon { flex-shrink: 0; opacity: .5; }
.article-snippet {
    font-size: 12px; color: var(--text-2); margin-top: 4px;
    line-height: 1.5;
}
.no-articles { font-size: 13px; color: var(--text-2); padding: 12px 0; }

/* ── Disposition chip on card ───────────────────────────────────────── */
.disposition-chip {
    display: inline-block; padding: 1px 7px; border-radius: 3px;
    font-size: 10px; font-weight: 600; letter-spacing: .03em;
    background: #ede9fe; color: #5b21b6; white-space: nowrap;
}

/* ── Detail fields (notes + disposition) ───────────────────────────── */
.detail-fields { margin-bottom: 14px; }
.detail-field { margin-bottom: 12px; }
.detail-label {
    display: block; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-2); margin-bottom: 4px;
}
.disposition-select {
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; font-family: var(--font); color: var(--text);
    background: var(--surface); cursor: pointer; min-width: 250px;
}
.disposition-select:focus { outline: none; border-color: var(--primary); }
.notes-textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 13px; font-family: var(--font);
    color: var(--text); resize: vertical; min-height: 60px;
}
.notes-textarea:focus { outline: none; border-color: var(--primary); }
.notes-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-save-notes {
    background: var(--primary); color: #fff; border: none;
    border-radius: 5px; cursor: pointer; font-weight: 600;
    font-family: var(--font); padding: 5px 14px;
}
.btn-save-notes:hover { background: var(--primary-h); }
.save-indicator { font-size: 12px; color: var(--text-2); }
.save-indicator.saved { color: var(--green-dark); font-weight: 600; }

/* ── Settings modal ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.4); z-index: 200;
    display: flex; align-items: center; justify-content: center;
}
.modal {
    background: var(--surface); border-radius: var(--radius);
    width: 480px; max-width: 90vw; max-height: 80vh;
    box-shadow: 0 20px 60px rgba(0,0,0,.15); overflow-y: auto;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close {
    background: none; border: none; font-size: 22px; cursor: pointer;
    color: var(--text-2); padding: 0 4px; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-body h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.settings-hint { font-size: 12px; color: var(--text-2); margin-bottom: 12px; }
.option-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 0; border-bottom: 1px solid var(--border);
}
.option-row:last-child { border-bottom: none; }
.option-label { font-size: 13px; }
.option-actions { display: flex; gap: 4px; }
.btn-icon-sm {
    width: 28px; height: 28px; border: 1px solid var(--border);
    border-radius: 5px; background: var(--surface); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; color: var(--text-2);
}
.btn-icon-sm:hover { background: var(--bg); }
.btn-danger:hover { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.add-option-form { display: flex; gap: 8px; margin-top: 12px; }
.settings-input {
    flex: 1; padding: 6px 10px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 13px; font-family: var(--font);
}
.settings-input:focus { outline: none; border-color: var(--primary); }
.no-options { font-size: 13px; color: var(--text-2); padding: 8px 0; }
.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border: none; border-radius: 6px;
    background: transparent; cursor: pointer; color: var(--text-2);
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── Empty state ────────────────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 60px 20px; color: var(--text-2);
}
.empty-icon { margin-bottom: 16px; opacity: .35; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-text { font-size: 13px; }

/* ── Loading indicator (HTMX) ───────────────────────────────────────── */
.htmx-request .action-btn { opacity: .4; pointer-events: none; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-main { padding: 12px; }
    .stats { flex-wrap: wrap; gap: 8px; }
    .stat-item { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 10px 12px; }
    .stat-count { font-size: 22px; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .search-filters { flex-wrap: wrap; }
    .search-filters input[type="text"] { width: 100%; }
    .card-main { flex-wrap: wrap; gap: 8px; }
    .card-actions { width: 100%; justify-content: flex-end; }
    .header-subtitle { display: none; }
}

@media (max-width: 480px) {
    .stat-item { flex: 1 1 100%; }
    .status-tabs { flex-wrap: wrap; }
}

/* ── Desirability Badges ────────────────────────────────────────────── */
.desirability-badge {
    font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
    padding: 2px 8px; border-radius: 9999px; letter-spacing: 0.04em;
}
.desr-high   { background: #dcfce7; color: #166534; }
.desr-medium { background: #fef3c7; color: #92400e; }
.desr-low    { background: #f3f4f6; color: #6b7280; }

/* ── AI Analysis Section ────────────────────────────────────────────── */
.ai-analysis-section {
    margin: 0.75rem 0; border: 1px solid #e5e7eb; border-radius: 8px;
    overflow: hidden;
}
.ai-analysis-header {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem;
    background: #f9fafb; cursor: pointer; user-select: none;
}
.ai-label { font-size: 0.8rem; font-weight: 600; color: #374151; }
.ai-toggle-icon {
    margin-left: auto; font-size: 0.65rem; color: #9ca3af;
    transition: transform 0.2s;
}
.ai-analysis-section.expanded .ai-toggle-icon { transform: rotate(180deg); }
.ai-analysis-body {
    display: none; padding: 0.75rem; font-size: 0.82rem; color: #4b5563;
    line-height: 1.5;
}
.ai-analysis-section.expanded .ai-analysis-body { display: block; }
.ai-reasoning { margin-bottom: 0.5rem; }
.ai-factors { display: flex; flex-direction: column; gap: 0.25rem; }
.ai-factor { font-size: 0.78rem; }
.ai-factor strong { color: #374151; text-transform: capitalize; }
.ai-escalated {
    margin-top: 0.5rem; font-size: 0.72rem; color: #7c3aed;
    font-style: italic;
}

/* ── Dashboard Layout (main + parking sidebar) ──────────────────────── */
.dashboard-layout {
    display: flex; gap: 0; min-height: calc(100vh - 64px);
}
.dashboard-main { flex: 1; min-width: 0; }

/* ── Parking Zone ───────────────────────────────────────────────────── */
.parking-zone {
    width: 280px; min-width: 280px; background: #f9fafb;
    border-left: 2px solid #e5e7eb; padding: 12px;
    display: flex; flex-direction: column; gap: 8px;
    transition: border-color 0.2s, background 0.2s;
    position: sticky; top: 64px; height: calc(100vh - 64px);
    overflow-y: auto;
}
.parking-zone.active {
    border-left-color: #3b82f6; background: #eff6ff;
}
.parking-zone.drop-hover {
    border-left-color: #2563eb; background: #dbeafe;
}
.parking-header {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.82rem; font-weight: 700; color: #374151;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.parking-hint {
    font-size: 0.75rem; color: #9ca3af; line-height: 1.4;
}
.parked-list {
    display: flex; flex-direction: column; gap: 6px;
}
.parked-card {
    display: flex; align-items: center; gap: 6px;
    background: #fff; border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 6px 8px; cursor: grab; font-size: 0.78rem;
    transition: box-shadow 0.15s, opacity 0.15s;
}
.parked-card:hover { box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
.parked-card.dragging { opacity: 0.4; }
.parked-card-content {
    flex: 1; display: flex; align-items: center; gap: 4px;
    min-width: 0; overflow: hidden;
}
.parked-headline {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    flex: 1; color: #374151;
}
.parked-count {
    font-size: 0.68rem; color: #6b7280; background: #f3f4f6;
    padding: 1px 5px; border-radius: 9999px; white-space: nowrap;
}
.parked-return {
    background: none; border: none; cursor: pointer;
    color: #6b7280; font-size: 0.9rem; padding: 2px 4px;
    border-radius: 4px; transition: color 0.15s, background 0.15s;
}
.parked-return:hover { color: #1d4ed8; background: #eff6ff; }

/* ── Drag states on incident cards ──────────────────────────────────── */
.incident-card { cursor: grab; transition: opacity 0.2s, border-color 0.2s; }
.incident-card.dragging {
    opacity: 0.35; border-style: dashed; cursor: grabbing;
}
.incident-card.drop-target {
    border-color: #3b82f6 !important; background: #eff6ff;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.3);
}
.incident-card.drop-target .drop-merge-indicator { display: flex; }
.drop-merge-indicator {
    display: none; align-items: center; justify-content: center;
    padding: 6px; font-size: 0.75rem; font-weight: 600;
    color: #2563eb; background: #dbeafe; border-top: 1px solid #bfdbfe;
}

/* Prevent expand when dragging */
body.is-dragging .card-main { pointer-events: none; }
body.is-dragging .card-actions { pointer-events: auto; }
body.is-dragging .incident-card { cursor: default; }

/* ── Separate article button ────────────────────────────────────────── */
.btn-separate {
    background: none; border: 1px solid transparent; cursor: pointer;
    color: #9ca3af; font-size: 1rem; line-height: 1; padding: 2px 6px;
    border-radius: 4px; margin-left: auto;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.btn-separate:hover {
    color: #dc2626; background: #fef2f2; border-color: #fecaca;
}

/* ── Responsive: collapse parking on small screens ──────────────────── */
@media (max-width: 900px) {
    .parking-zone { width: 200px; min-width: 200px; }
}
@media (max-width: 640px) {
    .dashboard-layout { flex-direction: column; }
    .parking-zone {
        width: 100%; min-width: 0; position: static;
        height: auto; border-left: none; border-top: 2px solid #e5e7eb;
    }
}

/* ── Scan Controls ──────────────────────────────────────────────────── */
.scan-controls {
    padding: 8px 14px; background: #fff; border-bottom: 1px solid #e5e7eb;
}
.scan-row {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.scan-dates {
    display: flex; gap: 8px; align-items: center; font-size: 0.8rem;
}
.scan-dates label { display: flex; align-items: center; gap: 4px; color: #6b7280; }
.scan-dates input[type=date] {
    padding: 3px 6px; border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 0.78rem;
}
.scan-last-time {
    font-size: 0.75rem; color: #9ca3af; margin-left: auto;
}

/* ── Bulk Actions ───────────────────────────────────────────────────── */
.bulk-actions {
    padding: 8px 14px; background: #fef2f2; border-bottom: 1px solid #fecaca;
}
.bulk-delete-row {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    font-size: 0.8rem;
}
.bulk-delete-row label { display: flex; align-items: center; gap: 4px; color: #991b1b; }
.bulk-delete-row input[type=date] {
    padding: 3px 6px; border: 1px solid #fca5a5; border-radius: 4px;
    font-size: 0.78rem;
}
.btn-danger {
    background: #dc2626; color: #fff; border: none; cursor: pointer;
    padding: 4px 10px; border-radius: 4px; font-size: 0.75rem; font-weight: 600;
}
.btn-danger:hover { background: #b91c1c; }
#bulk-delete-info { font-size: 0.78rem; color: #991b1b; }

/* ── State Override ─────────────────────────────────────────────────── */
.state-override-row { display: flex; align-items: center; gap: 6px; }
.state-select {
    padding: 4px 8px; border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 0.8rem; background: #fff;
}
.state-manual-badge {
    font-size: 0.65rem; color: #7c3aed; background: #ede9fe;
    padding: 1px 6px; border-radius: 9999px; font-weight: 600;
}

/* ── State Filter Checkboxes (Settings) ─────────────────────────────── */
.state-filter-controls { margin-bottom: 1rem; }
.state-filter-actions { display: flex; gap: 6px; margin-bottom: 6px; }
.state-checkbox-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(55px, 1fr));
    gap: 2px 4px; max-height: 180px; overflow-y: auto;
    border: 1px solid #e5e7eb; border-radius: 4px; padding: 6px;
    background: #f9fafb;
}
.state-cb-label {
    display: flex; align-items: center; gap: 2px;
    font-size: 0.72rem; cursor: pointer; padding: 1px 2px;
    border-radius: 2px;
}
.state-cb-label:hover { background: #eff6ff; }
.state-cb-label input[type=checkbox] { width: 14px; height: 14px; }
.toggle-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.78rem; color: #374151; margin-top: 8px; cursor: pointer;
}
.toggle-label input[type=checkbox] { width: 16px; height: 16px; }
/* ── Disposition option drag-to-reorder ──────────────────────────────── */
.option-drag-handle {
    cursor: grab; color: #9ca3af; font-size: 0.9rem; padding: 0 4px;
    user-select: none;
}
.option-drag-handle:hover { color: #374151; }
.option-row { cursor: default; transition: opacity 0.15s; }
.option-row.option-dragging { opacity: 0.35; border-style: dashed; }
.option-row.option-drop-above { border-top: 2px solid #3b82f6 !important; }

.settings-select {
    padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 6px;
    font-size: 0.82rem; background: #fff; width: 100%; max-width: 300px;
}

/* ── Box Sent On ────────────────────────────────────────────────────── */
.box-sent-section {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 0; border-top: 1px solid #e5e7eb;
    margin-top: 8px;
}
.box-sent-label {
    display: flex; align-items: center; gap: 5px;
    font-size: 0.8rem; font-weight: 600; color: #374151;
    cursor: pointer; white-space: nowrap;
}
.box-sent-label input[type=checkbox] { width: 16px; height: 16px; accent-color: #059669; }
.box-sent-date {
    padding: 3px 6px; border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 0.78rem;
}
.btn-clear-date {
    background: none; border: 1px solid #d1d5db; cursor: pointer;
    color: #9ca3af; font-size: 0.9rem; padding: 1px 6px;
    border-radius: 4px; line-height: 1;
}
.btn-clear-date:hover { color: #dc2626; border-color: #fca5a5; background: #fef2f2; }

/* ── Social source type badges ──────────────────────────────────────── */
/* ── Drag handle + pin + reorder ─────────────────────────────────────── */
.card-drag-handle {
    cursor: grab; color: #9ca3af; font-size: 1.1rem; padding: 0 4px;
    user-select: none; display: flex; align-items: center;
    border-right: 1px solid #e5e7eb; margin-right: 6px;
}
.card-drag-handle:hover { color: #374151; }
.card-drag-handle:active { cursor: grabbing; }
.pin-badge {
    background: #fbbf24; color: #78350f; font-size: 0.6rem; font-weight: 700;
    padding: 1px 5px; border-radius: 9999px;
}
.btn-pin { color: #d1d5db; font-size: 1rem; }
.btn-pin.active { color: #f59e0b; }
.btn-pin:hover { color: #f59e0b; }
.reorder-dragging { opacity: 0.4; border-style: dashed; }
.reorder-drop-above {
    border-top: 3px solid #3b82f6 !important;
    margin-top: -2px;
}

/* ── Crash date + wait date ──────────────────────────────────────────── */
.crash-date-section {
    padding: 8px 0; border-top: 1px solid #e5e7eb; margin-top: 8px;
}
.crash-date-row {
    display: flex; align-items: center; gap: 8px; margin-top: 4px;
}
.crash-date-input {
    padding: 3px 6px; border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 0.78rem;
}
.auto-badge {
    font-size: 0.65rem; color: #2563eb; background: #dbeafe;
    padding: 1px 6px; border-radius: 9999px; font-weight: 600;
}
.wait-date-badge {
    font-size: 0.7rem; color: #92400e; background: #fef3c7;
    padding: 2px 8px; border-radius: 9999px; font-weight: 600;
}
.meta-wait-date {
    color: #92400e; font-weight: 600; background: #fef3c7;
    padding: 1px 6px; border-radius: 4px;
}

/* ── Urgent stat highlight ──────────────────────────────────────────── */
.stat-urgent {
    background: #fef2f2 !important; border-top-color: #dc2626 !important;
    border: 2px solid #fca5a5; border-radius: 6px;
}
.stat-urgent .stat-count { color: #dc2626 !important; }
.urgent-badge {
    display: inline-block; background: #dc2626; color: #fff;
    font-size: 0.6rem; font-weight: 700; padding: 1px 5px;
    border-radius: 9999px; margin-left: 3px;
}

/* ── Urgent waiting banner ──────────────────────────────────────────── */
.urgent-banner {
    background: #fef2f2; border: 2px solid #fca5a5; border-radius: 8px;
    padding: 12px 16px; margin: 8px 14px;
}
/* ── Synopsis on card ────────────────────────────────────────────────── */
.card-synopsis {
    font-size: 0.78rem; color: #4b5563; line-height: 1.4;
    margin: 2px 0 4px 0; max-width: 700px;
}
.paste-text-row { margin-top: 4px; }
.paste-box { margin-top: 4px; display: flex; flex-direction: column; gap: 4px; }
.paste-textarea {
    width: 100%; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 0.78rem; resize: vertical;
}
.article-has-text {
    font-size: 0.65rem; color: #059669; font-weight: 600;
}

.ai-derived-badge {
    font-size: 0.55rem; background: #e0e7ff; color: #4338ca;
    padding: 0 4px; border-radius: 3px; font-weight: 700;
    vertical-align: middle;
}

/* ── New sources badge ───────────────────────────────────────────────── */
.new-sources-badge {
    background: #dbeafe; color: #1d4ed8; font-size: 0.65rem; font-weight: 700;
    padding: 1px 6px; border-radius: 9999px; border: 1px solid #93c5fd;
}

.urgent-header {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.urgent-actions { display: flex; align-items: center; gap: 6px; }
.btn-close-banner {
    background: none; border: none; cursor: pointer;
    color: #991b1b; font-size: 1.2rem; line-height: 1; padding: 0 4px;
}
.btn-close-banner:hover { color: #dc2626; }
.urgent-banner strong { color: #dc2626; }
.urgent-item {
    display: flex; gap: 8px; margin-top: 4px;
    font-size: 0.8rem; color: #991b1b;
}
.urgent-date { font-weight: 700; white-space: nowrap; }
.urgent-headline { color: #374151; }

.type-x { background: #000; color: #fff; }
.type-facebook { background: #1877f2; color: #fff; }
.type-instagram {
    background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
    color: #fff;
}

/* ── Login page ─────────────────────────────────────────────────────── */
.login-body {
    background: var(--bg); display: flex; align-items: center;
    justify-content: center; min-height: 100vh;
}
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card {
    background: #fff; border-radius: 12px; padding: 32px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
.login-title {
    font-size: 1.5rem; font-weight: 800; color: var(--brand);
    text-align: center; margin-bottom: 4px;
}
.login-subtitle {
    font-size: 0.85rem; color: #6b7280; text-align: center; margin-bottom: 20px;
}
.login-error {
    background: #fef2f2; color: #dc2626; padding: 8px 12px;
    border-radius: 6px; font-size: 0.82rem; margin-bottom: 16px;
    border: 1px solid #fecaca;
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-field { display: flex; flex-direction: column; gap: 4px; }
.login-field label { font-size: 0.8rem; font-weight: 600; color: #374151; }
.login-field input {
    padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 6px;
    font-size: 0.9rem;
}
.login-field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
.login-btn { padding: 10px; font-size: 0.9rem; border-radius: 6px; cursor: pointer; }

/* ── User menu in header ────────────────────────────────────────────── */
.user-menu {
    display: flex; align-items: center; gap: 6px;
    border-left: 1px solid var(--border); padding-left: 10px; margin-left: 6px;
}
.user-name { font-size: 0.78rem; color: var(--text-1); font-weight: 600; }
.btn-ghost {
    background: transparent; border: 1px solid var(--border);
    color: var(--brand); font-size: 0.7rem; padding: 3px 8px;
    border-radius: 4px; text-decoration: none; cursor: pointer;
}
.btn-ghost:hover { background: var(--bg); }
.btn-labeled {
    background: var(--bg); border: 1px solid var(--border); color: var(--text-1);
    padding: 5px 12px; border-radius: 6px; font-size: 0.78rem; font-weight: 600;
    cursor: pointer; text-decoration: none;
}
.btn-labeled:hover { background: var(--border); }

/* ── Admin panel ────────────────────────────────────────────────────── */
.admin-page { padding: 20px; max-width: 800px; margin: 0 auto; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.admin-header h2 { font-size: 1.3rem; color: #111827; }
.admin-section { background: #fff; border-radius: 8px; padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.admin-section h3 { font-size: 0.95rem; margin-bottom: 12px; color: #374151; }
.admin-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.admin-input {
    padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 4px;
    font-size: 0.82rem;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.admin-table th { text-align: left; padding: 8px; border-bottom: 2px solid #e5e7eb; color: #6b7280; font-weight: 600; }
.admin-table td { padding: 8px; border-bottom: 1px solid #f3f4f6; }
.admin-input-wide { flex: 1; min-width: 200px; }

/* ── Search term chips ──────────────────────────────────────────────── */
.term-list {
    display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.term-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 8px; border-radius: 6px; font-size: 0.78rem; font-weight: 500;
}
.term-positive { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.term-negative { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.term-delete {
    background: none; border: none; cursor: pointer; font-size: 0.9rem;
    color: inherit; opacity: 0.5; padding: 0 2px; line-height: 1;
}
.term-delete:hover { opacity: 1; }

/* ── Proximity rule builder ──────────────────────────────────────────── */
.prox-form { margin-bottom: 10px; }
.prox-inputs {
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px;
}
.prox-term { flex: 1; min-width: 140px; }
.prox-num { width: 60px; text-align: center; }
.prox-label { font-size: 0.78rem; color: #6b7280; white-space: nowrap; }
.prox-rules-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.prox-rule-chip {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px; border-radius: 6px; font-size: 0.8rem;
    background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af;
}
.prox-rule-text { flex: 1; }
.prox-rule-text strong { color: #1d4ed8; }

.role-badge { padding: 2px 8px; border-radius: 9999px; font-size: 0.68rem; font-weight: 700; }
.role-admin { background: #dbeafe; color: #1e40af; }
.role-user { background: #f3f4f6; color: #6b7280; }
.you-badge { font-size: 0.72rem; color: #9ca3af; font-style: italic; }

/* ── Scan Log ───────────────────────────────────────────────────────── */
.scan-log-stats {
    display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.log-stat {
    background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
    padding: 12px 16px; min-width: 120px; text-align: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.log-stat-value {
    display: block; font-size: 1.2rem; font-weight: 800; color: #111827;
}
.log-stat-label {
    font-size: 0.7rem; color: #6b7280; text-transform: uppercase;
    letter-spacing: 0.03em;
}
.scan-log-table td { font-size: 0.78rem; white-space: nowrap; }
.scan-status-badge {
    padding: 2px 6px; border-radius: 4px; font-size: 0.65rem; font-weight: 700;
}
.scan-completed { background: #dcfce7; color: #166534; }
.scan-running { background: #dbeafe; color: #1d4ed8; }
.scan-failed { background: #fef2f2; color: #dc2626; }
.scan-errors { font-size: 0.72rem; color: #dc2626; max-width: 200px; }
.scan-row-failed { background: #fef2f2; }
.scan-row-running { background: #eff6ff; }

/* ── AI Chat Panel ──────────────────────────────────────────────────── */
.chat-panel {
    position: fixed; right: 0; top: 0; bottom: 0; width: 380px;
    background: #fff; border-left: 2px solid #e5e7eb;
    box-shadow: -4px 0 20px rgba(0,0,0,0.1); z-index: 300;
    display: flex; flex-direction: column;
}
.chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid #e5e7eb;
    font-weight: 700; font-size: 0.9rem; color: #111827;
    background: #f9fafb;
}
.chat-header-actions { display: flex; gap: 6px; }
.chat-clear-btn {
    background: none; border: 1px solid #d1d5db; border-radius: 4px;
    padding: 2px 8px; font-size: 0.7rem; color: #6b7280; cursor: pointer;
}
.chat-clear-btn:hover { background: #f3f4f6; }
.chat-close-btn {
    background: none; border: none; font-size: 1.3rem; cursor: pointer;
    color: #6b7280; line-height: 1;
}
.chat-close-btn:hover { color: #111827; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 12px 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.chat-msg { max-width: 90%; }
.chat-msg-user { align-self: flex-end; }
.chat-msg-assistant { align-self: flex-start; }
.chat-msg-header {
    font-size: 0.65rem; color: #9ca3af; margin-bottom: 2px;
    display: flex; gap: 6px; align-items: center;
}
.chat-msg-time { font-size: 0.6rem; color: #d1d5db; }
.chat-msg-body {
    padding: 8px 12px; border-radius: 12px; font-size: 0.82rem;
    line-height: 1.5;
}
.chat-msg-user .chat-msg-body {
    background: #2563eb; color: #fff; border-bottom-right-radius: 4px;
}
.chat-msg-assistant .chat-msg-body {
    background: #f3f4f6; color: #111827; border-bottom-left-radius: 4px;
}
.chat-typing .chat-msg-body {
    color: #9ca3af; font-style: italic;
}
.chat-training-tag {
    display: inline-block; background: #dcfce7; color: #166534;
    font-size: 0.68rem; padding: 1px 6px; border-radius: 4px;
    font-weight: 600; margin-top: 4px;
}
.chat-welcome {
    text-align: center; color: #9ca3af; font-size: 0.8rem;
    padding: 20px; line-height: 1.5;
}
.chat-input-row {
    display: flex; gap: 6px; padding: 10px 12px;
    border-top: 1px solid #e5e7eb; background: #f9fafb;
}
.chat-input {
    flex: 1; padding: 8px 12px; border: 1px solid #d1d5db;
    border-radius: 8px; font-size: 0.82rem;
}
.chat-input:focus { outline: none; border-color: #2563eb; }
.chat-send-btn { padding: 8px 14px; border-radius: 8px; font-size: 0.82rem; }

@media (max-width: 640px) {
    .chat-panel { width: 100%; }
}

/* ── Per-State Severity ─────────────────────────────────────────────── */
.severity-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 6px; margin-top: 8px;
}
.severity-row {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 8px; background: #f9fafb; border: 1px solid #e5e7eb;
    border-radius: 4px;
}
.severity-state {
    font-weight: 700; font-size: 0.82rem; color: #374151;
    min-width: 28px;
}
.severity-select {
    flex: 1; padding: 3px 6px; border: 1px solid #d1d5db;
    border-radius: 4px; font-size: 0.78rem; background: #fff;
}
.user-actions-cell { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pw-form { display: inline-flex; align-items: center; gap: 4px; }
.pw-input { width: 120px; font-size: 0.78rem; padding: 3px 6px; }
