:root {
    color-scheme: light;
    --bg: #eef2f6;
    --rail: #141b24;
    --rail-2: #1c2633;
    --rail-3: #253142;
    --panel: #ffffff;
    --panel-soft: #f7f9fc;
    --ink: #172033;
    --muted: #667085;
    --line: #d8dee8;
    --line-soft: #e9edf4;
    --blue: #255ec7;
    --blue-dark: #17489f;
    --green: #0c7c59;
    --amber: #a86612;
    --danger: #b42318;
    --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
    --sans: "Noto Sans KR", "Malgun Gothic", Arial, sans-serif;
    --shadow: 0 16px 34px rgba(22, 32, 51, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
}

button,
textarea,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled,
textarea:disabled {
    cursor: not-allowed;
}

.app-shell {
    display: grid;
    grid-template-columns: 290px minmax(520px, 1fr) 360px;
    height: 100vh;
    min-height: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: 16px;
    background: var(--rail);
    color: #f8fafc;
    border-right: 1px solid #0e141d;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 46px;
    padding-bottom: 14px;
    border-bottom: 1px solid #2d3847;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 7px;
    background: #f8fafc;
    color: #172033;
    font-family: var(--mono);
    font-weight: 800;
}

.brand strong,
.brand span {
    display: block;
}

.brand strong {
    font-size: 15px;
    line-height: 1.25;
}

.brand div > span {
    margin-top: 2px;
    color: #aab6c7;
    font-family: var(--mono);
    font-size: 11px;
}

.sidebar-tools {
    display: grid;
    grid-template-columns: 1fr 38px;
    gap: 8px;
    padding: 14px 0 10px;
}

.runtime-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 0 14px;
    border-bottom: 1px solid #2d3847;
    color: #9daabe;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 800;
}

.history-section {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    padding-top: 14px;
}

.rail-label {
    margin: 0 0 9px;
    color: #8d9bad;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.history-list {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 7px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 1px;
}

.history-item {
    position: relative;
    display: grid;
    gap: 5px;
    width: 100%;
    min-height: 58px;
    padding: 10px 34px 10px 11px;
    border: 1px solid #2d3847;
    border-radius: 8px;
    background: var(--rail-2);
    color: #e9eef7;
    text-align: left;
}

.history-item:hover {
    border-color: rgba(151, 189, 246, 0.72);
    background: var(--rail-3);
}

.history-item.active {
    background: #f8fafc;
    border-color: #f8fafc;
    color: #101827;
}

