/*-------------------------------------------------------
  XenMoro chat interface
-------------------------------------------------------*/
:root {
    --bg: #6f9d95;
    --panel: #183d36;
    --panel-strong: #14352f;
    --ink: #1e2522;
    --muted: #66716d;
    --line: #32584f;
    --rail: #22312d;
    --rail-soft: #2d423d;
    --accent: #0f8f74;
    --accent-strong: #0b6f5a;
    --danger: #b84b4b;
    --user: #1f4a42;
    --assistant: #204039;
    --system: #463034;
    --shadow: 0 16px 34px rgba(14, 38, 33, 0.18);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 0;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    display: flex;
    min-height: 100vh;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(111, 157, 149, 0.96), rgba(72, 116, 107, 0.98)),
        var(--bg);
}

.health-page {
    display: block;
}

.health-shell {
    width: min(980px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0;
}

.health-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.health-header h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1.1;
}

.health-link {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    font-weight: 700;
    text-decoration: none;
}

.health-link:hover {
    background: var(--accent-strong);
}

.health-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.health-card,
.health-details {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.health-card {
    min-height: 118px;
    padding: 16px;
}

.health-label {
    display: block;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.health-card strong {
    display: block;
    font-size: 24px;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.health-details {
    margin-top: 12px;
    padding: 18px;
}

.health-details-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.health-details h2 {
    margin: 0;
    font-size: 20px;
}

#health-refresh {
    min-height: 38px;
    padding: 0 12px;
    background: #e9e1d5;
    color: var(--ink);
}

#health-refresh:hover {
    background: #ded3c4;
}

.health-cog-list {
    min-height: 44px;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf8;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: clamp(220px, 17vw, 260px);
    height: 100vh;
    background: var(--rail);
    color: white;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    gap: 10px;
    padding: 12px;
    overflow-y: auto;
    z-index: 10;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 9px;
}

.brand-mark {
    position: relative;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: white;
    font-weight: 800;
    letter-spacing: 0;
    overflow: hidden;
    text-decoration: none;
    flex: 0 0 34px;
}

.brand-mark img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.brand-fallback {
    font-size: 11px;
    line-height: 1;
}

.eyebrow,
.section-label {
    margin: 0 0 5px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

#sidebar .eyebrow,
#sidebar .section-label {
    color: #a9bab4;
}

#sidebar h1,
#sidebar h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.15;
}

#conversation-title:empty {
    display: none;
}

.sidebar-section {
    padding: 9px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    background: var(--rail-soft);
}

.sidebar-section code {
    display: block;
    color: #eaf4f0;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 13px;
    font-weight: 800;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: #63d9a9;
    box-shadow: 0 0 0 4px rgba(99, 217, 169, 0.14);
}

.status-dot.busy {
    background: #f2b84b;
    box-shadow: 0 0 0 4px rgba(242, 184, 75, 0.14);
}

.status-dot.idle {
    background: #f2a34b;
    box-shadow: 0 0 0 4px rgba(242, 163, 75, 0.16);
}

.status-dot.error {
    background: var(--danger);
    box-shadow: 0 0 0 4px rgba(184, 75, 75, 0.14);
}

.model-section {
    display: grid;
    grid-template-columns: max-content;
    gap: 6px;
    align-items: end;
}

.processor-section {
    display: grid;
    grid-template-columns: max-content;
    gap: 6px;
}

.model-section p,
.processor-section p {
    grid-column: 1 / -1;
}

.model-section select,
.processor-section select {
    width: auto;
    min-height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: #eef8f4;
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    padding: 0 8px;
}

.model-section select {
    width: var(--model-select-width, auto);
    min-width: 110px;
    max-width: min(100%, 184px);
}

.processor-section select {
    width: max-content;
    min-width: 82px;
}

#model-status,
#processor-status {
    min-height: 18px;
    margin: 0;
    color: #d4e1dc;
    font-size: 12px;
    overflow-wrap: anywhere;
}

