/* Theme variables */
[data-theme="dark"] {
    --color-bg: #0d1117;
    --color-text: #e2e8f0;
    --color-muted: #8b949e;
    --color-card-bg: #161b22;
    --color-border: #30363d;
    --color-card-value: #e2e8f0;
    --color-accent: #667eea;
    --color-th-bg: #161b22;
    --color-th-text: #8b949e;
    --color-th-hover: #e2e8f0;
    --color-row-hover: #1c2128;
    --badge-green-bg: #22543d;
    --badge-green-text: #68d391;
    --badge-yellow-bg: #744210;
    --badge-yellow-text: #fbd38d;
    --badge-red-bg: #822727;
    --badge-red-text: #fc8181;
    --badge-blue-bg: #2a4365;
    --badge-blue-text: #90cdf4;
    --badge-gray-bg: #2d3748;
    --badge-gray-text: #a0aec0;
    --badge-teal-bg: #234e52;
    --badge-teal-text: #81e6d9;
    --badge-purple-bg: #44337a;
    --badge-purple-text: #d6bcfa;
    --badge-orange-bg: #7b341e;
    --badge-orange-text: #fbd38d;
    --color-pagination-border: #30363d;
    --color-pagination-text: #8b949e;
    --btn-bg: #161b22;
    --btn-border: #30363d;
    --btn-text: #8b949e;
    --btn-hover-bg: #1c2128;
    --btn-delete-text: #fc8181;
    --btn-delete-border: #822727;
    --btn-delete-hover-bg: #822727;
    --btn-save-text: #68d391;
    --btn-save-border: #22543d;
    --btn-save-hover-bg: #22543d;
    --modal-backdrop: rgba(0,0,0,0.65);
    --modal-bg: #161b22;
    --modal-border: #30363d;
    --modal-text: #e2e8f0;
    --modal-close: #8b949e;
    --source-text-bg: #0d1117;
    --tooltip-bg: #161b22;
    --tooltip-border: #30363d;
    --tooltip-shadow: rgba(0,0,0,0.4);
    --tooltip-text: #e2e8f0;
    --input-bg: #0d1117;
    --input-border: #30363d;
    --input-text: #e2e8f0;
}

[data-theme="light"] {
    --color-bg: #f8f9fa;
    --color-text: #1a202c;
    --color-muted: #718096;
    --color-card-bg: #ffffff;
    --color-border: #e2e8f0;
    --color-card-value: #1a202c;
    --color-accent: #667eea;
    --color-th-bg: #f7fafc;
    --color-th-text: #718096;
    --color-th-hover: #1a202c;
    --color-row-hover: #f7fafc;
    --badge-green-bg: #c6f6d5;
    --badge-green-text: #22543d;
    --badge-yellow-bg: #fefcbf;
    --badge-yellow-text: #744210;
    --badge-red-bg: #fed7d7;
    --badge-red-text: #9b2c2c;
    --badge-blue-bg: #bee3f8;
    --badge-blue-text: #2a4365;
    --badge-gray-bg: #e2e8f0;
    --badge-gray-text: #4a5568;
    --badge-teal-bg: #b2f5ea;
    --badge-teal-text: #234e52;
    --badge-purple-bg: #e9d8fd;
    --badge-purple-text: #553c9a;
    --badge-orange-bg: #feebc8;
    --badge-orange-text: #c05621;
    --color-pagination-border: #e2e8f0;
    --color-pagination-text: #718096;
    --btn-bg: #ffffff;
    --btn-border: #e2e8f0;
    --btn-text: #718096;
    --btn-hover-bg: #f7fafc;
    --btn-delete-text: #e53e3e;
    --btn-delete-border: #fc8181;
    --btn-delete-hover-bg: #fff5f5;
    --btn-save-text: #38a169;
    --btn-save-border: #68d391;
    --btn-save-hover-bg: #f0fff4;
    --modal-backdrop: rgba(0,0,0,0.4);
    --modal-bg: #ffffff;
    --modal-border: #e2e8f0;
    --modal-text: #1a202c;
    --modal-close: #718096;
    --source-text-bg: #f7fafc;
    --tooltip-bg: #ffffff;
    --tooltip-border: #e2e8f0;
    --tooltip-shadow: rgba(0,0,0,0.15);
    --tooltip-text: #1a202c;
    --input-bg: #ffffff;
    --input-border: #e2e8f0;
    --input-text: #1a202c;
}

