* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-0: #f7fbff;
    --bg-1: #eef6ff;
    --panel: rgba(255, 255, 255, 0.78);
    --panel-strong: rgba(255, 255, 255, 0.94);
    --line: rgba(37, 99, 235, 0.14);
    --line-strong: rgba(0, 174, 239, 0.32);
    --text: #102033;
    --muted: #5d728a;
    --muted-strong: #344a61;
    --cyan: #00aeef;
    --blue: #2563eb;
    --violet: #7c3aed;
    --green: #22c55e;
    --red: #ef4444;
    --amber: #ffb020;
    --warm: #ff7a59;
    --radius-lg: 32px;
    --radius-md: 22px;
    --shadow-glow: 0 26px 90px rgba(37, 99, 235, 0.14);
}

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg-0);
    color: var(--text);
}

body::before {
    position: fixed;
    inset: 0;
    z-index: -2;
    content: "";
    background:
        radial-gradient(circle at 12% 18%, rgba(0, 174, 239, 0.22), transparent 30%),
        radial-gradient(circle at 80% 14%, rgba(255, 122, 89, 0.16), transparent 28%),
        radial-gradient(circle at 62% 82%, rgba(124, 58, 237, 0.12), transparent 34%),
        linear-gradient(135deg, #ffffff 0%, #f4faff 46%, #eef4ff 100%);
}

body::after {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    content: "";
    background-image:
        linear-gradient(rgba(37, 99, 235, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(37, 99, 235, 0.045) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.62), transparent);
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.login-wrapper {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 32px;
}

.login-box {
    position: relative;
    width: min(440px, 100%);
    padding: 42px;
    overflow: hidden;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(240, 248, 255, 0.86));
    border: 1px solid var(--line);
    border-radius: 36px;
    box-shadow: var(--shadow-glow), 0 28px 80px rgba(16, 32, 51, 0.12);
    backdrop-filter: blur(20px);
}

.login-box::before {
    position: absolute;
    inset: 0;
    pointer-events: none;
    content: "";
    border-radius: inherit;
    background:
        linear-gradient(135deg, rgba(0, 174, 239, 0.15), transparent 38%, rgba(255, 122, 89, 0.12)),
        radial-gradient(circle at top right, rgba(124, 58, 237, 0.12), transparent 32%);
}

.login-logo {
    position: relative;
    margin-bottom: 32px;
    text-align: center;
}

.icon-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    margin-bottom: 18px;
    color: white;
    background: linear-gradient(135deg, var(--cyan), var(--blue) 52%, var(--warm));
    border-radius: 26px;
    box-shadow: 0 18px 44px rgba(0, 174, 239, 0.24);
}

.login-logo h1 {
    font-size: 2rem;
    line-height: 1;
    letter-spacing: -0.04em;
    color: var(--text);
}

.login-logo p {
    margin-top: 10px;
    color: var(--muted);
}

.login-field {
    position: relative;
    margin-bottom: 18px;
}

.login-field label,
.field-label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.login-field input,
.action-select,
.input-box {
    width: 100%;
    color: var(--text);
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--line);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.login-field input {
    padding: 14px 16px;
    border-radius: 14px;
}

.login-field input:focus,
.action-select:focus,
.input-container:focus-within {
    border-color: var(--cyan);
    box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.12);
}

.login-btn,
.send-btn,
.file-btn,
.logout-btn {
    border: 0;
    transition: transform 0.15s, opacity 0.2s, border-color 0.2s, background 0.2s;
}

.login-btn {
    position: relative;
    width: 100%;
    padding: 14px;
    margin-top: 8px;
    color: #fff;
    font-weight: 800;
    background: linear-gradient(135deg, var(--blue), var(--cyan) 52%, var(--warm));
    border-radius: 999px;
    box-shadow: 0 16px 32px rgba(0, 174, 239, 0.18);
}

.login-btn:hover,
.send-btn:hover,
.file-btn:hover,
.logout-btn:hover {
    transform: translateY(-1px);
}

.login-error {
    display: none;
    margin-top: 14px;
    color: #fecaca;
    font-size: 0.9rem;
    text-align: center;
}

.page-layout {
    display: grid;
    grid-template-columns: minmax(320px, 34vw) minmax(0, 1fr);
    gap: 22px;
    width: 100vw;
    height: 100vh;
    padding: 22px;
}

.avatar-section,
.chat-section {
    min-height: 0;
    overflow: hidden;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(244, 250, 255, 0.76));
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-glow), 0 22px 70px rgba(16, 32, 51, 0.1);
    backdrop-filter: blur(18px);
}

.avatar-section {
    display: flex;
    flex-direction: column;
    position: relative;
}

.avatar-stage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
}

.stage-title {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--muted);
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.stage-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--blue);
    font-size: 0.82rem;
    font-weight: 700;
}

