:root {
    --ink: #181a1f;
    --muted: #68707d;
    --line: #dce1e8;
    --panel: #ffffff;
    --stage: #eef3f0;
    --accent: #146c5f;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: #f7f8fa;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.workspace {
    min-height: calc(100vh - 57px);
    display: grid;
    grid-template-columns: 320px minmax(360px, 1fr) 420px;
}

.persona-panel,
.chat-panel,
.admin-list,
.admin-form {
    background: var(--panel);
}

.persona-panel {
    padding: 24px;
    border-right: 1px solid var(--line);
}

.panel-header h1,
.admin-list h1 {
    font-size: 1.5rem;
    line-height: 1.15;
    margin: 6px 0 10px;
}

.panel-header p {
    color: var(--muted);
    margin: 0;
}

.eyebrow {
    color: var(--accent);
    font-size: .76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0;
}

.status-line {
    margin: 18px 0 8px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 600;
}

.status-authorized {
    border-color: #84b89f;
    color: #0f5b3d;
}

.status-pending {
    border-color: #e2bc61;
    color: #76530c;
}

.status-synthetic_only {
    border-color: #7fb5ce;
    color: #215b72;
}

.status-rejected {
    border-color: #d98b8b;
    color: #8a2222;
}

.avatar-stage {
    position: relative;
    min-height: calc(100vh - 57px);
    background: radial-gradient(circle at 50% 30%, #ffffff 0, var(--stage) 42%, #d8e2df 100%);
}

#avatarCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.avatar-hud {
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.avatar-hud span {
    background: rgba(255, 255, 255, .84);
    border: 1px solid rgba(24, 26, 31, .12);
    border-radius: 8px;
    padding: 6px 9px;
    font-size: .84rem;
}

.chat-panel {
    border-left: 1px solid var(--line);
    display: grid;
    grid-template-rows: 1fr auto;
    min-height: calc(100vh - 57px);
}

.chat-log {
    padding: 18px;
    overflow-y: auto;
}

.message {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    line-height: 1.35;
}

.message.user {
    margin-left: auto;
    background: #20242b;
    color: #fff;
}

.message.bot {
    background: #eef1f5;
}

.chat-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 14px;
    border-top: 1px solid var(--line);
}

.chat-experience {
    min-height: calc(100vh - 57px);
    display: grid;
    grid-template-columns: 300px minmax(360px, 1fr) 430px;
    grid-template-rows: auto 1fr;
    background: #f7f8fa;
}

.chat-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 22px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.chat-header h1 {
    font-size: 1.35rem;
    margin: 2px 0 0;
}

.emotion-state {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 10px;
    background: #f9fafb;
    color: var(--muted);
    min-width: 96px;
    text-align: center;
    font-weight: 600;
}

.chat-avatar {
    position: relative;
    min-height: calc(100vh - 126px);
    background: radial-gradient(circle at 50% 30%, #ffffff 0, var(--stage) 42%, #d8e2df 100%);
}

.chat-context {
    background: #fff;
    border-right: 1px solid var(--line);
    padding: 20px;
}

.chat-context p {
    color: var(--muted);
    margin-top: 8px;
}

.conversation-card {
    background: #fff;
    border-left: 1px solid var(--line);
    display: grid;
    grid-template-rows: 1fr auto auto auto;
    min-height: calc(100vh - 126px);
}

.thinking-indicator {
    color: var(--muted);
    padding: 0 16px 10px;
}

.reply-audio {
    width: calc(100% - 28px);
    margin: 0 14px 12px;
}

.admin-shell {
    min-height: calc(100vh - 57px);
    display: grid;
    grid-template-columns: 340px 1fr;
}

.admin-list {
    border-right: 1px solid var(--line);
    padding: 24px;
}

.persona-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 0;
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px solid var(--line);
}

.persona-row span {
    color: var(--muted);
    font-size: .88rem;
}

.admin-form {
    padding: 24px;
}