body {
    display: flex;
    min-height: 100vh;
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
}

.sidebar {
    width: 170px;
    height: 100vh;
    position: sticky;
    top: 0;
    background: #1a1a2e;
    padding: 1rem 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

/* Override Pico CSS nav styles */
nav.sidebar {
    display: flex;
    flex-direction: column;
}

nav.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sidebar li {
    margin: 0;
    padding: 0;
    display: block;
    width: 100%;
}

nav.sidebar a {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0.45rem 1rem;
    color: #a0aec0;
    text-decoration: none;
    font-size: 0.8rem;
    box-shadow: inset 3px 0 0 transparent;
    transition: all 0.15s;
    box-sizing: border-box;
}

nav.sidebar a:hover,
nav.sidebar a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
    box-shadow: inset 3px 0 0 #667eea;
}

.sidebar-details {
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: none !important;
}
.sidebar-details summary {
    display: block;
    padding: 0.45rem 1rem;
    color: #a0aec0 !important;
    font-size: 0.8rem;
    font-weight: normal;
    cursor: pointer;
    list-style: none;
    border: none !important;
    background: none !important;
    margin-bottom: 0 !important;
    transition: color 0.15s;
}
.sidebar-details summary::-webkit-details-marker,
.sidebar-details summary::marker { display: none; content: ""; }
.sidebar-details summary::after {
    content: "" !important;
    background-image: none !important;
    width: 0.4rem;
    height: 0.4rem;
    float: right;
    margin-top: 0.35rem;
    border-right: 1.5px solid #a0aec0;
    border-bottom: 1.5px solid #a0aec0;
    transform: rotate(-45deg);
    transition: transform 0.15s;
}
.sidebar-details[open] summary::after {
    transform: rotate(45deg);
}
.sidebar-details summary:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.05) !important;
}
.sidebar-details[open] summary {
    color: #cbd5e0 !important;
}
.sidebar-details ul {
    margin: 0;
    padding: 0;
    list-style: none;
}
.sidebar-details ul li {
    margin: 0;
    padding: 0;
}
.sidebar-details ul a {
    padding-left: 1.5rem !important;
    font-size: 0.75rem;
    opacity: 0.85;
}

.content {
    flex: 1;
    padding: 1rem 1.5rem 2rem;
    padding-bottom: 32px;
    overflow-x: auto;
}

/* Cards strip — single horizontal row with scroll */
.cards {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.card {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 0 0 auto;
    min-width: 120px;
}

.card-gear {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    text-decoration: none;
    font-family: serif;
    font-size: 1rem;
    line-height: 1;
    color: var(--color-muted);
    opacity: 0.6;
    transition: opacity 0.15s;
}
.card-gear:hover { opacity: 1; }

.card h3 {
    margin: 0 0 0.25rem;
    font-size: 0.7rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card .value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-card-value);
    margin-top: auto;
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-green  { background: var(--badge-green-bg); color: var(--badge-green-text); }
.badge-yellow { background: var(--badge-yellow-bg); color: var(--badge-yellow-text); }
.badge-red    { background: var(--badge-red-bg); color: var(--badge-red-text); }
.badge-blue   { background: var(--badge-blue-bg); color: var(--badge-blue-text); }
.badge-gray   { background: var(--badge-gray-bg); color: var(--badge-gray-text); }
.badge-teal   { background: var(--badge-teal-bg); color: var(--badge-teal-text); }
.badge-purple { background: var(--badge-purple-bg); color: var(--badge-purple-text); }
.badge-orange { background: var(--badge-orange-bg); color: var(--badge-orange-text); }

/* Tables */
table {
    width: max-content;
    min-width: 100%;
    font-size: 0.8rem;
}

th {
    text-align: left;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--color-th-text);
    letter-spacing: 0.05em;
    background: var(--color-th-bg);
}

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--color-th-hover); }
th.active-sort { color: var(--color-accent); }