#model-status:empty,
#processor-status:empty {
    display: none;
}

.resource-section {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.resource-header,
.resource-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.resource-header .section-label {
    margin: 0;
}

.resource-header {
    grid-column: 1 / -1;
}

#resource-monitor-status {
    color: #d4e1dc;
    font-size: 12px;
    font-weight: 700;
}

.resource-item {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.resource-row span {
    color: #d4e1dc;
    font-size: 11px;
    font-weight: 700;
}

.resource-row strong {
    color: white;
    font-size: 12px;
}

.resource-meter {
    height: 5px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.11);
}

.resource-meter span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 180ms ease;
}

.resource-item small {
    min-height: 12px;
    color: #a9bab4;
    font-size: 10px;
    overflow-wrap: anywhere;
}

.resource-item canvas {
    width: 100%;
    height: 18px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-footer {
    margin-top: auto;
    color: #a9bab4;
    font-size: 13px;
}

#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-width: 0;
    height: 100vh;
    padding: 24px;
    overflow: hidden;
    margin-left: clamp(220px, 17vw, 260px);
    background:
        linear-gradient(180deg, rgba(111, 157, 149, 0.38), rgba(55, 91, 82, 0.32)),
        #6f9d95;
}

button {
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

button:disabled,
select:disabled {
    cursor: wait;
    opacity: 0.65;
}

#clear-button {
    min-width: 78px;
    height: 34px;
    padding: 0 12px;
    background: #eae01d;
    color: var(--ink);
}

#clear-button:hover {
    background: #f4ea25;
}

#chat-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(180deg, rgba(31, 74, 66, 0.82), rgba(18, 48, 42, 0.96)),
        var(--panel);
    border: 1px solid rgba(185, 218, 207, 0.16);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

#response-window {
    flex: 1;
    min-height: 360px;
    padding: 22px;
    color: #e7f2ee;
    background:
        linear-gradient(180deg, rgba(22, 53, 47, 0.92), rgba(14, 38, 33, 0.98)),
        var(--panel);
    overflow-y: auto;
    overflow-anchor: none;
    scroll-behavior: smooth;
}

#empty-state {
    height: 100%;
    min-height: 260px;
    display: grid;
    align-content: center;
    justify-items: center;
    text-align: center;
    color: #a9c2ba;
}

#empty-state h3 {
    margin: 0 0 8px;
    color: #f0f8f5;
    font-size: 22px;
}

#empty-state p {
    margin: 0;
}

#chat-input {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
    padding: 14px;
    border-top: 1px solid rgba(185, 218, 207, 0.18);
    background:
        linear-gradient(180deg, rgba(20, 53, 47, 0.96), rgba(15, 41, 36, 0.98)),
        var(--panel-strong);
}

.input-actions {
    display: grid;
    gap: 8px;
    align-self: stretch;
    align-content: end;
}

#message-input {
    width: 100%;
    min-height: 112px;
    max-height: 260px;
    resize: vertical;
    padding: 13px 14px;
    border: 1px solid rgba(185, 218, 207, 0.22);
    border-radius: 8px;
    background: #0f2924;
    color: #edf7f3;
    font: inherit;
    line-height: 1.45;
    outline: none;
}

#message-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 143, 116, 0.16);
}

#send-button {
    min-width: 78px;
    height: 42px;
    padding: 0 14px;
    background: var(--accent);
    color: white;
}

