:root {
    --bg: #09090b;
    --sidebar: #111113;
    --border: #27272a;
    --text: #e4e4e7;
    --text-dim: #71717a;
    --accent: #d4d4d8;
    --highlight: #22c55e;
    --council: #f59e0b;
    --adv: #8b5cf6;
    --danger: #ef4444;
    --font-mono: 'Space Mono', monospace;
    --font-mono: 'Space Mono', monospace;
    --font-body: 'Inter', sans-serif;
}

body.light-mode {
    --bg: #f4f4f5;
    --sidebar: #ffffff;
    --border: #e4e4e7;
    --text: #18181b;
    --text-dim: #52525b;
    --accent: #27272a;
    --highlight: #16a34a;
}

body.light-mode .card {
    background: #fff;
    border-color: #e4e4e7;
}

body.light-mode .card-body {
    color: #333;
    opacity: 1;
}

body.light-mode .msg.user {
    background: #e4e4e7;
    color: #000;
}

body.light-mode .msg.assistant {
    color: #000;
    /* Darker text for readability */
}

body.light-mode textarea {
    background: #fff;
    color: #000;
}

body.light-mode .section-head {
    color: #333;
    font-weight: bold;
}



body.light-mode blockquote {
    border-left-color: #e4e4e7;
    color: #555;
    background: #fff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    height: 100vh;
    height: 100dvh;
    /* Dynamic Viewport Height for Mobile */
    margin: 0;
    overflow: hidden;
    font-size: 13px;
}

/* Responsive Utilities */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: flex !important;
}

.app-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Header */
header {
    height: auto;
    min-height: 50px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    padding-top: env(safe-area-inset-top, 0);
    /* Dynamic Island */
    background: var(--sidebar);
    flex-shrink: 0;
    font-family: var(--font-mono);
}

#mobile-mode-select {
    /* Style is handled by .mobile-only for display */
    background: rgba(20, 20, 20, 0.8);
    border: 1px solid #333;
    color: #fff;
    padding: 5px 10px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    margin-left: 10px;
    outline: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
}

.indicator.online {
    background: var(--highlight);
    box-shadow: 0 0 8px var(--highlight);
}

.uuid-badge {
    font-size: 10px;
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Mode Select */
.mode-select {
    display: flex;
    gap: 2px;
    background: #000;
    border: 1px solid var(--border);
    padding: 2px;
    border-radius: 4px;
}

.mode-select button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: var(--font-mono);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    padding: 4px 10px;
    cursor: pointer;
    transition: 0.2s;
    border-radius: 2px;
}

.mode-select button:hover {
    color: var(--text);
}

.mode-select button.active {
    background: #333;
    color: var(--text);
    font-weight: bold;
}

#btn-cls.active {
    background: #3f3f46;
    color: var(--council);
}

#btn-council.active {
    background: #3f3f46;
    color: var(--council);
}

#btn-adv.active {
    background: #3f3f46;
    color: var(--adv);
    box-shadow: 0 0 5px rgba(139, 92, 246, 0.2);
}

#btn-set {
    font-size: 16px;
    padding: 8px 12px;
}

.workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    height: 100%;
}

aside {
    width: 300px;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    flex-shrink: 0;
    font-family: var(--font-mono);
}

.hidden {
    display: none !important;
}

/* Sidebar Elements */
.tab-header {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 15px;
}

.tab-header button {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 8px;
    font-family: var(--font-mono);
    font-size: 10px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab-header button.active {
    color: var(--text);
    border-bottom-color: var(--highlight);
    font-weight: bold;
}

.tab-header button:hover {
    color: var(--text);
}

.section-head {
    font-size: 10px;
    color: var(--text-dim);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}

select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px;
    font-family: var(--font-mono);
    outline: none;
    cursor: pointer;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 8px;
    cursor: pointer;
    width: 100%;
    font-family: var(--font-mono);
    font-size: 11px;
    transition: 0.2s;
}

.btn-ghost:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.sys-status {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: auto;
}

/* Advanced Settings Panel */
#panel-adv-settings {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #333;
}

.adv-setting-group {
    margin-bottom: 12px;
    font-size: 11px;
}

.adv-setting-group label {
    display: block;
    color: #aaa;
    margin-bottom: 4px;
    font-family: var(--font-mono);
}

.adv-setting-group .row-spread {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sub-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    padding-left: 8px;
    border-left: 2px solid #333;
}

.sub-control input[type=range] {
    flex: 1;
    height: 4px;
}

.val-display {
    font-family: var(--font-mono);
    color: var(--adv);
    width: 20px;
    text-align: right;
}

.model-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 11px;
}

.counter {
    display: flex;
    gap: 5px;
}

.cnt-btn {
    background: var(--border);
    border: none;
    color: var(--text);
    width: 24px;
    cursor: pointer;
}

.cnt-val {
    width: 20px;
    text-align: center;
    color: var(--council);
    font-weight: bold;
}

.param-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 11px;
}

.tri-toggle {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--border);
}

.tri-toggle span {
    padding: 4px 8px;
    cursor: pointer;
    color: var(--text-dim);
}

.tri-toggle span.active {
    background: var(--border);
    color: var(--text);
}

/* Confidence Meter */
.conf-meter-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    position: relative;
}

.conf-bar-bg {
    flex: 1;
    height: 10px;
    background: #222;
    border-radius: 2px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.conf-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #f59e0b, #22c55e);
    transition: width 0.5s ease;
}

.conf-val {
    font-size: 12px;
    font-weight: bold;
    color: var(--council);
    width: 35px;
    text-align: right;
}

.conf-icon {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid var(--text-dim);
    color: var(--text-dim);
    font-size: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: help;
}

