:root {
    color-scheme: light;
    --bg: #f3f5f6;
    --paper: #ffffff;
    --paper-soft: #f7f9fa;
    --paper-muted: #eef2f3;
    --ink: #252a2d;
    --muted: #667076;
    --faint: #8a949a;
    --line: #dce2e5;
    --line-strong: #cbd4d8;
    --accent: #176b63;
    --accent-dark: #10534c;
    --accent-soft: #e3f0ee;
    --ok: #1e6f45;
    --warn: #9b5a17;
    --danger: #b33a2f;
    --danger-soft: #f7ded9;
    --shadow: 0 14px 34px rgba(31, 42, 48, 0.09);
    --shadow-soft: 0 8px 20px rgba(31, 42, 48, 0.06);
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(90deg, rgba(37, 42, 45, 0.028) 1px, transparent 1px) 0 0 / 28px 28px,
        linear-gradient(180deg, #fafbfc 0%, var(--bg) 48%, #edf1f3 100%);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 76% 0%, rgba(15, 109, 99, 0.12), transparent 34vw);
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1.12;
    letter-spacing: -0.025em;
    font-weight: 740;
}

h2 {
    margin-bottom: 14px;
    font-size: 16px;
    letter-spacing: -0.01em;
    font-weight: 720;
}

.app {
    position: relative;
    width: min(1040px, calc(100% - 40px));
    margin: 28px auto 46px;
}

.header {
    position: relative;
    margin-bottom: 18px;
    padding: 26px 30px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: linear-gradient(135deg, #ffffff 0%, #f7fafb 100%);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.header::after {
    content: "";
    position: absolute;
    right: 28px;
    bottom: 24px;
    width: 120px;
    height: 10px;
    border-top: 1px solid rgba(15, 109, 99, 0.22);
    border-bottom: 1px solid rgba(15, 109, 99, 0.22);
    opacity: 0.8;
}

.header p {
    max-width: 640px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.65;
}

.card,
.login-panel,
.session-list-panel,
.session-detail-panel {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow-soft);
}

.card {
    margin-top: 14px;
    padding: 18px;
    border-radius: var(--radius);
}

.connection-card {
    display: grid;
    gap: 16px;
}

.field-group {
    min-width: 0;
}

label,
.placeholder,
.log,
.hint,
.eyebrow {
    color: var(--muted);
}

label {
    font-size: 13px;
    font-weight: 650;
}

.eyebrow {
    display: block;
    margin-bottom: 8px;
    color: var(--accent-dark);
    font-size: 11px;
    font-weight: 760;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.hint {
    margin-bottom: 12px;
    font-size: 13px;
    line-height: 1.6;
}

input[type="text"],
input[type="password"],
textarea {
    width: 100%;
    margin-top: 8px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #ffffff;
    color: var(--ink);
    font: inherit;
    outline: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
    transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
    border-color: rgba(15, 109, 99, 0.5);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(15, 109, 99, 0.12);
}

textarea {
    resize: vertical;
}

button {
    min-height: 36px;
    padding: 8px 14px;
    border: 1px solid rgba(15, 109, 99, 0.16);
    border-radius: 10px;
    background: var(--accent);
    color: #ffffff;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(15, 109, 99, 0.16);
    transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, opacity 120ms ease;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    background: var(--accent-dark);
    box-shadow: 0 11px 22px rgba(15, 109, 99, 0.18);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:disabled {
    border-color: var(--line);
    background: var(--paper-muted);
    color: var(--faint);
    cursor: not-allowed;
    box-shadow: none;
}

button.danger {
    border-color: rgba(179, 58, 47, 0.18);
    background: var(--danger);
    box-shadow: 0 8px 18px rgba(179, 58, 47, 0.14);
}

button.danger:hover:not(:disabled) {
    background: #8f2f27;
}

.options,
.actions,
.status,
.composer {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
}

.connection-card .options,
.connection-card .actions,
.connection-card .status {
    margin-top: 0;
}

.control-strip {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px 18px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--paper-soft);
}

.control-strip .options {
    min-width: 0;
}

.control-strip .actions {
    justify-content: flex-end;
}

.options label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper-soft);
    color: var(--ink);
}

input[type="checkbox"] {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.status {
    align-items: center;
    color: var(--muted);
    font-size: 13px;
}

.status span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 23px;
    padding: 2px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper-soft);
    color: var(--muted);
    font-weight: 700;
}

.pill.good {
    border-color: rgba(30, 111, 69, 0.22);
    background: #e2f0e6;
    color: var(--ok);
}

.pill.warn {
    border-color: rgba(155, 90, 23, 0.22);
    background: #f3e8dc;
    color: var(--warn);
}

.chat-log {
    min-height: 240px;
    max-height: 430px;
    overflow-y: auto;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #f8fafb;
}

.message {
    width: fit-content;
    max-width: 82%;
    margin: 0 0 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #ffffff;
    color: var(--ink);
    box-shadow: 0 4px 12px rgba(31, 42, 48, 0.05);
}

.message.user {
    margin-left: auto;
    border-color: rgba(15, 109, 99, 0.18);
    background: var(--accent);
    color: #ffffff;
}