#send-button:hover {
    background: var(--accent-strong);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.message {
    position: relative;
    max-width: min(760px, 92%);
    padding: 12px 44px 12px 14px;
    margin: 0 0 14px;
    border: 1px solid rgba(185, 218, 207, 0.2);
    border-radius: 8px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message-copy-button {
    position: absolute;
    top: 8px;
    right: 8px;
    min-width: 0;
    min-height: 26px;
    padding: 0 8px;
    border: 1px solid rgba(185, 218, 207, 0.22);
    border-radius: 6px;
    background: rgba(10, 31, 27, 0.72);
    color: #d9ebe5;
    font-size: 11px;
    font-weight: 800;
    opacity: 0;
    transition: opacity 140ms ease, background 140ms ease, color 140ms ease;
}

.message:hover .message-copy-button,
.message:focus-within .message-copy-button {
    opacity: 1;
}

.message-copy-button:hover,
.message-copy-button:focus-visible {
    background: rgba(15, 143, 116, 0.92);
    color: white;
    opacity: 1;
}

.message-copy-button.copied {
    background: #63d9a9;
    color: #0d241f;
    opacity: 1;
}

.message-copy-button.copied::after {
    content: "ed";
}

.message-copy-button.copy-error {
    background: var(--danger);
    color: white;
    opacity: 1;
}

.message-label {
    display: block;
    margin-bottom: 5px;
    font-size: 12px;
    font-weight: 800;
    color: #a9c2ba;
    text-transform: uppercase;
    letter-spacing: 0;
}

.message.user {
    margin-left: auto;
    background: var(--user);
}

.message.assistant {
    margin-right: auto;
    background: var(--assistant);
}

.message.system {
    margin-right: auto;
    background: #37bc16;
    border-color: #58d33b;
    color: #092505;
}

.message.system .message-label {
    color: #0b3a05;
}

.message.pending {
    color: #c7d8d2;
    background: #193730;
}

#response-window::-webkit-scrollbar {
    width: 8px;
}

#response-window::-webkit-scrollbar-thumb {
    background: #4d746a;
    border-radius: 4px;
}

#response-window::-webkit-scrollbar-track {
    background: #0f2924;
}

@media (max-width: 1100px) {
    body {
        flex-direction: column;
        overflow: auto;
    }

    .health-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #sidebar {
        position: sticky;
        left: auto;
        width: 100%;
        height: auto;
        max-height: 46vh;
        display: grid;
        grid-template-columns: repeat(4, minmax(180px, 1fr));
        align-items: start;
        padding: 14px;
        overflow-y: auto;
    }

    .brand-block {
        min-height: 68px;
    }

    .model-section,
    .processor-section {
        grid-template-columns: max-content auto auto;
        align-items: end;
    }

    .model-section .section-label,
    .model-section p,
    .processor-section .section-label,
    .processor-section p {
        grid-column: 1 / -1;
    }

    .model-section select,
    .processor-section select {
        grid-column: auto;
    }

    .resource-section {
        grid-column: 1 / -1;
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .resource-header {
        grid-column: 1 / -1;
    }

    .resource-item canvas {
        height: 30px;
    }

    .sidebar-footer {
        display: none;
    }

    #main {
        height: calc(100vh - min(46vh, 360px));
        min-height: 560px;
        padding: 16px;
        margin-left: 0;
    }
}

@media (max-width: 820px) {
    #sidebar {
        grid-template-columns: repeat(2, minmax(170px, 1fr));
        max-height: 52vh;
    }

    .resource-section {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #main {
        height: auto;
        min-height: 620px;
    }

    #chat-input {
        grid-template-columns: 1fr;
    }

    .input-actions,
    #send-button,
    #clear-button {
        width: 100%;
    }
}

@media (max-width: 520px) {
    .health-shell {
        width: min(100% - 24px, 980px);
        padding: 20px 0;
    }

    .health-header,
    .health-details-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .health-link,
    #health-refresh {
        width: 100%;
        justify-content: center;
    }

    .health-grid {
        grid-template-columns: 1fr;
    }

    .resource-section {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #sidebar {
        grid-template-columns: 1fr;
        max-height: 58vh;
    }

    .model-section {
        grid-template-columns: max-content 1fr 1fr;
    }

    .message {
        max-width: 100%;
        padding-right: 14px;
    }

    .message-copy-button {
        position: static;
        float: right;
        margin: 0 0 8px 8px;
        opacity: 1;
    }
}
