* { box-sizing: border-box; }
:root {
    --bg: #081322;
    --panel: #111d32;
    --panel-2: #172642;
    --line: #2b3d61;
    --text: #edf3ff;
    --muted: #9ba8c1;
    --blue: #58b9ff;
    --pink: #ef476f;
    --green: #42d891;
    --yellow: #ffd166;
    --red: #ff6b6b;
}
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.auth-card {
    width: min(480px, 100%);
    border: 1px solid var(--line);
    background: var(--panel);
    padding: 32px;
    border-radius: 8px;
}
.brand-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--blue);
    box-shadow: 0 0 24px var(--blue);
}
h1, h2 { margin: 0; }
.auth-card h1 { margin-top: 16px; }
.auth-card p { color: var(--muted); }
input, textarea, button {
    font: inherit;
}
input, textarea {
    width: 100%;
    background: #0b1628;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 8px;
    padding: 12px 14px;
}
button, .top-actions a, #open-link {
    border: 1px solid #31547e;
    background: #10233b;
    color: var(--text);
    border-radius: 8px;
    padding: 10px 14px;
    cursor: pointer;
    text-decoration: none;
}
button:hover, #open-link:hover {
    border-color: var(--blue);
}
.auth-card button {
    margin-top: 14px;
    width: 100%;
    background: var(--pink);
    border-color: var(--pink);
    font-weight: 700;
}
.error { color: var(--red) !important; }
.app {
    padding: 22px;
    max-width: 1680px;
    margin: 0 auto;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 18px;
}
.eyebrow {
    margin: 0 0 2px;
    color: var(--blue);
    letter-spacing: .12em;
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 700;
}
.top-actions {
    display: flex;
    gap: 10px;
}
.summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    gap: 12px;
    padding: 18px 0;
}
.summary div, .metric-grid div {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}
.summary b, .metric-grid b {
    display: block;
    font-size: 24px;
}
.summary span, .metric-grid span {
    color: var(--muted);
    font-size: 13px;
}
.layout {
    display: grid;
    grid-template-columns: 390px 1fr;
    gap: 18px;
    min-height: 70vh;
}
.companions, .detail {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--line);
}
#count-pill, #chat-model {
    color: var(--muted);
}
.companion-list {
    max-height: calc(100vh - 230px);
    overflow: auto;
    padding: 10px;
}
.companion {
    width: 100%;
    display: grid;
    grid-template-columns: 12px 1fr auto;
    align-items: center;
    gap: 12px;
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    padding: 12px;
    margin-bottom: 8px;
}
.companion.selected {
    background: var(--panel-2);
    border-color: #31547e;
}
.companion small, .companion em {
    color: var(--muted);
    font-style: normal;
}
.companion strong, .companion small {
    display: block;
}
.status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--muted);
}
.status.healthy { background: var(--green); }
.status.warning { background: var(--yellow); }
.status.error { background: var(--red); }
.status.setup { background: var(--blue); }
.detail {
    padding: 20px;
}
.empty {
    color: var(--muted);
    padding: 30px;
}
.detail-head {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
}
#detail-sub {
    margin: 4px 0 0;
    color: var(--muted);
}
.state-pill {
    display: inline-block;
    margin: 0 0 8px;
    color: #06101d;
    background: var(--muted);
    border-radius: 999px;
    padding: 2px 10px;
    font-weight: 700;
}
.state-pill.healthy { background: var(--green); }
.state-pill.warning { background: var(--yellow); }
.state-pill.error { background: var(--red); }
.state-pill.setup { background: var(--blue); }
.metric-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(130px, 1fr));
    gap: 10px;
    margin: 20px 0;
}
.metric-grid b {
    font-size: 18px;
    overflow-wrap: anywhere;
}
.hints-box, .token-box, .chat-box {
    border-top: 1px solid var(--line);
    padding-top: 18px;
    margin-top: 18px;
}
.section-head.compact {
    padding: 0 0 12px;
    border: 0;
}
.hints-list {
    display: grid;
    gap: 10px;
}
.hint {
    border: 1px solid var(--line);
    border-left: 5px solid var(--yellow);
    background: #091426;
    border-radius: 8px;
    padding: 12px 14px;
}
.hint.error {
    border-left-color: var(--red);
}
.hint.warning {
    border-left-color: var(--yellow);
}
.hint.info {
    border-left-color: var(--blue);
}
.hint strong, .hint small {
    display: block;
}
.hint small {
    color: var(--muted);
    margin-top: 2px;
}
.hint p {
    margin: 8px 0 0;
    color: var(--text);
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.hint-empty {
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 12px 14px;
}
.token-box label {
    display: block;
    font-weight: 700;
    margin-bottom: 8px;
}
.token-box p {
    color: var(--muted);
    margin: 8px 0 0;
}
.token-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}
.chat-box .section-head {
    padding: 0 0 12px;
    border: 0;
}
.chat-log {
    min-height: 260px;
    max-height: 430px;
    overflow: auto;
    background: #071120;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}
.bubble {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 10px;
    max-width: 86%;
}
.bubble.user {
    margin-left: auto;
    background: #3a2469;
}
.bubble.assistant {
    background: var(--panel-2);
}
.chat-row {
    margin-top: 12px;
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 10px;
    align-items: stretch;
}
@media (max-width: 980px) {
    .summary { grid-template-columns: repeat(2, 1fr); }
    .layout { grid-template-columns: 1fr; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .topbar, .detail-head { flex-direction: column; align-items: stretch; }
}