.conf-tooltip {
    position: absolute;
    bottom: 100%;
    right: 0;
    width: 250px;
    background: #18181b;
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 4px;
    font-size: 10px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

/* Chat Area */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg);
    height: 100%;
}

#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* Messages */
.msg {
    max-width: 800px;
    line-height: 1.6;
    font-size: 14px;
}

.msg.user {
    align-self: flex-end;
    text-align: right;
    color: var(--text);
    background: #18181b;
    padding: 10px 15px;
    border-radius: 8px;
    border-bottom-right-radius: 2px;
    max-width: 80%;
}

.msg.assistant {
    align-self: flex-start;
    color: #d4d4d8;
    padding-left: 15px;
    border-left: 2px solid var(--border);
    width: 100%;
}

.msg.system {
    align-self: center;
    color: var(--text-dim);
    font-size: 11px;
    font-family: var(--font-mono);
    border: none;
}

.msg.leader-final {
    border-color: var(--council);
    background: #131313;
    padding: 15px;
    border-radius: 8px;
    border-left: 3px solid var(--council);
    width: 100%;
}

/* Advanced Leader Styling */
.msg.leader-final.adv {
    border-left-color: var(--adv);
    background: #121016;
}

.adv-meta-header {
    font-family: var(--font-mono);
    color: var(--adv);
    font-size: 11px;
    padding-bottom: 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid #333;
    letter-spacing: 0.5px;
}

.adv-main-answer {
    font-size: 15px;
    color: #fff;
    margin-bottom: 10px;
}

.adv-details-toggle {
    font-size: 10px;
    color: #666;
    cursor: pointer;
    display: inline-block;
    margin-top: 5px;
    text-decoration: underline;
}

.adv-details-box {
    background: #000;
    padding: 10px;
    border: 1px solid #333;
    margin-top: 10px;
    font-size: 11px;
    color: #aaa;
    border-radius: 4px;
}

.leader-summary {
    font-size: 11px;
    color: var(--council);
    margin-bottom: 10px;
    font-family: var(--font-mono);
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
    font-style: italic;
}

.msg-warning {
    color: var(--council);
    font-size: 11px;
    font-weight: bold;
    margin-bottom: 5px;
    display: block;
}

.minority-reports {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #333;
}

.minority-head {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: bold;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.minority-item {
    font-size: 11px;
    color: #aaa;
    margin-bottom: 4px;
    padding-left: 8px;
    border-left: 2px solid #333;
}

body.light-mode .adv-details-box {
    background: #f4f4f5;
    border-color: #e4e4e7;
    color: #555;
}

body.light-mode .leader-summary {
    border-bottom-color: #e4e4e7;
}

body.light-mode .minority-reports {
    border-top-color: #e4e4e7;
}

body.light-mode .minority-item {
    border-left-color: #e4e4e7;
    color: #666;
}

body.light-mode .conf-tooltip {
    background: #fff;
    border-color: #e4e4e7;
    color: #333;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

body.light-mode .conf-icon {
    border-color: #e4e4e7;
    color: #555;
    background: #fff;
}

/* Markdown Styling */
.msg-content h1,
.msg-content h2,
.msg-content h3 {
    margin-top: 10px;
    margin-bottom: 5px;
    font-size: 1.1em;
    color: #fff;
}

.msg-content p {
    margin-bottom: 10px;
}

.msg-content code {
    background: #27272a;
    padding: 2px 4px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.9em;
    color: #e4e4e7;
}

.msg-content pre {
    background: #111;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid var(--border);
}

.msg-content pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

/* Council Stream Cards */
#council-dash {
    height: 25vh;
    background: #0f0f10;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: height 0.2s;
}

.dash-head {
    padding: 5px 10px;
    font-size: 10px;
    color: var(--council);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    display: flex;
    justify-content: space-between;
}

#stream-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    grid-auto-rows: 1fr;
    /* Firefox fix: removed minmax */
    gap: 4px;
    padding: 10px;
    overflow-y: auto;
    min-height: 0;
    /* Firefox flex child fix */
}

.card {
    background: #000;
    border: 1px solid #333;
    padding: 4px;
    display: flex;
    flex-direction: column;
    font-family: var(--font-mono);
    overflow: hidden;
    position: relative;
    height: 100%;
    /* Firefox fix: stretch to fill grid cell */
}

.card.running {
    border-color: var(--council);
}

.card.running.adv {
    border-color: var(--adv);
}

.card-header {
    font-weight: bold;
    font-size: 9px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #888;
    border-bottom: 1px solid #222;
    margin-bottom: 2px;
}

.card-body {
    flex: 1;
    min-height: 0;
    /* Firefox fix: allows flex child to shrink */
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: none;
    /* Hide scrollbar for aesthetics */
    color: #444;
    font-size: 7px;
    line-height: 8px;
    word-break: break-all;
    opacity: 0.8;
}

.card-body pre {
    margin: 0;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
    white-space: pre-wrap;
    word-break: break-all;
}

#stream-grid::-webkit-scrollbar {
    width: 6px;
}

#stream-grid::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

/* Input */
.input-bar {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    background: var(--bg);
    flex-shrink: 0;
    align-items: flex-end;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    width: 45px;
    height: 45px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: 0.2s;
    border-radius: 4px;
}

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

#preview-area {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 4px;
    max-width: 100px;
    display: none;
}

#preview-area.visible {
    display: flex !important;
}

#preview-img {
    width: 30px;
    height: 30px;
    object-fit: cover;
    border-radius: 2px;
}

textarea {
    flex: 1;
    background: #18181b;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px;
    font-family: var(--font-mono);
    resize: none;
    outline: none;
    height: 45px;
    scrollbar-width: none;
    /* Firefox */
}