.auth-shell {
    min-height: calc(100vh - 57px);
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-panel {
    width: min(420px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
}

.auth-panel h1 {
    font-size: 1.35rem;
    margin-bottom: 8px;
}

.auth-panel p {
    color: var(--muted);
}

.admin-console {
    min-height: calc(100vh - 57px);
    display: grid;
    grid-template-columns: 260px 1fr;
    background: #f4f6f8;
}

.admin-sidebar {
    background: #17212b;
    color: #fff;
    padding: 22px;
}

.admin-brand {
    display: grid;
    gap: 2px;
    margin-bottom: 22px;
}

.admin-brand span {
    color: #aab6c2;
    font-size: .86rem;
}

.admin-nav {
    display: grid;
    gap: 6px;
}

.admin-nav a,
.admin-nav button {
    width: 100%;
    text-align: left;
    color: #d8e1ea;
    background: transparent;
    border: 0;
    border-radius: 8px;
    padding: 9px 10px;
    text-decoration: none;
    font: inherit;
}

.admin-nav a.active,
.admin-nav a:hover,
.admin-nav button:hover {
    background: #243241;
    color: #fff;
}

.admin-content {
    padding: 24px;
    min-width: 0;
}

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

.admin-page-title h1 {
    font-size: 1.65rem;
    margin: 3px 0 0;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.metric-card,
.admin-section {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.metric-card {
    display: grid;
    gap: 5px;
}

.metric-card span,
.metric-card small {
    color: var(--muted);
}

.metric-card strong {
    font-size: 1.35rem;
    line-height: 1.2;
}

.admin-two-col {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    gap: 16px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-heading h2,
.admin-section h2 {
    font-size: 1.05rem;
    margin: 0;
}

.admin-message-row,
.knowledge-row {
    display: grid;
    gap: 3px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}

.admin-message-row:first-of-type,
.knowledge-row:first-of-type {
    border-top: 0;
}

.admin-message-row span,
.knowledge-row p {
    color: var(--muted);
    margin: 0;
}

.admin-message-row small {
    color: #7b8490;
}

.knowledge-row {
    grid-template-columns: 1fr auto;
    align-items: start;
}

.knowledge-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.knowledge-actions form {
    margin: 0;
}

.upload-form {
    border-bottom: 1px solid var(--line);
    margin-bottom: 14px;
    padding-bottom: 14px;
}

.media-preview {
    display: grid;
    grid-template-columns: 86px 1fr;
    gap: 12px;
    align-items: center;
    border-top: 1px solid var(--line);
    padding: 12px 0;
}

.media-preview img {
    width: 86px;
    height: 64px;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f6f7f9;
}

.media-preview div {
    display: grid;
    gap: 3px;
}

.media-preview span,
.media-preview small {
    color: var(--muted);
}

.audio-preview {
    grid-template-columns: 1fr;
}

.audio-preview audio {
    width: 100%;
    max-width: 420px;
}

@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 280px 1fr;
    }

    .chat-panel {
        grid-column: 1 / -1;
        min-height: 460px;
        border-left: 0;
        border-top: 1px solid var(--line);
    }

    .metric-grid,
    .admin-two-col {
        grid-template-columns: 1fr 1fr;
    }

    .chat-experience {
        grid-template-columns: 260px 1fr;
    }

    .conversation-card {
        grid-column: 1 / -1;
        min-height: 460px;
    }
}

@media (max-width: 760px) {
    .workspace,
    .admin-shell {
        display: block;
    }

    .persona-panel,
    .admin-list {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .avatar-stage {
        min-height: 56vh;
    }

    .admin-console {
        display: block;
    }

    .admin-sidebar {
        padding: 16px;
    }

    .admin-content {
        padding: 16px;
    }

    .metric-grid,
    .admin-two-col {
        grid-template-columns: 1fr;
    }

    .admin-page-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .chat-experience {
        display: block;
    }

    .chat-avatar {
        min-height: 48vh;
    }

    .chat-context,
    .conversation-card {
        border-left: 0;
        border-right: 0;
        min-height: auto;
    }
}