td {
    vertical-align: top;
}

.text-truncate {
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text-muted {
    color: var(--color-muted);
    font-size: 0.73rem;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    align-items: center;
}

.pagination a {
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--color-pagination-border);
    border-radius: 4px;
    font-size: 0.78rem;
    text-decoration: none;
    color: var(--color-pagination-text);
}

.pagination a.active-page {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

.pagination-ellipsis {
    padding: 0.35rem 0.25rem;
    font-size: 0.78rem;
    color: var(--color-pagination-text);
}

/* Job status section */
.job-status {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.job-card {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    position: relative;
}

.job-card h3 {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
}

.job-card dl {
    margin: 0;
    font-size: 0.78rem;
}

.job-card dt {
    color: var(--color-muted);
    margin-top: 0.35rem;
}

.job-card dd {
    margin: 0 0 0.25rem;
    font-weight: 500;
}

/* Log viewer */
#log-container {
    background: #1a1a2e;
    color: #a0f0a0;
    font-family: "Menlo", "Consolas", "Courier New", monospace;
    font-size: 0.75rem;
    line-height: 1.4;
    padding: 1rem;
    border-radius: 8px;
    height: calc(100vh - 120px);
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

#log-container .log-line { display: block; }

/* Scheduler jobs table */
.scheduler-section {
    margin-top: 1.5rem;
}

/* Filter bar */
.filter-bar {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1rem;
    align-items: center;
}

.filter-bar select,
.filter-bar input {
    font-size: 0.78rem;
    padding: 0.25rem 0.4rem;
    margin-bottom: 0;
}

.filter-bar select {
    padding-right: 1.6rem;
}

/* Add-channel form */
.add-channel-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    align-items: center;
}

.add-channel-form input {
    font-size: 0.78rem;
    padding: 0.25rem 0.4rem;
    margin-bottom: 0;
    flex: 1;
    min-width: 260px;
}

.add-channel-form button {
    font-size: 0.78rem;
    padding: 0.25rem 0.6rem;
    margin-bottom: 0;
    white-space: nowrap;
}

/* Small action buttons */
.btn-sm {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    margin: 0 0.15rem;
    border: 1px solid var(--btn-border);
    border-radius: 4px;
    cursor: pointer;
    background: var(--btn-bg);
    color: var(--btn-text);
}

.btn-sm:hover { background: var(--btn-hover-bg); }

.pitch-cell {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-copy {
    flex-shrink: 0;
    padding: 0.1rem 0.3rem;
    border: 1px solid var(--btn-border);
    border-radius: 4px;
    cursor: pointer;
    background: var(--btn-bg);
    color: var(--color-muted);
    font-size: 0.7rem;
    line-height: 1;
}
.btn-copy:hover { color: var(--color-accent); background: var(--btn-hover-bg); }
.btn-delete { color: var(--btn-delete-text); border-color: var(--btn-delete-border); }
.btn-delete:hover { background: var(--btn-delete-hover-bg); }
.btn-save { color: var(--btn-save-text); border-color: var(--btn-save-border); }
.btn-save:hover { background: var(--btn-save-hover-bg); }

td.actions-cell { vertical-align: middle; }
td.actions-cell > * { display: inline-block; margin: 0.1rem; }

.cell-edit {
    font-size: 0.78rem;
    padding: 0.15rem 0.3rem;
    margin-bottom: 0;
    width: 100%;
}

/* Responsive tables */
.table-responsive,
#table-container { overflow-x: auto; }

/* Media thumbnails */
.media-thumb { max-width: 48px; max-height: 48px; border-radius: 4px; object-fit: cover; }

/* Modal */
#modal-container {
    position: fixed; top: 0; left: 0;
    width: 0; height: 0;
    overflow: visible;
    z-index: 1000;
}
.modal-backdrop {
    position: fixed; inset: 0;
    background: var(--modal-backdrop);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--modal-bg); border: 1px solid var(--modal-border); border-radius: 8px;
    padding: 1.15rem; max-width: 650px; width: 90%;
    max-height: 80vh; overflow-y: auto;
    position: relative; color: var(--modal-text);
}
.modal-close {
    position: absolute; top: 0.5rem; right: 0.75rem;
    background: none; border: none; font-size: 1.25rem;
    cursor: pointer; color: var(--modal-close);
}
.source-message { margin-bottom: 1rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.75rem; }
.source-message:last-child { border-bottom: none; }
.source-meta { font-size: 0.7rem; color: var(--color-muted); margin-bottom: 0.25rem; }
.source-text {
    font-size: 0.78rem; white-space: pre-wrap; word-break: break-word;
    background: var(--source-text-bg); padding: 0.4rem; border-radius: 4px;
    max-height: 300px; overflow-y: auto; margin: 0; color: var(--color-text);
}
.source-text a {
    color: var(--color-accent);
    text-decoration: underline;
}