textarea::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

textarea:focus {
    border-color: var(--text-dim);
}

#send-btn {
    background: var(--text);
    color: var(--bg);
    border: none;
    padding: 0 20px;
    font-family: var(--font-mono);
    font-weight: 700;
    cursor: pointer;
}

#send-btn:hover {
    background: #fff;
}

/* History List Item */
.history-item {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-dim);
    transition: all 0.2s;
    user-select: none;
    /* Prevent text selection */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:hover {
    background: #111;
    color: var(--text);
}

.history-item.active {
    background: #222;
    color: #fff;
    font-weight: bold;
}

.del-chat {
    color: #555;
    font-weight: bold;
    padding: 0 5px;
}

.del-chat:hover {
    color: var(--danger);
}

#history-list-std {
    max-height: none !important;
    overflow: visible !important;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-box {
    background: var(--sidebar);
    border: 1px solid var(--border);
    width: 300px;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-header {
    font-family: var(--font-mono);
    font-weight: bold;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
}

.close-modal {
    cursor: pointer;
}

.setting-row {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    padding: 8px;
    width: 100%;
    cursor: pointer;
    font-family: var(--font-mono);
    border-radius: 4px;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Light Mode Specific Overrides */
body.light-mode #council-dash {
    background: #f4f4f5;
    border-top-color: #e4e4e7;
}

body.light-mode .card {
    background: #fff;
    border-color: #e4e4e7;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

body.light-mode .card-header {
    color: #666;
    border-bottom-color: #f4f4f5;
}

body.light-mode #send-btn {
    background: #18181b;
    color: #fff;
    border: 1px solid #18181b;
}

body.light-mode #send-btn:hover {
    background: #333;
}

body.light-mode .mode-select {
    background: #e4e4e7;
    border-color: #d4d4d8;
}

body.light-mode .mode-select button.active {
    background: #fff;
    color: #000;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

body.light-mode #btn-adv.active {
    background: #fff;
    color: var(--adv);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-box {
    background: var(--sidebar);
    border: 1px solid var(--border);
    width: 300px;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-header {
    font-family: var(--font-mono);
    font-weight: bold;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
}

.close-modal {
    cursor: pointer;
}

.setting-row {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    padding: 8px;
    width: 100%;
    cursor: pointer;
    font-family: var(--font-mono);
    border-radius: 4px;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Light Mode Specific Overrides */
body.light-mode #council-dash {
    background: #f4f4f5;
    border-top-color: #e4e4e7;
}

body.light-mode .card {
    background: #fff;
    border-color: #e4e4e7;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

body.light-mode .card-header {
    color: #666;
    border-bottom-color: #f4f4f5;
}

body.light-mode #send-btn {
    background: #18181b;
    color: #fff;
    border: 1px solid #18181b;
}

body.light-mode #send-btn:hover {
    background: #333;
}

body.light-mode .mode-select {
    background: #e4e4e7;
    border-color: #d4d4d8;
}

body.light-mode .mode-select button.active {
    background: #fff;
    color: #000;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

body.light-mode #btn-adv.active {
    background: #fff;
    color: var(--adv);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2147483647;
}

.modal-box {
    background: var(--sidebar);
    border: 1px solid var(--border);
    width: 300px;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-header {
    font-family: var(--font-mono);
    font-weight: bold;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
}

.close-modal {
    cursor: pointer;
}

.setting-row {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    padding: 8px;
    width: 100%;
    cursor: pointer;
    font-family: var(--font-mono);
    border-radius: 4px;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Responsive Utilities */
/* Mobile & Responsive */
@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }

    .app-layout {
        overflow: hidden;
        position: relative;
    }

    aside {
        position: absolute;
        height: 100%;
        width: 85%;
        max-width: 320px;
        z-index: 200;
        left: -100%;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform: translateX(0);
        border-right: 1px solid var(--border);
        background: var(--sidebar);
        box-shadow: none;
    }

    aside.mobile-visible {
        transform: translateX(100%);
        /* Moves it from -100% (relative to itself? No, wait) */
        /* Actually simpler: Left is -100%. We need to change logic slightly. */
        /* Let's stick to left transition for simplicity or use translateX */
        left: 0;
        transform: none;
        box-shadow: 10px 0 50px rgba(0, 0, 0, 0.5);
    }

    /* Overlay for sidebar */
    #sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    #sidebar-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }

    main {
        width: 100%;
        padding-bottom: 0;
        /* Input bar handles its own spacing */
    }

    .brand {
        font-size: 14px;
    }

    /* Mobile: Stick input bar to bottom and handle keyboard */
    .input-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        z-index: 100;
        border-top: 1px solid var(--border);
        padding: 10px;
        background: rgba(24, 24, 27, 0.95);
        /* translucent */
        backdrop-filter: blur(10px);
        padding-bottom: env(safe-area-inset-bottom, 20px);
        /* iOS Home bar */
    }

    .input-bar textarea {
        font-size: 16px;
        /* Prevents iOS zoom */
        border-radius: 20px;
        padding-left: 15px;
    }

    /* Adjust main content padding to account for input bar */
    #chat-container {
        padding-bottom: 80px;
        /* Base padding */
    }

    /* Mobile: Larger Touch Targets */
    .btn-icon,
    .btn-ghost,
    button {
        min-height: 44px;
        min-width: 44px;
    }

    .setting-row input[type=checkbox] {
        transform: scale(1.3);
    }

    /* Modal fixes */
    .modal-box {
        width: 90%;
        max-height: 85vh;
        overflow-y: auto;
        padding: 20px;
    }

    /* Turnstile Mobile Fix */
    #turnstile-widget {
        transform: scale(0.85);
        transform-origin: center top;
        margin-left: -5px;
    }

    /* Hide some non-critical UI elements if needed */
    .uuid-badge {
        display: none;
    }
}