.stage-status::before {
    width: 8px;
    height: 8px;
    content: "";
    background: var(--green);
    border-radius: 999px;
    box-shadow: 0 0 18px var(--green);
}

.avatar-iframe-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
}

#fingerDanceAvatar {
    width: 100%;
    height: 100%;
    background: transparent;
    border: 0;
}

.avatar-hint {
    padding: 14px 18px 18px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
    text-align: center;
    border-top: 1px solid var(--line);
}

#fingerDanceLoading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted-strong);
    font-weight: 700;
    background: rgba(247, 251, 255, 0.9);
    transition: opacity 300ms ease;
}

.chat-section {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.chat-header-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--line);
}

.brand-mark {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    color: white;
    background: linear-gradient(135deg, var(--blue), var(--cyan), var(--warm));
    border-radius: 18px;
    box-shadow: 0 14px 30px rgba(37, 99, 235, 0.18);
}

.module-title-wrap {
    min-width: 0;
}

.eyebrow {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

#moduleLabel {
    display: block;
    margin-top: 2px;
    font-size: 1.18rem;
    font-weight: 850;
    letter-spacing: -0.02em;
}

.module-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-left: auto;
    color: var(--blue);
    font-size: 0.82rem;
    font-weight: 800;
    background: rgba(0, 174, 239, 0.1);
    border: 1px solid rgba(0, 174, 239, 0.28);
    border-radius: 999px;
}

.logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 13px;
    color: var(--muted-strong);
    background: rgba(255, 255, 255, 0.74);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.logout-btn:hover {
    color: #fecaca;
    border-color: rgba(239, 68, 68, 0.45);
    background: rgba(127, 29, 29, 0.2);
}

.workspace-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 16px 22px 0;
}

.module-context-card,
.action-panel {
    padding: 16px;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
}

.module-context-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.context-title {
    font-weight: 850;
}

.context-copy {
    margin-top: 5px;
    color: var(--muted);
    font-size: 0.9rem;
}

.mode-badge {
    flex: none;
    padding: 8px 12px;
    color: var(--blue);
    font-size: 0.8rem;
    font-weight: 800;
    background: rgba(37, 99, 235, 0.1);
    border: 1px solid rgba(37, 99, 235, 0.22);
    border-radius: 999px;
}

.mode-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.58);
    border: 1px solid var(--line);
    border-radius: 999px;
    width: fit-content;
    max-width: 100%;
}

.mode-switcher[hidden] {
    display: none;
}

.mode-switch-btn {
    min-height: 38px;
    padding: 0 16px;
    color: var(--muted-strong);
    font-weight: 850;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    transition: transform 0.15s, color 0.2s, background 0.2s, border-color 0.2s;
}

.mode-switch-btn:hover {
    color: var(--blue);
    background: rgba(0, 174, 239, 0.08);
    border-color: rgba(0, 174, 239, 0.2);
    transform: translateY(-1px);
}

.mode-switch-btn[data-active="true"] {
    color: #fff;
    background: linear-gradient(135deg, var(--blue), var(--cyan));
    border-color: transparent;
    box-shadow: 0 10px 22px rgba(0, 174, 239, 0.18);
}

body[data-module="api_action"] .mode-badge,
body[data-module="api_action"] .module-chip {
    color: #8a3a22;
    background: rgba(255, 122, 89, 0.13);
    border-color: rgba(255, 122, 89, 0.3);
}

.action-panel {
    display: none;
    grid-template-columns: 1fr auto;
    gap: 14px;
    align-items: end;
}

body[data-module="api_action"] .action-panel {
    display: grid;
}

.action-select {
    min-height: 44px;
    padding: 0 14px;
    color-scheme: dark;
    border-radius: 12px;
}

.file-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 14px;
    color: var(--text);
    background: rgba(255, 122, 89, 0.12);
    border: 1px solid rgba(255, 122, 89, 0.32);
    border-radius: 12px;
}

.file-btn input {
    display: none;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
    padding: 18px 22px;
    overflow-y: auto;
}

.message-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: min(760px, 82%);
    width: fit-content;
}

.message-row.user {
    align-self: flex-end;
}

.message-row.bot {
    align-self: flex-start;
}

.avatar-icon {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    color: white;
    background: linear-gradient(135deg, var(--blue), var(--cyan));
    border-radius: 16px;
}

.message-row.user .avatar-icon {
    background: linear-gradient(135deg, var(--warm), var(--violet));
}

.message-bubble {
    padding: 13px 16px;
    color: var(--text);
    font-size: 0.96rem;
    line-height: 1.6;
    white-space: pre-wrap;
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid var(--line);
    border-radius: 6px 20px 20px;
    box-shadow: 0 10px 28px rgba(16, 32, 51, 0.06);
}