.message.bot {
    margin-right: auto;
}

.message .meta {
    display: block;
    margin-bottom: 4px;
    color: var(--faint);
    font-size: 12px;
}

.message.user .meta {
    color: rgba(255, 255, 255, 0.72);
}

.composer {
    align-items: flex-end;
}

.composer textarea {
    flex: 1 1 280px;
    margin-top: 0;
}

audio {
    width: 100%;
    height: 38px;
}

.log,
.json-view {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #f8fafb;
}

.log {
    min-height: 90px;
    max-height: 180px;
    overflow-y: auto;
    padding: 13px;
    font-size: 13px;
    line-height: 1.6;
}

.log-entry {
    margin-bottom: 8px;
}

.log-entry.warn {
    color: var(--warn);
}

.event-card {
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: #ffffff;
    color: var(--ink);
    box-shadow: 0 4px 12px rgba(31, 42, 48, 0.04);
}

.event-card.warn {
    border-color: rgba(155, 90, 23, 0.22);
    background: #fffaf4;
}

.event-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.event-title {
    overflow: hidden;
    color: var(--accent-dark);
    font-weight: 760;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-head time {
    flex: 0 0 auto;
    color: var(--faint);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.event-body {
    color: var(--ink);
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.event-meta {
    margin-top: 5px;
    color: var(--faint);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.event-details {
    margin-top: 8px;
    color: var(--muted);
}

.event-details summary {
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

.event-details pre {
    max-height: 180px;
    overflow: auto;
    margin: 8px 0 0;
    padding: 10px;
    border-radius: 10px;
    background: var(--paper-soft);
    color: var(--muted);
    font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
}

.hidden {
    display: none !important;
}

.console-shell {
    position: relative;
    width: min(1340px, calc(100% - 40px));
    margin: 24px auto 44px;
}

.login-panel {
    width: min(430px, 100%);
    margin: 60px auto;
    display: grid;
    gap: 12px;
    padding: 24px;
    border-radius: 18px;
}

.console-panel {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 18px;
}

.session-list-panel,
.session-detail-panel {
    min-width: 0;
    padding: 18px;
    border-radius: var(--radius);
}

.detail-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 12px;
}

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

.session-list {
    display: grid;
    gap: 10px;
    max-height: calc(100vh - 130px);
    overflow-y: auto;
}

.session-item {
    width: 100%;
    display: grid;
    gap: 4px;
    text-align: left;
    border-color: var(--line);
    border-radius: 14px;
    background: var(--paper-soft);
    color: var(--ink);
    box-shadow: none;
}

.session-item:hover:not(:disabled) {
    background: #ffffff;
    box-shadow: 0 6px 16px rgba(31, 42, 48, 0.06);
}

.session-item.active {
    border-color: rgba(15, 109, 99, 0.34);
    background: var(--accent-soft);
}

.session-item.urgent {
    position: relative;
    border-color: rgba(179, 58, 47, 0.32);
    background: var(--danger-soft);
    box-shadow: 0 8px 20px rgba(179, 58, 47, 0.1);
}

.session-item.urgent::after {
    content: "待接管";
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--danger);
    color: #ffffff;
    font-size: 11px;
    font-weight: 760;
}

.session-item strong {
    overflow-wrap: anywhere;
}

.session-item span {
    color: var(--muted);
    font-size: 12px;
}

.compact {
    margin-top: 0;
}

.console-status {
    margin-bottom: 14px;
}

.audio-strip {
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}

.audio-strip span {
    color: var(--muted);
    font-size: 13px;
}

.console-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
    gap: 18px;
    margin-top: 18px;
}

.tall {
    min-height: 320px;
    max-height: 520px;
}

.json-view {
    min-height: 320px;
    max-height: 520px;
    overflow: auto;
    margin: 0;
    padding: 13px;
    color: var(--ink);
    font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre-wrap;
}

@media (max-width: 860px) {
    .app,
    .console-shell {
        width: min(100% - 24px, 100%);
        margin-top: 16px;
    }

    .header {
        padding: 22px;
        border-radius: 16px;
    }

    .header::after {
        display: none;
    }

    .card,
    .login-panel,
    .session-list-panel,
    .session-detail-panel {
        border-radius: 16px;
    }

    .console-panel,
    .console-grid {
        grid-template-columns: 1fr;
    }

    .detail-head,
    .audio-strip {
        display: grid;
        grid-template-columns: 1fr;
    }

    .control-strip {
        grid-template-columns: 1fr;
    }

    .control-strip .actions {
        justify-content: stretch;
    }

    .control-strip .actions button {
        flex: 1 1 120px;
    }

    .message {
        max-width: 92%;
    }
}

@media (max-width: 520px) {
    .app {
        width: min(100% - 16px, 100%);
    }

    .header,
    .card {
        padding: 16px;
    }

    .control-strip {
        padding: 10px;
    }

    .options label,
    .control-strip .actions button,
    .composer button {
        flex: 1 1 100%;
        justify-content: center;
    }

    .status span {
        flex: 1 1 100%;
    }

    .composer textarea,
    .composer button {
        flex-basis: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
    }
}