/* Sidebar Collapsed (Desktop) */
aside.collapsed {
    width: 0;
    padding: 0;
    border: none;
    overflow: hidden;
}

/* Metrics Display */
.msg-metrics {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #333;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.metric-item {
    display: flex;
    gap: 4px;
}

.metric-label {
    opacity: 0.7;
}

.metric-val {
    color: var(--council);
    font-weight: bold;
}

/* Turnstile Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-box {
    background: var(--sidebar);
    border: 1px solid var(--border);
    padding: 30px;
    border-radius: 0;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text);
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal-btn {
    width: 45px;
    height: 45px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
}

.close-modal-btn:hover {
    background: #f4f4f5;
    transform: translateY(-1px);
}

body.light-mode .close-modal-btn {
    background: #fff;
    border-color: #e4e4e7;
    color: #333;
}

body.light-mode .close-modal-btn:hover {
    background: #f4f4f5;
}

/* Force light mode code background */
body.light-mode pre {
    background: #f4f4f5 !important;
    color: #333 !important;
}

body.light-mode .code-block-wrapper {
    background: #f4f4f5 !important;
    border-color: #e4e4e7;
}

body.light-mode .code-header {
    background: #e4e4e7 !important;
    border-bottom-color: #d4d4d8;
}

.modal-body {
    color: var(--text);
}

/* Input Bar Enhancements */
.input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 15px;
    border-top: 1px solid var(--border);
    background: var(--sidebar);
}

.input-bar textarea {
    flex: 1;
    resize: none;
    height: 45px;
    min-height: 45px;
    max-height: 200px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    overflow-y: auto;
}

.input-bar textarea:focus {
    outline: none;
    border-color: var(--highlight);
}

#send-btn {
    height: 45px;
    min-width: 80px;
    padding: 0 20px;
    background: #fff;
    color: #000;
    border: 1px solid var(--border);
    border-radius: 0;
    font-weight: 700;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    letter-spacing: 0.5px;
}

#send-btn:hover {
    background: #f4f4f5;
    transform: translateY(-1px);
}

#send-btn:active {
    transform: translateY(0);
}

.btn-icon {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0;
    color: var(--text);
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
}

/* Code Block & Copy Button */
.code-block-wrapper {
    position: relative;
    border-radius: 6px;
    background: #111;
    border: 1px solid var(--border);
    margin: 10px 0;
    overflow: hidden;
}

body.light-mode .code-block-wrapper {
    background: #f4f4f5;
    border-color: #e4e4e7;
}

pre {
    position: relative;
    padding: 10px;
    margin: 0;
    border-radius: 0;
    background: inherit;
    border: none;
    overflow-x: auto;
    color: inherit;
    /* Let highlighting theme decide */
}

.code-header {
    display: flex;
    justify-content: flex-end;
    background: rgba(255, 255, 255, 0.05);
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
}

body.light-mode .code-header {
    background: #e4e4e7;
    border-bottom-color: #d4d4d8;
}

.copy-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 11px;
    cursor: pointer;
    font-family: var(--font-mono);
    display: flex;
    align-items: center;
    gap: 5px;
    transition: color 0.2s;
}

.copy-btn:hover {
    color: var(--text);
}

.copy-btn svg {
    width: 14px;
    height: 14px;
}

.btn-icon:hover {
    border-color: var(--highlight);
    background: var(--sidebar);
}

/* Settings Gear Button */
.controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.gear-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 18px;
}

.gear-btn:hover {
    border-color: var(--highlight);
    background: var(--sidebar);
    transform: rotate(90deg);
}

/* Settings Modal Fixes */
#settings-modal .modal-box {
    max-width: 450px;
    text-align: left;
}

#settings-modal .setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border);
}

#settings-modal .setting-row:last-child {
    border-bottom: none;
    padding-top: 20px;
    justify-content: center;
}

#settings-modal .setting-row label,
#settings-modal .setting-row span {
    text-align: left;
    flex: 1;
    font-size: 14px;
}

#settings-modal .btn-danger {
    width: 100%;
    max-width: 300px;
}

/* Mobile Settings Button Fix */
.mobile-settings-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 0;
    margin-left: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-settings-btn svg {
    width: 16px;
    height: 16px;
}

/* Mobile Select Alignment Fix */
#mobile-mode-select {
    height: 32px;
    line-height: normal;
    /* Fix vertical alignment */
}

/* Improved Close Button (Desktop - Matches .btn-icon) */
.close-modal-btn {
    width: 45px;
    height: 45px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
}

.close-modal-btn:hover {
    background: #f4f4f5;
    transform: translateY(-1px);
}

body.light-mode .close-modal-btn {
    background: #fff;
    border-color: #e4e4e7;
    color: #333;
}

body.light-mode .close-modal-btn:hover {
    background: #f4f4f5;
}

