:root, [data-theme="light"] {
    --bg: #f8fafc;
    --bg-elevated: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-soft: #f1f5f9;
    --accent: #0F3054;
    --row-hover: #f8fafc;
    --row-selected: #e0f2fe;
    --input-bg: #ffffff;
}
[data-theme="dark"] {
    --bg: #020617;
    --bg-elevated: #0f172a;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --border-soft: #1e293b;
    --accent: #3989C6;
    --row-hover: #1e293b;
    --row-selected: #0c4a6e;
    --input-bg: #0b1220;
}
body {
    background-color: var(--bg);
    color: var(--text);
    overflow: hidden;
}
html { height: 100%; }
.console-shell {
    height: 100%;
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
}
.console-toolbar {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    min-height: 2.5rem;
}
.console-toolbar .btn-primary {
    font-size: 0.8rem;
    padding: 0.35rem 0.75rem;
}
.console-toolbar > #newEventBtn {
    justify-self: start;
}
.console-toolbar > #newStreamBtn {
    justify-self: end;
}
.console-toolbar-centre {
    justify-self: center;
    min-width: 11.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.console-toolbar-context {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted, #94a3b8);
    user-select: none;
}

/* Section title — brand pill (same as Control CR bar) */
.admin-context-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 0.45rem 1.15rem;
    border-radius: 0.45rem;
    text-decoration: none;
    color: #f8fafc !important;
    background: linear-gradient(135deg, #0F3054 0%, #1e5a9e 35%, #3989C6 50%, #1e5a9e 65%, #0F3054 100%);
    border: 1px solid rgba(56, 189, 248, 0.45);
    box-shadow:
        0 0 0 1px rgba(14, 165, 233, 0.15),
        0 6px 18px rgba(15, 48, 84, 0.45);
    white-space: nowrap;
    box-sizing: border-box;
}
.admin-context-title {
    cursor: default;
    user-select: none;
    pointer-events: none;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 0.8rem;
}
.console-toolbar-centre .btn-console {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 0.45rem 1.15rem;
    border-radius: 0.45rem;
    text-decoration: none;
    color: #f8fafc;
    background: linear-gradient(135deg, #0F3054 0%, #1e5a9e 35%, #3989C6 50%, #1e5a9e 65%, #0F3054 100%);
    border: 1px solid rgba(56, 189, 248, 0.45);
    box-shadow:
        0 0 0 1px rgba(14, 165, 233, 0.15),
        0 6px 18px rgba(15, 48, 84, 0.45);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.console-toolbar-centre .btn-console:hover {
    filter: brightness(1.08);
    box-shadow:
        0 0 0 1px rgba(56, 189, 248, 0.35),
        0 8px 22px rgba(30, 64, 175, 0.55);
    transform: translateY(-1px);
}
.console-toolbar-centre .btn-console[hidden] {
    /* legacy — prefer is-idle so the bar does not jump */
    display: none !important;
}
.console-toolbar-centre .btn-console.is-idle {
    visibility: hidden;
    pointer-events: none;
}
.console-panels {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}
.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--border);
}
.panel:last-child { border-right: none; }

.panel-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 1rem 1.15rem;
}
.form-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.25rem;
    scrollbar-gutter: stable;
}
.action-band {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0;
    border-top: 1px solid var(--border);
}
.table-block {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}
.table-block-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.45rem;
}
.table-scroll {
    height: 16rem;
    max-height: 16rem;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
}

#crmBlock { display: none; }
#crmBlock.visible { display: block; }
.crm-toggle {
    display: none;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.4rem 0;
    margin-bottom: 0.45rem;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-soft);
    cursor: pointer;
    text-align: left;
}
.crm-toggle.visible { display: flex; }
.crm-toggle .chevron {
    display: inline-block;
    transition: transform 0.15s;
    font-size: 0.65rem;
}
.crm-toggle.open .chevron { transform: rotate(90deg); }
#crmInner { display: none; }
#crmInner.open { display: block; }

.form-tight label {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    margin-bottom: 0.3rem;
    line-height: 1;
    color: var(--text-muted);
}
.form-tight input,
.form-tight select,
.form-tight textarea {
    padding: 0.45rem 0.65rem;
    border-radius: 0.4rem;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.875rem;
    line-height: 1.35;
    box-sizing: border-box;
    transition: border-color 0.15s;
}
.form-tight input.badge-input {
    text-align: center;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1.2;
    color: #7dd3fc;
    background: color-mix(in srgb, var(--bg) 55%, #0c4a6e);
    border: 1px solid #0ea5e9;
    padding: 0.45rem 0.65rem;
    height: 2.35rem;
    box-sizing: border-box;
    border-radius: 0.4rem;
}
.form-tight input:focus,
.form-tight select:focus,
.form-tight textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.form-tight input[readonly] { cursor: default; }
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem 0.75rem;
    margin-bottom: 0.75rem;
    align-items: flex-end;
}
.field { display: flex; flex-direction: column; }
.w-type   { width: 10rem; }
.w-status { width: 9rem; }
.w-full   { width: 100%; }