/* VS Code-style status bar */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 170px;
    right: 0;
    height: 20px;
    background: #1a1a2e;
    color: #a0aec0;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    z-index: 100;
}

.sb-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sb-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sb-logs-toggle {
    background: none;
    border: none;
    color: #a0aec0;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    transition: color 0.15s;
}
.sb-logs-toggle:hover { color: #e2e8f0; }

.sb-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    position: relative;
    cursor: default;
}

.sb-item::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 6px;
    background: #1a1a2e;
    color: #e2e8f0;
    font-size: 0.65rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}

.sb-item:hover::after {
    opacity: 1;
}

.sb-db  { color: #68d391; }
.sb-tg  { color: #63b3ed; }
.sb-llm { color: #d6bcfa; }

/* Collapsible log panel */
.log-panel {
    position: fixed;
    bottom: 20px;
    left: 170px;
    right: 0;
    height: 0;
    overflow: hidden;
    transition: height 0.2s ease;
    z-index: 99;
    display: flex;
    flex-direction: column;
}

.log-panel.open {
    height: 220px;
    overflow: visible;
}

.log-panel.dragging {
    transition: none;
}

.log-panel-resize {
    position: absolute;
    top: -3px;
    left: 0;
    right: 0;
    height: 6px;
    cursor: ns-resize;
    z-index: 101;
    display: none;
}
.log-panel.open .log-panel-resize {
    display: block;
}
.log-panel-resize:hover,
.log-panel-resize.active {
    background: var(--color-accent, #3b82f6);
    opacity: 0.5;
}

.log-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1a1a2e;
    border-top: 1px solid #30363d;
    border-bottom: 1px solid #30363d;
    padding: 0 0.75rem;
    height: 22px;
    flex-shrink: 0;
    color: #a0aec0;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.log-panel-close {
    background: none;
    border: none;
    color: #8b949e;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}
.log-panel-close:hover { color: #e2e8f0; }

.log-panel #log-container {
    flex: 1;
    margin: 0;
    border-radius: 0;
    height: auto;
}

/* Cell tooltip for truncated text */
.cell-tooltip {
    position: fixed;
    background: var(--tooltip-bg);
    border: 1px solid var(--tooltip-border);
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    font-size: 0.78rem;
    max-width: 450px;
    word-break: break-word;
    white-space: normal;
    box-shadow: 0 4px 12px var(--tooltip-shadow);
    z-index: 900;
    user-select: text;
    cursor: text;
    line-height: 1.4;
    color: var(--tooltip-text);
}

/* Inline form inputs inside tables (e.g. depth) */
td input[type="number"] {
    width: 3.5rem;
    text-align: center;
    padding: 0.2rem 0.35rem;
    margin: 0;
    font-size: 0.78rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    border-radius: 4px;
}

/* Theme-aware overrides for inputs/selects */
.filter-bar select,
.filter-bar input,
.add-channel-form input,
.cell-edit {
    background-color: var(--input-bg);
    border-color: var(--input-border);
    color: var(--input-text);
}

/* Inline status dropdown */
.status-select {
    font-size: 0.7rem;
    padding: 0.1rem 0.3rem;
    margin: 0;
    border: 1px solid transparent;
    border-radius: 9999px;
    cursor: pointer;
    font-weight: 600;
    appearance: none;
    -webkit-appearance: none;
    text-align: center;
    background-image: none;
}
.status-new          { background: var(--badge-blue-bg);    color: var(--badge-blue-text); }
.status-contacted    { background: var(--badge-teal-bg);    color: var(--badge-teal-text); }
.status-primary_takeover { background: var(--badge-teal-bg); color: var(--badge-teal-text); }
.status-rejected     { background: var(--badge-red-bg);     color: var(--badge-red-text); }
.status-scam         { background: var(--badge-red-bg);     color: var(--badge-red-text); }
.status-sent         { background: var(--badge-yellow-bg);  color: var(--badge-yellow-text); }
.status-proposal_sent { background: var(--badge-orange-bg); color: var(--badge-orange-text); }
.status-outreach_queued  { background: var(--badge-purple-bg); color: var(--badge-purple-text); }
.status-outreach_sent    { background: var(--badge-purple-bg); color: var(--badge-purple-text); }
.status-outreach_replied { background: var(--badge-green-bg);  color: var(--badge-green-text); }
.status-warm_lead    { background: var(--badge-orange-bg);  color: var(--badge-orange-text); }
.status-cold_lead    { background: var(--badge-gray-bg);    color: var(--badge-gray-text); }
.status-done         { background: var(--badge-green-bg);   color: var(--badge-green-text); }

/* Table row hover */
tr:hover td {
    background: var(--color-row-hover);
}

/* Theme toggle button */
.theme-toggle {
    width: 30px;
    height: 30px;
    margin: auto auto 0.5rem;
    padding: 0;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    cursor: pointer;
    color: #a0aec0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.theme-toggle:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.25);
}

.theme-toggle svg {
    width: 15px;
    height: 15px;
}

.sidebar-user {
    text-align: center;
    padding: 0.75rem 0.5rem 0.6rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 0.25rem;
}
.sidebar-avatar {
    width: 2.2rem;
    height: 2.2rem;
    margin: 0 auto 0.4rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 2.2rem;
    letter-spacing: 0;
}
.sidebar-username {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #e2e8f0;
}
.sidebar-role {
    display: inline-block;
    font-size: 0.55rem;
    color: #a78bfa;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: rgba(139,92,246,0.15);
    padding: 0.1rem 0.45rem;
    border-radius: 3px;
    margin-top: 0.2rem;
}
.sidebar-logout {
    text-align: center;
    padding: 0 0.75rem;
    margin: 0;
}
.sidebar-logout-btn {
    width: 100%;
    padding: 0.25rem !important;
    font-size: 0.75rem !important;
    margin: 0 !important;
}

.sidebar-version {
    font-size: 0.65rem;
    color: rgba(160, 174, 192, 0.5);
    text-align: center;
    padding-bottom: 0.75rem;
    letter-spacing: 0.05em;
}

/* Rules section header (normalizer settings modal) */
.rules-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

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

/* Channels toolbar */
.channels-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}
.toolbar-left { display: flex; gap: 0.5rem; align-items: center; flex: 1; }
.toolbar-right { display: flex; gap: 0.5rem; align-items: center; }

/* Channel row states */
tr.row-inactive { opacity: 0.5; }
tr.row-inactive:hover { opacity: 0.75; }
tr.row-banned { border-left: 3px solid var(--badge-red-text); }

/* htmx swap fade-out */
tr.htmx-swapping { opacity: 0; transition: opacity 0.5s ease; }

/* Status legend */
.status-legend {
    margin-bottom: 1rem;
    font-size: 0.73rem;
    color: var(--color-muted);
}
.status-legend summary {
    cursor: pointer;
    user-select: none;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.legend-grid {
    display: grid;
    grid-template-columns: auto 1fr auto 1fr;
    gap: 0.3rem 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
}

/* ── Compact form reset (override Pico CSS defaults) ── */
.content input:not([type="checkbox"]):not([type="radio"]),
.content select:not(.status-select),
.content textarea,
.content button:not(.btn-sm):not(.theme-toggle):not(.sb-logs-toggle):not(.log-panel-close),
.modal-content input:not([type="checkbox"]):not([type="radio"]),
.modal-content select,
.modal-content textarea,
.modal-content button:not(.btn-sm):not(.modal-close) {
    --pico-form-element-spacing-vertical: 0;
    --pico-form-element-spacing-horizontal: 0;
    font-size: 0.78rem;
    padding: 0.25rem 0.4rem;
    margin-bottom: 0;
    line-height: 1.4;
    border-width: 1px;
    box-sizing: border-box;
}

.content input:not([type="checkbox"]):not([type="radio"]),
.content select:not(.status-select),
.content button:not(.btn-sm):not(.theme-toggle):not(.sb-logs-toggle):not(.log-panel-close),
.modal-content input:not([type="checkbox"]):not([type="radio"]),
.modal-content select,
.modal-content button:not(.btn-sm):not(.modal-close) {
    height: auto !important;
    min-height: 0 !important;
}

.content textarea,
.modal-content textarea {
    resize: vertical;
    min-height: 0 !important;
}

.content select:not(.status-select),
.modal-content select {
    padding-right: 1.6rem;
    background-position: center right 0.4rem;
    background-size: 0.75rem auto;
}

.modal-content label {
    margin-bottom: 0;
}

/* ── HTMX loading indicator ── */
.htmx-indicator {
    position: fixed;
    top: 0;
    left: 170px;
    right: 0;
    height: 2px;
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.2s;
}

.htmx-indicator .htmx-progress-bar {
    height: 100%;
    background: var(--color-accent);
    animation: htmx-progress 1.5s ease-in-out infinite;
}

@keyframes htmx-progress {
    0% { width: 0; margin-left: 0; }
    50% { width: 60%; margin-left: 20%; }
    100% { width: 0; margin-left: 100%; }
}

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

/* ── HTMX error toast ── */
.htmx-toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.8rem;
    z-index: 1100;
    animation: toast-in 0.3s ease forwards, toast-out 0.3s ease 3.7s forwards;
}

.htmx-toast-error {
    background: var(--badge-red-bg);
    color: var(--badge-red-text);
    border: 1px solid var(--badge-red-text);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ── Modal detail classes (replaces inline styles) ── */
.modal-wide { max-width: 750px; }
.modal-meta { margin-bottom: 0.5rem; }
.modal-actions { margin-top: 0.75rem; display: flex; gap: 0.5rem; justify-content: flex-end; }
.modal-media { margin-top: 0.5rem; }
.modal-media img { max-width: 100%; border-radius: 4px; margin-top: 0.25rem; }

.chain-section { margin-bottom: 0.75rem; }
.chain-label { font-size: 0.72rem; color: var(--color-muted); margin-bottom: 0.35rem; }
.chain-ancestor { border-left: 3px solid var(--color-border); padding-left: 0.6rem; margin-bottom: 0.5rem; opacity: 0.8; }
.chain-ancestor-text { max-height: 150px; }
.chain-current { border-left: 3px solid var(--btn-save-text, #68d391); padding-left: 0.6rem; }

/* ── Empty state for tables ── */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--color-muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* ── Modal form layout ── */
.modal-form-group {
    margin-bottom: 0.6rem;
}
.modal-form-group label {
    display: block;
    font-size: 0.73rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.15rem;
}
.modal-form-row {
    display: flex;
    gap: 0.5rem;
}
.modal-form-row > * {
    flex: 1;
}

/* ── Error page ── */
.error-card {
    max-width: 500px;
    margin: 80px auto;
    text-align: center;
}
.error-code {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}
.error-home-btn {
    margin-top: 1rem;
    display: inline-block;
}

/* ── Validation error text ── */
.error {
    color: var(--badge-red-text);
    font-size: 0.8rem;
}

/* ── Toast success variant ── */
.htmx-toast-success {
    background: var(--badge-green-bg);
    color: var(--badge-green-text);
    border: 1px solid var(--badge-green-text);
}
.htmx-toast-info {
    background: var(--badge-blue-bg);
    color: var(--badge-blue-text);
    border: 1px solid var(--badge-blue-text);
}

/* Workstation matching panel */
.workstation-layout {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}
.workstation-layout > #workstation-card {
    flex: 1;
    min-width: 0;
}
.workstation-matches-panel {
    width: 280px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    max-height: 100vh;
    overflow-y: auto;
}
.matches-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.match-card {
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--card-bg);
    font-size: 0.8rem;
}
.match-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.25rem;
}
.match-actions {
    margin-top: 0.35rem;
}

/* Inline editable cells */
[data-editable] {
    cursor: pointer;
}
[data-editable]:hover {
    outline: 1px dashed var(--color-accent);
    outline-offset: -1px;
}

/* ── Common inline style replacements ── */
.text-error { color: var(--badge-red-text); }
.text-small { font-size: 0.75rem; }
.text-xs { font-size: 0.7rem; }
.text-nowrap { white-space: nowrap; }
.text-prewrap { white-space: pre-wrap; }
.cell-pitch { max-width: 200px; }
.cell-wide { max-width: 20rem; }
.cell-medium { max-width: 12rem; }

/* ── Cell truncation ── */
.cell-truncate {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Hamburger menu for mobile ── */
.hamburger {
    display: none;
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 1002;
    background: #1a1a2e;
    border: 1px solid #30363d;
    border-radius: 4px;
    color: #a0aec0;
    font-size: 1.2rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    line-height: 1;
}

/* ── Mobile responsive ── */
@media (max-width: 768px) {
    .hamburger {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: -170px;
        z-index: 1001;
        transition: left 0.2s ease;
    }
    .sidebar.open {
        left: 0;
    }

    .content {
        padding: 0.75rem;
        padding-top: 2.5rem;
        padding-bottom: 32px;
    }

    .status-bar {
        left: 0;
        height: 20px;
        padding: 0 0.5rem;
    }
    .sb-left {
        gap: 0.5rem;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .sb-item .sb-text {
        display: none;
    }

    .log-panel {
        left: 0;
    }

    .htmx-indicator {
        left: 0;
    }

    .job-status {
        grid-template-columns: 1fr;
    }

    .filter-bar {
        flex-wrap: wrap;
    }

    .add-channel-form {
        flex-direction: column;
        align-items: stretch;
    }
    .add-channel-form input {
        min-width: 0;
    }

    .channels-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar-left, .toolbar-right {
        flex-wrap: wrap;
    }

    table {
        font-size: 0.72rem;
    }
    th, td {
        padding: 0.25rem 0.35rem;
    }
    .text-truncate {
        max-width: 120px;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
        padding: 0.75rem;
    }

    .workstation-layout {
        flex-direction: column;
    }
    .workstation-matches-panel {
        width: 100%;
        position: static;
        max-height: none;
        order: -1;
    }
    .workstation-matches-panel .matches-list {
        flex-direction: row;
        overflow-x: auto;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }
    .workstation-matches-panel .match-card {
        min-width: 200px;
        flex-shrink: 0;
    }
    .workstation-info-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .card {
        min-width: 100px;
    }
}

/* ── Dashboard header ── */
.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.dashboard-header h1 {
    margin: 0;
}

/* ── Workstation ── */
.workstation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.workstation-header h1 {
    margin: 0;
    font-size: 1.25rem;
}
.workstation-type-switch {
    display: flex;
    gap: 0.5rem;
}
.workstation-type-switch .badge {
    text-decoration: none;
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.workstation-type-switch .badge.active {
    opacity: 1;
    box-shadow: 0 0 0 2px var(--color-accent);
}
.workstation-type-switch .badge:hover {
    opacity: 1;
}

.workstation-card {
    max-width: 900px;
    margin: 0 auto;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
}

.workstation-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.workstation-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.workstation-info-main h3,
.workstation-info-side h3 {
    font-size: 0.75rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0 0 0.5rem;
}

.workstation-info-main dl,
.workstation-info-side dl {
    margin: 0;
    font-size: 0.8rem;
}
.workstation-info-main dt,
.workstation-info-side dt {
    color: var(--color-muted);
    font-size: 0.72rem;
    margin-top: 0.35rem;
}
.workstation-info-main dd,
.workstation-info-side dd {
    margin: 0;
    font-weight: 500;
}

.workstation-contacts {
    font-size: 0.85rem;
    word-break: break-word;
}
.workstation-contacts a {
    color: var(--color-accent);
}

.workstation-pitch {
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.workstation-section {
    margin-bottom: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}
.workstation-section h3 {
    font-size: 0.75rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0 0 0.5rem;
}

.workstation-requirements {
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 250px;
    overflow-y: auto;
    background: var(--source-text-bg);
    padding: 0.5rem;
    border-radius: 4px;
}

.workstation-raw-messages {
    max-height: 350px;
    overflow-y: auto;
}

.workstation-raw-msg {
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}
.workstation-raw-msg:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.workstation-meta {
    padding: 0.5rem 0;
    border-top: 1px solid var(--color-border);
    margin-bottom: 0.75rem;
}

.workstation-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

.workstation-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.ws-action-btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    font-weight: 600;
}
.ws-action-sent      { color: var(--badge-yellow-text); border-color: var(--badge-yellow-bg); background: var(--badge-yellow-bg); }
.ws-action-proposal_sent { color: var(--badge-orange-text); border-color: var(--badge-orange-bg); background: var(--badge-orange-bg); }
.ws-action-contacted { color: var(--badge-teal-text); border-color: var(--badge-teal-bg); background: var(--badge-teal-bg); }
.ws-action-rejected  { color: var(--badge-red-text); border-color: var(--badge-red-bg); background: var(--badge-red-bg); }
.ws-action-scam      { color: var(--badge-red-text); border-color: var(--badge-red-bg); background: var(--badge-red-bg); }
.ws-action-warm_lead { color: var(--badge-orange-text); border-color: var(--badge-orange-bg); background: var(--badge-orange-bg); }
.ws-action-cold_lead { color: var(--badge-gray-text); border-color: var(--badge-gray-bg); background: var(--badge-gray-bg); }
.ws-action-done      { color: var(--badge-green-text); border-color: var(--badge-green-bg); background: var(--badge-green-bg); }

.workstation-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-muted);
    font-size: 1rem;
}

.workstation-badges {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.workstation-badges .badge {
    text-decoration: none;
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
}

@media (max-width: 768px) {
    .workstation-info-grid {
        grid-template-columns: 1fr;
    }
}