/* LIGHT MODE OVERRIDES - NUCLEAR OPTION V3 */
@media screen {

    /* 1. Code Blocks */
    body.light-mode pre,
    body.light-mode code,
    body.light-mode .hljs,
    body.light-mode .code-block-wrapper pre,
    body.light-mode .code-block-wrapper code {
        background-color: #f4f4f5 !important;
        color: #222 !important;
        border: none !important;
        text-shadow: none !important;
    }

    body.light-mode .code-block-wrapper {
        background: #f4f4f5 !important;
        border-color: #e4e4e7 !important;
    }

    body.light-mode .code-header {
        background: #e4e4e7 !important;
        border-bottom-color: #d4d4d8 !important;
        color: #333 !important;
    }

    /* 2. Council Elements (Container) */
    html body.light-mode div.msg.leader-final,
    html body.light-mode div.msg.leader-final.adv,
    body.light-mode .msg-content .leader-final {
        background-color: #f4f4f5 !important;
        border: 1px solid #e4e4e7 !important;
        border-left: 3px solid #e4e4e7 !important;
        color: #333 !important;
        box-shadow: none !important;
    }

    /* 3. Council Inner Elements (Crucial for text visibility) */
    html body.light-mode .adv-main-answer {
        color: #111 !important;
    }

    html body.light-mode .adv-meta-header {
        color: #666 !important;
        border-bottom-color: #ccc !important;
    }

    html body.light-mode .adv-details-box {
        background: #fff !important;
        color: #444 !important;
        border-color: #ddd !important;
    }

    html body.light-mode .msg-warning {
        color: #b91c1c !important;
    }

    html body.light-mode .leader-summary {
        color: #555 !important;
        border-bottom-color: #ccc !important;
    }

    html body.light-mode .minority-reports,
    html body.light-mode .minority-item {
        border-color: #e4e4e7 !important;
        color: #666 !important;
    }

    body.light-mode .metric-val {
        color: #000 !important;
    }
}



/* ============================================================
   COUNCIL PLANNING -- Complete Redesign (n8n-inspired)
   ============================================================ */

/* --- Container --- */
#council-planning {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    background: #0a0a0c;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999 !important;
    font-family: var(--font-body);
}

#council-planning.hidden {
    display: none !important;
}

/* --- Toolbar --- */
.planning-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: #111113;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    gap: 10px;
    height: 48px;
    flex-shrink: 0;
    z-index: 300;
}

.planning-toolbar-left,
.planning-toolbar-center,
.planning-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.planning-toolbar-left {
    position: relative;
}

.planning-title-icon {
    font-size: 16px;
    color: var(--council);
    opacity: 0.8;
}

#planning-flow-name {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 6px;
    width: 180px;
    transition: all 0.2s;
}

#planning-flow-name:hover {
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
}

#planning-flow-name:focus {
    border-color: var(--council);
    outline: none;
    background: rgba(255, 255, 255, 0.03);
}

.planning-template-select {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.planning-template-select:hover {
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text);
}

.planning-toolbar-sep {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.06);
    margin: 0 4px;
}

.planning-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}

.planning-btn:hover {
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

.planning-btn-run {
    color: #22c55e;
    border-color: rgba(34, 197, 94, 0.25);
    font-weight: 700;
}

.planning-btn-run:hover {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.5);
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.1);
}

.planning-btn-stop {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.25);
}

.planning-btn-stop:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.5);
}

.planning-btn-exit {
    color: var(--text-dim);
}

.planning-btn-exit:hover {
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
}

.planning-btn-sm {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 12px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.planning-btn-sm:hover {
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

.planning-zoom-controls {
    display: flex;
    gap: 2px;
}

/* --- Main Workspace --- */
.planning-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    background: #08080a;
}

/* --- Canvas --- */
#drawflow-canvas {
    flex: 1;
    height: 100%;
    background-color: #0c0c0e;
    background-image: radial-gradient(circle, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 28px 28px;
    touch-action: none;
    outline: none;
    cursor: grab;
}

#drawflow-canvas .parent-drawflow,
#drawflow-canvas .drawflow,
#drawflow-canvas .precanvas,
#drawflow-canvas svg {
    width: 100% !important;
    height: 100% !important;
}

#drawflow-canvas:active {
    cursor: grabbing;
}

body.planning-pan-active #drawflow-canvas,
body.planning-pan-active #drawflow-canvas * {
    cursor: grabbing !important;
}

/* --- Node Palette --- */
.planning-node-palette {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 200px;
    background: rgba(17, 17, 19, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 12px;
    z-index: 120;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    max-height: calc(100% - 24px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

.planning-node-palette::-webkit-scrollbar {
    width: 4px;
}

.planning-node-palette::-webkit-scrollbar-track {
    background: transparent;
}

.planning-node-palette::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
}

.palette-section {
    margin-bottom: 16px;
}

.palette-section:last-child {
    margin-bottom: 0;
}

.palette-title {
    font-family: var(--font-mono);
    font-size: 9px;
    color: rgba(255, 255, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding-bottom: 8px;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-weight: 600;
}

.palette-item {
    padding: 7px 10px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    cursor: grab;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.12s;
    border: 1px solid transparent;
    margin-bottom: 2px;
}

.palette-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.06);
}

.palette-item:active {
    cursor: grabbing;
}

.palette-icon {
    font-size: 13px;
    width: 16px;
    text-align: center;
}

/* --- Properties Panel --- */
.planning-props {
    position: absolute;
    top: 12px;
    right: 12px;
    bottom: 12px;
    height: auto;
    width: 0;
    background: rgba(17, 17, 19, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.15s;
    z-index: 101;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

.planning-props.open {
    width: 320px;
    opacity: 1;
    pointer-events: auto;
}

.planning-props-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 1px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.planning-props-header .close-modal-btn {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: transparent;
    border-radius: 6px;
}

.planning-props-header .close-modal-btn:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.04);
}

.planning-props-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

.planning-props-body::-webkit-scrollbar {
    width: 4px;
}

.planning-props-body::-webkit-scrollbar-track {
    background: transparent;
}

.planning-props-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
}

.planning-props-empty {
    color: var(--text-dim);
    text-align: center;
    margin-top: 40px;
    font-size: 12px;
    font-family: var(--font-mono);
    opacity: 0.5;
}

/* ===================== */
/* NODE STYLING (n8n-inspired) */
/* ===================== */