.message-row.user .message-bubble {
    color: white;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(0, 174, 239, 0.86));
    border-color: rgba(0, 174, 239, 0.32);
    border-radius: 20px 6px 20px 20px;
}

.message-bubble-text,
.message-json {
    white-space: pre-wrap;
}

.message-json,
.action-result {
    margin-top: 10px;
    padding: 12px;
    overflow: auto;
    color: #1e3a8a;
    font-size: 0.82rem;
    line-height: 1.5;
    background: rgba(239, 246, 255, 0.82);
    border: 1px solid rgba(37, 99, 235, 0.12);
    border-radius: 12px;
}

.sign-status-hint {
    margin: 10px 0 0;
    padding: 9px 11px;
    color: #1d4ed8;
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1.45;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.18);
    border-radius: 10px;
}

.sign-status-hint[data-state="ready"] {
    color: #047857;
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.26);
}

.sign-status-hint[data-state="failed"] {
    color: #b91c1c;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.24);
}

.input-container-wrapper {
    padding: 16px 22px 20px;
    border-top: 1px solid var(--line);
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 8px 8px 8px 18px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--line);
    border-radius: 22px;
}

.input-box {
    flex: 1;
    max-height: 140px;
    padding: 9px 0;
    resize: none;
    background: transparent;
    border: 0;
}

.input-box::placeholder {
    color: #8aa0b7;
}

.send-btn {
    display: grid;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    place-items: center;
    color: white;
    background: linear-gradient(135deg, var(--blue), var(--cyan));
    border-radius: 999px;
    box-shadow: 0 12px 24px rgba(0, 174, 239, 0.18);
}

.send-btn:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 4px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--blue);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%,
    60%,
    100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-6px);
    }
}

@media (max-width: 960px) {
    .page-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 38vh minmax(0, 1fr);
    }

    .module-context-card,
    .action-panel {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
}

html:has(.admin-body) {
    height: 100%;
    overflow: hidden;
}

.admin-body {
    height: 100%;
    min-height: 100%;
    overflow: hidden;
}

.admin-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 22px;
    width: min(1440px, 100%);
    height: 100vh;
    padding: 28px;
    margin: 0 auto;
    overflow: hidden;
}

.admin-header,
.admin-panel,
.admin-footer {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(244, 250, 255, 0.78));
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(16, 32, 51, 0.08);
    backdrop-filter: blur(18px);
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 24px;
}

.admin-header h1 {
    margin-top: 4px;
    font-size: clamp(2rem, 4vw, 3.3rem);
    line-height: 1;
    letter-spacing: -0.06em;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
}

.admin-grid {
    display: grid;
    grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
    gap: 22px;
    min-height: 0;
}

.admin-panel {
    min-width: 0;
    min-height: 0;
    padding: 22px;
    overflow: auto;
}

.admin-panel-heading,
.editor-card-title,
.admin-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.admin-panel-heading h2 {
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.admin-panel-heading p {
    margin-top: 5px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.editor-list {
    display: grid;
    gap: 16px;
    margin-top: 18px;
}

.editor-card {
    padding: 16px;
    background: rgba(255, 255, 255, 0.76);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
}

.editor-card-title {
    margin-bottom: 14px;
}

.danger-link {
    color: #b91c1c;
    background: transparent;
    border: 0;
    font-weight: 800;
}

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

.admin-field {
    display: grid;
    gap: 7px;
    margin-top: 12px;
}

.admin-field span {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.admin-field input,
.admin-field select,
.admin-field textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
}

.admin-field textarea {
    resize: vertical;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.84rem;
    line-height: 1.5;
}

.admin-field-wide {
    grid-column: 1 / -1;
}

.admin-permission-group {
    margin-top: 16px;
    padding: 14px;
    background: rgba(239, 246, 255, 0.56);
    border: 1px solid rgba(37, 99, 235, 0.12);
    border-radius: 16px;
}

.admin-permission-title {
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 850;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.admin-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
}

.admin-checkbox {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 40px;
    padding: 9px 11px;
    color: var(--text);
    font-weight: 750;
    background: rgba(255, 255, 255, 0.76);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.admin-checkbox input {
    width: 16px;
    height: 16px;
    accent-color: var(--blue);
}

.admin-empty-state {
    color: var(--muted);
    font-size: 0.9rem;
}

.admin-footer {
    padding: 16px 18px;
    flex-shrink: 0;
}

.admin-save-btn {
    width: auto;
    min-width: 180px;
    margin: 0;
    padding-inline: 24px;
}

#adminStatus {
    color: var(--muted-strong);
    font-weight: 700;
}

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

@media (max-width: 720px) {
    .admin-shell {
        padding: 16px;
    }

    .admin-header,
    .admin-panel-heading,
    .admin-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .admin-form-grid {
        grid-template-columns: 1fr;
    }
}