.history-title {
    overflow: hidden;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-meta {
    overflow: hidden;
    color: #aeb9c8;
    font-size: 11px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item.active .history-meta {
    color: #667085;
}

.history-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 5px;
    color: #94a3b8;
    font-size: 16px;
    line-height: 1;
}

.history-remove:hover {
    background: rgba(148, 163, 184, 0.18);
    color: #fff;
}

.history-item.active .history-remove:hover {
    color: #1f2937;
}

.workspace {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    min-width: 0;
    min-height: 0;
    background: var(--panel);
    border-right: 1px solid var(--line);
}

.workspace-header,
.inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 74px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.title-block {
    min-width: 0;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
h3 {
    margin: 0;
    letter-spacing: 0;
}

.workspace-header h1 {
    overflow: hidden;
    max-width: 56vw;
    font-size: 20px;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inspector-header h2 {
    font-size: 17px;
    line-height: 1.3;
}

.session-badges {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
    min-width: 0;
    flex-wrap: wrap;
}

.status-badge,
.health-pill,
.agent-state,
.profile-current {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
}

.status-badge {
    background: #eef2f7;
    color: #475467;
}

.health-pill {
    background: rgba(255, 255, 255, 0.09);
    color: #d7dee9;
}

.health-pill.ok {
    background: rgba(12, 124, 89, 0.28);
    color: #bdf4dd;
}

.health-pill.degraded {
    background: rgba(168, 102, 18, 0.25);
    color: #fde68a;
}

.agent-dock {
    display: grid;
    gap: 10px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: #fbfcfe;
}

.dock-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: #475467;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.agent-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 8px;
}

.agent-option {
    display: grid;
    gap: 7px;
    min-width: 0;
    min-height: 94px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    text-align: left;
    box-shadow: 0 2px 10px rgba(23, 32, 51, 0.03);
}

.agent-option:hover {
    border-color: #9fc0f5;
    background: #f8fbff;
}

.agent-option.active {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 94, 199, 0.12);
}

.agent-option.unavailable {
    background: #f8fafc;
    color: #667085;
}

.agent-option-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.agent-option strong {
    overflow: hidden;
    min-width: 0;
    font-size: 13px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agent-state {
    flex: 0 0 auto;
    min-height: 22px;
    padding: 0 7px;
    background: #eef2f7;
    color: #475467;
}

.agent-option.available .agent-state {
    background: #e8f8f1;
    color: var(--green);
}

.agent-option.unavailable .agent-state {
    background: #fff6db;
    color: var(--amber);
}

.agent-desc {
    display: -webkit-box;
    overflow: hidden;
    color: #667085;
    font-size: 12px;
    line-height: 1.45;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.agent-option code {
    overflow: hidden;
    color: #255ec7;
    font-family: var(--mono);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-bar {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 28px;
    overflow-x: auto;
}

.profile-current {
    background: #eef4ff;
    color: #1f4f99;
}

.profile-bar button {
    flex: 0 0 auto;
    min-height: 28px;
    padding: 0 9px;
    border: 1px solid #a7d9ca;
    border-radius: 999px;
    background: #fff;
    color: var(--green);
    font-size: 12px;
    font-weight: 800;
}

.profile-bar button:hover {
    background: #ecfdf7;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 11px;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
    background:
        linear-gradient(#fbfcfe, #fbfcfe) padding-box,
        repeating-linear-gradient(0deg, rgba(37, 94, 199, 0.05) 0, rgba(37, 94, 199, 0.05) 1px, transparent 1px, transparent 34px);
}

.conversation-empty {
    display: grid;
    place-items: center;
    align-self: center;
    gap: 6px;
    margin: auto;
    color: #667085;
    text-align: center;
}

.conversation-empty strong {
    color: #344054;
    font-size: 16px;
}

.conversation-empty span {
    font-size: 13px;
}

.message {
    display: grid;
    gap: 6px;
    max-width: min(88%, 720px);
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: #273244;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: 0 3px 12px rgba(23, 32, 51, 0.04);
}

.message.user {
    align-self: flex-end;
    background: #eaf2ff;
    border-color: #bdd2f5;
}

.message.assistant {
    align-self: flex-start;
}

.message.system {
    align-self: center;
    max-width: 96%;
    background: #fff8e8;
    border-color: #ead6a7;
    color: #73510a;
    font-size: 12px;
    box-shadow: none;
}

.message-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: #667085;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 800;
}

.message.user .message-head {
    color: #315c95;
}

.message.system .message-head {
    color: #8a6416;
}

.message-text {
    min-width: 0;
}

.composer {
    display: grid;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid var(--line);
    background: var(--panel);
}

.composer textarea {
    width: 100%;
    min-height: 92px;
    resize: vertical;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 10px 11px;
    color: var(--ink);
    background: #fff;
}

.composer textarea:focus {
    outline: 2px solid rgba(37, 94, 199, 0.18);
    border-color: var(--blue);
}

.composer-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.primary-button,
.file-button,
.ghost-button,
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 800;
}

.primary-button {
    padding: 0 13px;
    background: var(--blue);
    color: #fff;
}

.primary-button:hover {
    background: var(--blue-dark);
}

.primary-button:disabled {
    opacity: 0.55;
}

.file-button,
.ghost-button {
    padding: 0 12px;
    background: #fff;
    color: #334155;
    border-color: #cbd5e1;
}

.file-button:hover,
.ghost-button:hover {
    background: #f8fafc;
}

.file-button.disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.icon-button {
    width: 38px;
    padding: 0;
    background: var(--rail-2);
    color: #f8fafc;
    border-color: #2d3847;
    font-family: var(--mono);
    font-size: 16px;
}

.icon-button:hover {
    background: var(--rail-3);
}

.inspector {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--panel-soft);
}

.inspector-header {
    flex: 0 0 auto;
}

.inspect-section {
    display: grid;
    gap: 10px;
    min-height: 0;
    padding: 14px;
    border-bottom: 1px solid var(--line);
}

.inspect-section.grow {
    flex: 1 1 auto;
}

.inspect-section h3 {
    color: #344054;
    font-size: 13px;
    line-height: 1.35;
}

.detail-list {
    display: grid;
    grid-template-columns: 102px minmax(0, 1fr);
    gap: 7px 10px;
    margin: 0;
    font-size: 12px;
    line-height: 1.45;
}

.detail-list dt {
    color: #667085;
    font-weight: 800;
}

.detail-list dd {
    min-width: 0;
    margin: 0;
    color: #1f2937;
    overflow-wrap: anywhere;
}

.response-json {
    flex: 1 1 auto;
    min-height: 190px;
    max-height: 38vh;
    margin: 0;
    overflow: auto;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101827;
    color: #dce7f7;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.action-list {
    display: grid;
    gap: 7px;
    max-height: 210px;
    overflow: auto;
}

.action-item {
    display: grid;
    grid-template-columns: minmax(72px, 0.34fr) minmax(0, 1fr);
    gap: 8px;
    padding: 8px 9px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    font-size: 12px;
}

.action-item code {
    color: #1e4d9a;
    font-family: var(--mono);
    font-weight: 800;
    overflow-wrap: anywhere;
}

.action-item span {
    color: #344054;
    overflow-wrap: anywhere;
}

.empty-state,
.agent-empty {
    margin: 0;
    color: #98a2b3;
    font-size: 13px;
}

.agent-empty {
    padding: 12px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: #fff;
}

@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: 270px minmax(480px, 1fr);
    }

    .inspector {
        display: none;
    }
}

@media (max-width: 860px) {
    body {
        overflow: auto;
    }

    .app-shell {
        display: block;
        height: auto;
        min-height: 100vh;
    }

    .sidebar,
    .workspace,
    .inspector {
        min-height: 360px;
    }

    .inspector {
        display: flex;
    }

    .history-list {
        max-height: 260px;
    }

    .workspace {
        grid-template-rows: auto auto minmax(340px, 52vh) auto;
    }

    .workspace-header,
    .inspector-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .workspace-header h1 {
        max-width: 100%;
        white-space: normal;
    }

    .agent-picker {
        grid-template-columns: 1fr;
    }

    .composer-actions,
    .session-badges {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

@media (max-width: 520px) {
    .sidebar,
    .workspace-header,
    .agent-dock,
    .messages,
    .composer,
    .inspect-section,
    .inspector-header {
        padding-left: 12px;
        padding-right: 12px;
    }

    .sidebar-tools {
        grid-template-columns: 1fr 36px;
    }

    .message {
        max-width: 100%;
    }

    .detail-list,
    .action-item {
        grid-template-columns: 1fr;
    }
}