.drawflow .drawflow-node {
    background: #16161a;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
    min-width: 240px;
    padding: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4), 0 0 0 0px transparent;
    /* NO transition on transform/position — this prevents the heavy/sluggish feel */
    transition: box-shadow 0.2s, border-color 0.2s;
    z-index: 2;
    overflow: visible;
}

.drawflow .drawflow-node:hover {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.drawflow .drawflow-node.selected {
    border-color: rgba(245, 158, 11, 0.5) !important;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.15), 0 8px 30px rgba(0, 0, 0, 0.5) !important;
    background: #16161a !important;
    /* Override Drawflow's red */
    z-index: 10;
}

/* --- Node Header (Top Color Bar + Title) --- */
.df-head {
    padding: 10px 14px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    border-top: 3px solid var(--nc, #71717a);
    /* Color accent as top bar */
    border-left: none;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.02);
    cursor: grab;
    user-select: none;
    border-radius: 9px 9px 0 0;
    color: var(--text);
}

.df-head:active {
    cursor: grabbing;
}

/* Remove the cluttery ⓘ icon */
.df-head::after {
    display: none;
}

.df-ic {
    font-size: 14px;
    opacity: 0.7;
}

/* --- Node Body --- */
.df-body {
    padding: 12px 14px;
}

/* --- Node Textarea (Input node query) --- */
.df-ta {
    width: 100%;
    min-height: 60px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 8px 10px;
    border-radius: 6px;
    line-height: 1.5;
    resize: none;
    transition: border-color 0.15s;
}

.df-ta:focus {
    border-color: rgba(245, 158, 11, 0.4);
    outline: none;
}

.df-ta::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

/* --- Node Select/Input fields --- */
.df-sel,
.df-inp {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 11px;
    font-family: var(--font-mono);
    padding: 6px 8px;
    border-radius: 5px;
    width: 100%;
    transition: border-color 0.15s;
    appearance: none;
    -webkit-appearance: none;
}

.df-sel:focus,
.df-inp:focus {
    border-color: rgba(245, 158, 11, 0.4);
    outline: none;
}

.df-sel {
    cursor: pointer;
}

.df-lbl {
    display: block;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.35);
    margin: 10px 0 4px 0;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

.df-lbl:first-child {
    margin-top: 0;
}

.df-desc {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    margin-top: 6px;
    line-height: 1.4;
}

.df-prompt-key {
    font-size: 10px;
    color: rgba(245, 158, 11, 0.6);
    font-family: var(--font-mono);
    margin-top: 6px;
    padding: 3px 6px;
    background: rgba(245, 158, 11, 0.05);
    border-radius: 4px;
    display: inline-block;
}

/* --- Output Labels --- */
.df-outs {
    padding: 6px 14px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.df-ol {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.35);
    font-family: var(--font-mono);
    display: flex;
    align-items: center;
    gap: 4px;
}

.df-odot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--nc, #71717a);
    opacity: 0.5;
}

/* --- Execution Stream inside nodes --- */
.df-stream {
    font-family: var(--font-mono);
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    padding: 8px 14px;
    max-height: 120px;
    overflow-y: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.4;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.06) transparent;
}

.df-stream::-webkit-scrollbar {
    width: 3px;
}

.df-stream::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
}

/* --- Node Execution States --- */
.drawflow .drawflow-node.node-running {
    border-color: rgba(34, 197, 94, 0.5) !important;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.12), 0 4px 20px rgba(0, 0, 0, 0.4) !important;
    animation: nodeRunPulse 1.5s ease-in-out infinite;
}

@keyframes nodeRunPulse {

    0%,
    100% {
        box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.12), 0 4px 20px rgba(0, 0, 0, 0.4);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.2), 0 4px 24px rgba(34, 197, 94, 0.1);
    }
}

.drawflow .drawflow-node.node-done {
    border-color: rgba(34, 197, 94, 0.4) !important;
    box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.1), 0 2px 12px rgba(0, 0, 0, 0.3) !important;
}

.drawflow .drawflow-node.node-done .df-head {
    border-top-color: #22c55e;
}

.drawflow .drawflow-node.node-error {
    border-color: rgba(239, 68, 68, 0.5) !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15), 0 4px 20px rgba(0, 0, 0, 0.4) !important;
}

.drawflow .drawflow-node.node-error .df-head {
    border-top-color: #ef4444;
}

/* --- Ports / Handles --- */
.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
    background: #1e1e22;
    border: 2px solid rgba(255, 255, 255, 0.2);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    transition: all 0.12s;
    top: auto;
    cursor: crosshair;
}

.drawflow .drawflow-node .input {
    left: -8px;
}

.drawflow .drawflow-node .output {
    right: -8px;
}

.drawflow .drawflow-node .input:hover,
.drawflow .drawflow-node .output:hover {
    background: var(--council);
    border-color: var(--council);
    transform: scale(1.25);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
}

/* --- Connections --- */
.drawflow .connection .main-path {
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 2px;
    transition: stroke 0.15s, stroke-width 0.15s;
    opacity: 1;
}

.drawflow .connection .main-path:hover {
    stroke: rgba(255, 255, 255, 0.5);
    stroke-width: 2.5px;
    cursor: pointer;
}

.drawflow .connection .main-path.selected {
    stroke: var(--council);
    stroke-width: 2.5px;
    opacity: 1;
}

/* --- Status Bar --- */
.planning-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: #111113;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    font-family: var(--font-mono);
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    height: 28px;
    flex-shrink: 0;
    z-index: 20;
}

/* --- Flows Dropdown --- */
.planning-flows-dropdown {
    position: absolute;
    top: 52px;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    background: rgba(17, 17, 19, 0.95);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 8px;
    z-index: 9999;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.7);
}