.list-table {
    width: 100%;
    font-size: 0.82rem;
    border-collapse: collapse;
    table-layout: fixed;
}
.list-table th {
    text-align: left;
    font-weight: 500;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-elevated);
    z-index: 1;
}
.list-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.list-table tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}
.list-table tbody tr:hover td {
    filter: brightness(1.08);
}
.list-table tbody tr.selected {
    background: transparent;
    box-shadow: none;
}
.list-table tbody tr.selected td {
    box-shadow:
        inset 0 1px 0 0 var(--accent),
        inset 0 -1px 0 0 var(--accent);
}
.list-table tbody tr.selected td:first-child {
    box-shadow:
        inset 1px 0 0 0 var(--accent),
        inset 0 1px 0 0 var(--accent),
        inset 0 -1px 0 0 var(--accent);
}
.list-table tbody tr.selected td:last-child {
    box-shadow:
        inset -1px 0 0 0 var(--accent),
        inset 0 1px 0 0 var(--accent),
        inset 0 -1px 0 0 var(--accent);
}

#eventsPanel .list-table th:nth-child(1),
#eventsPanel .list-table td:nth-child(1) { width: 28%; }
#eventsPanel .list-table th:nth-child(2),
#eventsPanel .list-table td:nth-child(2) { width: 28%; }
#eventsPanel .list-table th:nth-child(3),
#eventsPanel .list-table td:nth-child(3) { width: 14%; }
#eventsPanel .list-table th:nth-child(4),
#eventsPanel .list-table td:nth-child(4) { width: 12%; }
#eventsPanel .list-table th:nth-child(5),
#eventsPanel .list-table td:nth-child(5) { width: 18%; }

#streamsPanel .list-table th:nth-child(1),
#streamsPanel .list-table td:nth-child(1) { width: 22%; }
#streamsPanel .list-table th:nth-child(2),
#streamsPanel .list-table td:nth-child(2) { width: 12%; }
#streamsPanel .list-table th:nth-child(3),
#streamsPanel .list-table td:nth-child(3) { width: 14%; }
#streamsPanel .list-table th:nth-child(4),
#streamsPanel .list-table td:nth-child(4) { width: 18%; }
#streamsPanel .list-table th:nth-child(5),
#streamsPanel .list-table td:nth-child(5) { width: 18%; }
#streamsPanel .list-table th:nth-child(6),
#streamsPanel .list-table td:nth-child(6) { width: 8%; }

#streamsTableBody tr.tl-blue td { background: transparent; }
#streamsTableBody tr.tl-amber td { background: #FF8C00; }
#streamsTableBody tr.tl-green td { background: #006400; }
#streamsTableBody tr.tl-red td { background: #8B0000; }
#streamsTableBody tr.tl-slate td { background: rgba(100, 116, 139, 0.45); }
#streamsTableBody tr.tl-amber.selected td { background: #FF8C00; }
#streamsTableBody tr.tl-green.selected td { background: #006400; }
#streamsTableBody tr.tl-red.selected td { background: #8B0000; }
#streamsTableBody tr.tl-slate.selected td { background: rgba(100, 116, 139, 0.60); }

#eventsTableBody tr.tl-blue td { background: transparent; }
#eventsTableBody tr.tl-amber td { background: #FF8C00; }
#eventsTableBody tr.tl-green td { background: #006400; }
#eventsTableBody tr.tl-red td { background: #8B0000; }
#eventsTableBody tr.tl-slate td { background: rgba(100, 116, 139, 0.45); }
#eventsTableBody tr.tl-amber.selected td { background: #FF8C00; }
#eventsTableBody tr.tl-green.selected td { background: #006400; }
#eventsTableBody tr.tl-red.selected td { background: #8B0000; }
#eventsTableBody tr.tl-slate.selected td { background: rgba(100, 116, 139, 0.60); }

#streamsTableBody tr.tl-red td.font-mono,
#streamsTableBody tr.tl-green td.font-mono,
#streamsTableBody tr.tl-amber td.font-mono,
#streamsTableBody tr.tl-slate td.font-mono {
    color: #f8fafc !important;
    font-weight: 600;
}
#streamsTableBody tr.tl-blue td.font-mono {
    color: #38bdf8;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.1rem;
    border-radius: 0.4rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: white;
    background: var(--accent);
    border: none;
    cursor: pointer;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.75rem;
    border-radius: 0.4rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
}
.btn-ghost:hover { background: var(--row-hover); }
.btn-ghost:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}
.empty-state {
    padding: 1.5rem 0.5rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-muted);
}
.check-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    color: var(--text);
    font-size: 0.85rem;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    margin-bottom: 0;
    padding-bottom: 0.3rem;
}

