: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-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;
    }
}