.flow-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text);
    transition: background 0.1s;
}

.flow-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.flow-item button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.flow-item button:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.flow-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-dim);
    font-size: 11px;
    font-family: var(--font-mono);
}

/* --- Responsive (hide on small screens) --- */
@media (max-width: 900px) {
    #council-planning::after {
        content: "Planning Mode requires a larger screen.";
        position: fixed;
        inset: 0;
        background: #0a0a0c;
        z-index: 99999;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-dim);
        font-family: var(--font-mono);
        padding: 40px;
        text-align: center;
        font-size: 13px;
    }
}

/* ===================== */
/* PROPERTY PANEL STYLES */
/* ===================== */

.prop-grp {
    margin-bottom: 14px;
}

.prop-grp label {
    display: block;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.35);
    margin-bottom: 5px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.prop-ta,
.prop-inp,
.prop-sel {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 7px 10px;
    border-radius: 6px;
    transition: border-color 0.15s;
}

.prop-ta {
    min-height: 80px;
    resize: vertical;
    line-height: 1.5;
}

.prop-ta:focus,
.prop-inp:focus,
.prop-sel:focus {
    border-color: rgba(245, 158, 11, 0.4);
    outline: none;
}

.prop-btn {
    width: 100%;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 7px;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 6px;
    transition: all 0.15s;
}

.prop-btn:hover {
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text);
    background: rgba(255, 255, 255, 0.03);
}

.prop-btn-save {
    border-color: rgba(34, 197, 94, 0.3);
    color: #22c55e;
}

.prop-btn-save:hover {
    background: rgba(34, 197, 94, 0.06);
    border-color: rgba(34, 197, 94, 0.5);
}

.prop-btn-reset {
    border-color: rgba(239, 68, 68, 0.2);
    color: rgba(239, 68, 68, 0.6);
}

.prop-btn-reset:hover {
    background: rgba(239, 68, 68, 0.06);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
}

.prop-btn-sm {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.12s;
}

.prop-btn-sm:hover {
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text);
}

.prop-info-box {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    line-height: 1.5;
    padding: 10px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    margin-bottom: 14px;
}

.prop-info {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.3);
    padding: 8px;
}

.prop-preview {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.35);
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    border-radius: 6px;
    margin-top: 6px;
    max-height: 100px;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.03);
    line-height: 1.4;
    font-family: var(--font-mono);
}

.prop-pk {
    font-size: 10px;
    color: rgba(245, 158, 11, 0.6);
    font-family: var(--font-mono);
    padding: 3px 6px;
    background: rgba(245, 158, 11, 0.05);
    border-radius: 4px;
}

.prop-out {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    border-radius: 6px;
    max-height: 150px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: var(--font-mono);
    line-height: 1.4;
    border: 1px solid rgba(255, 255, 255, 0.03);
    margin: 0;
}

.prop-hint {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.25);
    font-family: var(--font-mono);
}

.prop-var-row {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

/* --- Prompt Editor --- */
.prompt-ed {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.prompt-ed-hdr {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.prompt-ed-key {
    font-size: 11px;
    color: rgba(245, 158, 11, 0.7);
    font-family: var(--font-mono);
    font-weight: 600;
}

.prompt-ed-mod {
    font-size: 9px;
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    letter-spacing: 0.5px;
}

.prompt-ed-ta {
    width: 100%;
    min-height: 350px;
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    color: #a3e635;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 12px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    line-height: 1.6;
    resize: none;
    transition: border-color 0.15s;
}

.prompt-ed-ta:focus {
    border-color: rgba(163, 230, 53, 0.3);
    outline: none;
}

.prompt-ed-vars {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.3);
    margin-top: 8px;
    line-height: 1.6;
}

.prompt-ed-vars code {
    font-size: 10px;
    color: rgba(245, 158, 11, 0.5);
    background: rgba(245, 158, 11, 0.05);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--font-mono);
}

.prompt-ed-btns {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.prompt-ed-btns .prop-btn {
    flex: 1;
}

/* --- Light Mode Overrides --- */
body.light-mode #council-planning {
    background: #fafafa;
}

body.light-mode .planning-toolbar {
    background: #fff;
    border-bottom-color: #e5e7eb;
}

body.light-mode .planning-toolbar-sep {
    background: #e5e7eb;
}

body.light-mode .planning-btn {
    border-color: #e5e7eb;
    color: #6b7280;
}

body.light-mode .planning-btn:hover {
    background: #f9fafb;
    border-color: #d1d5db;
    color: #374151;
}

body.light-mode #planning-flow-name {
    color: #111;
}

body.light-mode #planning-flow-name:hover {
    border-color: #d1d5db;
    background: #f9fafb;
}

body.light-mode .planning-template-select {
    background: #fff;
    border-color: #e5e7eb;
    color: #6b7280;
}

body.light-mode #drawflow-canvas {
    background-color: #fafafa;
    background-image: radial-gradient(circle, rgba(0, 0, 0, 0.06) 1px, transparent 1px);
}

body.light-mode .drawflow .drawflow-node {
    background: #fff;
    border-color: #e5e7eb;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

body.light-mode .drawflow .drawflow-node:hover {
    border-color: #d1d5db;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

body.light-mode .drawflow .drawflow-node.selected {
    border-color: rgba(245, 158, 11, 0.5) !important;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.12), 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    background: #fff !important;
}

body.light-mode .df-head {
    background: #f9fafb;
    border-bottom-color: #e5e7eb;
    color: #111;
}

body.light-mode .df-body {
    color: #333;
}

body.light-mode .df-ta,
body.light-mode .df-sel,
body.light-mode .df-inp {
    background: #f4f4f5;
    border-color: #e5e7eb;
    color: #111;
}

body.light-mode .df-lbl {
    color: #9ca3af;
}

body.light-mode .df-desc {
    color: #9ca3af;
}

body.light-mode .planning-node-palette {
    background: rgba(255, 255, 255, 0.92);
    border-color: #e5e7eb;
}

body.light-mode .palette-title {
    color: #9ca3af;
    border-bottom-color: #e5e7eb;
}

body.light-mode .palette-item {
    color: #6b7280;
}

body.light-mode .palette-item:hover {
    background: #f3f4f6;
    color: #111;
    border-color: #e5e7eb;
}

body.light-mode .planning-props {
    background: rgba(255, 255, 255, 0.95);
    border-color: #e5e7eb;
}

body.light-mode .planning-props-header {
    border-bottom-color: #e5e7eb;
    color: #111;
}

body.light-mode .prop-ta,
body.light-mode .prop-inp,
body.light-mode .prop-sel {
    background: #f4f4f5;
    border-color: #e5e7eb;
    color: #111;
}

body.light-mode .prop-btn {
    border-color: #e5e7eb;
    color: #6b7280;
}

body.light-mode .prop-btn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
    color: #111;
}

body.light-mode .prop-info-box {
    background: #f9fafb;
    border-color: #e5e7eb;
    color: #6b7280;
}

body.light-mode .planning-status-bar {
    background: #fff;
    border-top-color: #e5e7eb;
    color: #9ca3af;
}

body.light-mode .drawflow .drawflow-node .input,
body.light-mode .drawflow .drawflow-node .output {
    background: #fff;
    border-color: #d1d5db;
}

body.light-mode .drawflow .connection .main-path {
    stroke: #d1d5db;
}

body.light-mode .drawflow .connection .main-path:hover {
    stroke: #6b7280;
}

body.light-mode .prompt-ed-ta {
    background: #f4f4f5;
    color: #166534;
    border-color: #e5e7eb;
}

/* --- Settings Popover --- */
.planning-settings-popover {
    position: absolute;
    top: 44px;
    left: 0;
    width: 220px;
    background: rgba(17, 17, 19, 0.97);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 12px;
    z-index: 500;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.planning-settings-popover.hidden {
    display: none;
}

.settings-popover-title {
    font-family: var(--font-mono);
    font-size: 9px;
    color: rgba(255, 255, 255, 0.35);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding-bottom: 10px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-weight: 600;
}

.settings-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 0;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    position: relative;
}

.settings-toggle-row:hover {
    color: var(--text);
}

.settings-toggle-row input[type="checkbox"] {
    display: none;
}

.settings-toggle-slider {
    width: 32px;
    height: 18px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 9px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.settings-toggle-slider::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    top: 2px;
    left: 2px;
    transition: transform 0.2s, background 0.2s;
}

.settings-toggle-row input:checked+.settings-toggle-slider {
    background: rgba(245, 158, 11, 0.3);
}

.settings-toggle-row input:checked+.settings-toggle-slider::after {
    transform: translateX(14px);
    background: var(--council);
}

body.light-mode .planning-settings-popover {
    background: rgba(255, 255, 255, 0.97);
    border-color: #e5e7eb;
}

body.light-mode .settings-popover-title {
    color: #9ca3af;
    border-bottom-color: #e5e7eb;
}

body.light-mode .settings-toggle-row {
    color: #6b7280;
}

body.light-mode .settings-toggle-row:hover {
    color: #111;
}

body.light-mode .settings-toggle-slider {
    background: #e5e7eb;
}

body.light-mode .settings-toggle-slider::after {
    background: #9ca3af;
}

/* --- Select Dropdown Dark Styling --- */
.planning-template-select option {
    background: #111113;
    color: #e5e5e5;
}

.planning-template-select option:disabled {
    color: #666;
}

/* --- Node Drag Area Fix --- */
/* Make node wrapper width match content so invisible areas don't block canvas pan */
.drawflow .drawflow-node {
    width: auto !important;
    min-width: 220px;
    max-width: 320px;
}

.planning-docs-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 600;
    padding: 20px;
}

.planning-docs-card {
    width: min(980px, 96vw);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: #0f0f12;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.planning-docs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.6px;
}

.planning-docs-body {
    overflow: auto;
    padding: 16px;
    display: grid;
    gap: 16px;
}

.planning-docs-section {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    padding: 12px;
}

.planning-docs-section h4 {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.6px;
    margin-bottom: 8px;
    color: #f3f4f6;
}

.planning-docs-section p,
.planning-docs-section li {
    font-size: 12px;
    line-height: 1.55;
    color: #d4d4d8;
}

.planning-docs-section ul {
    margin: 8px 0 0 16px;
    display: grid;
    gap: 6px;
}

.planning-docs-kv {
    display: grid;
    grid-template-columns: 210px 1fr;
    gap: 8px;
    align-items: start;
    font-size: 12px;
    margin-top: 8px;
}

@media (max-width: 900px) {
    .planning-docs-kv {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}

.planning-docs-code {
    font-family: var(--font-mono);
    color: #f59e0b;
    word-break: break-all;
}

body.light-mode .planning-docs-card {
    background: #ffffff;
    border-color: #e5e7eb;
}

body.light-mode .planning-docs-header {
    border-bottom-color: #e5e7eb;
    color: #111827;
}

body.light-mode .planning-docs-section {
    background: #f9fafb;
    border-color: #e5e7eb;
}

body.light-mode .planning-docs-section h4 {
    color: #111827;
}

body.light-mode .planning-docs-section p,
body.light-mode .planning-docs-section li {
    color: #374151;
}

body.light-mode .planning-docs-code {
    color: #b45309;
}
