:root {
    color-scheme: light;
    --bg: #eef4f8;
    --ink: #132028;
    --muted: #667784;
    --glass: rgba(255, 255, 255, 0.58);
    --glass-strong: rgba(255, 255, 255, 0.78);
    --line: rgba(255, 255, 255, 0.72);
    --stroke: rgba(48, 79, 96, 0.12);
    --accent: #0f8cff;
    --accent-2: #00c2a8;
    --danger: #d93a4a;
    --success: #16895f;
    --shadow: 0 24px 70px rgba(33, 56, 71, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.72);
    --radius: 28px;
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Microsoft YaHei", sans-serif;
    background:
        radial-gradient(circle at 10% 15%, rgba(0, 194, 168, 0.24), transparent 26rem),
        radial-gradient(circle at 80% 8%, rgba(15, 140, 255, 0.22), transparent 24rem),
        linear-gradient(145deg, #f8fbfd, var(--bg) 56%, #e9f0f4);
    letter-spacing: 0;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

.aurora {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(115deg, rgba(255, 255, 255, 0.6), transparent 34%),
        radial-gradient(circle at 55% 85%, rgba(124, 92, 255, 0.12), transparent 22rem);
    z-index: -1;
}

.glass-panel {
    border: 1px solid var(--line);
    background: var(--glass);
    box-shadow: var(--shadow);
    backdrop-filter: blur(26px) saturate(1.45);
    -webkit-backdrop-filter: blur(26px) saturate(1.45);
}

.app-shell {
    display: block;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    padding: 22px;
    overflow-x: hidden;
}

.sidebar {
    position: fixed;
    top: 22px;
    left: 22px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    width: 280px;
    height: calc(100vh - 44px);
    padding: 18px;
    border-radius: var(--radius);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    border-radius: 17px;
    color: white;
    font-weight: 800;
    background: linear-gradient(145deg, #0f8cff, #00c2a8);
    box-shadow: 0 16px 34px rgba(15, 140, 255, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

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

.brand strong {
    font-size: 21px;
}

.brand small {
    color: var(--muted);
    margin-top: 2px;
}

.nav-list {
    display: grid;
    gap: 8px;
    margin-top: 28px;
}

.sidebar-footer {
    display: grid;
    gap: 8px;
    margin-top: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid transparent;
    border-radius: 18px;
    color: #304756;
    transition: transform 160ms var(--ease-out), background 180ms var(--ease-out), border-color 180ms var(--ease-out);
}

.nav-item svg {
    width: 21px;
    height: 21px;
    flex: 0 0 auto;
}

.nav-item:hover,
.nav-item.active {
    border-color: rgba(255, 255, 255, 0.86);
    background: rgba(255, 255, 255, 0.56);
}

.nav-item:active,
.primary-button:active,
.module-card:active {
    transform: scale(0.97);
}

.main-surface {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding-left: 302px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 760;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(26px, 3vw, 42px);
    line-height: 1.08;
}

h2 {
    margin-bottom: 10px;
    font-size: clamp(24px, 2.6vw, 38px);
    line-height: 1.1;
}

h3 {
    margin-bottom: 8px;
    font-size: 21px;
}

p {
    color: var(--muted);
    line-height: 1.65;
}

.status-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.56);
    border: 1px solid rgba(255, 255, 255, 0.78);
    color: #274151;
    white-space: nowrap;
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
}

.module-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 220px;
    padding: 22px;
    border-radius: 24px;
    transition: transform 180ms var(--ease-out), background 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
}

.module-card:hover {
    transform: translateY(-4px);
    background: var(--glass-strong);
}

.module-icon {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    border-radius: 19px;
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.85);
}

.module-icon svg {
    width: 25px;
    height: 25px;
    color: var(--accent);
}

.login-body {
    display: grid;
    place-items: center;
    padding: 22px;
}

.login-wrap {
    width: min(100%, 440px);
}

.login-card {
    padding: 30px;
    border-radius: 32px;
}

.login-brand {
    margin-bottom: 30px;
}

.form-stack,
.admin-panel,
.module-admin-list {
    display: grid;
    gap: 16px;
}

label span,
.sort-input span {
    display: block;
    margin-bottom: 8px;
    color: #385264;
    font-size: 14px;
    font-weight: 680;
}

input,
textarea {
    width: 100%;
    min-width: 0;
    border: 1px solid rgba(255, 255, 255, 0.82);
    outline: none;
    border-radius: 17px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.58);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
    transition: border-color 160ms var(--ease-out), background 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

input {
    min-height: 48px;
    padding: 12px 14px;
}

textarea {
    resize: none;
    padding: 14px;
    line-height: 1.55;
}

input:focus,
textarea:focus {
    border-color: rgba(15, 140, 255, 0.45);
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 0 0 4px rgba(15, 140, 255, 0.1);
}

.primary-button {
    min-height: 48px;
    border: 0;
    border-radius: 18px;
    padding: 0 18px;
    color: white;
    font-weight: 760;
    cursor: pointer;
    background: linear-gradient(145deg, #0f8cff, #00a6d6);
    box-shadow: 0 15px 30px rgba(15, 140, 255, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.42);
    transition: transform 150ms var(--ease-out), filter 150ms var(--ease-out);
}

.primary-button:hover {
    filter: brightness(1.03);
}

.notice {
    margin-top: 22px;
    padding: 14px 16px;
    border-radius: 17px;
    border: 1px solid rgba(255, 255, 255, 0.75);
    background: rgba(255, 255, 255, 0.64);
}

.notice.error {
    color: var(--danger);
}

.notice.success {
    color: var(--success);
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    width: 100%;
    min-width: 0;
}

.admin-panel {
    width: 100%;
    min-width: 0;
    margin-top: 22px;
    padding: 22px;
    border-radius: 24px;
}

.panel-heading h2 {
    margin-bottom: 0;
    font-size: 24px;
}

.module-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 120px;
    align-items: center;
    gap: 16px;
    padding: 14px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.62);
    min-width: 0;
}

.switch-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.switch-row input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch {
    position: relative;
    width: 52px;
    height: 32px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: rgba(121, 137, 148, 0.3);
    box-shadow: inset 0 1px 3px rgba(20, 40, 55, 0.12);
    transition: background 180ms var(--ease-out);
}

.switch::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 4px 10px rgba(31, 50, 61, 0.18);
    transition: transform 180ms var(--ease-out);
}

.switch-row input:checked + .switch {
    background: linear-gradient(145deg, var(--accent), var(--accent-2));
}

.switch-row input:checked + .switch::after {
    transform: translateX(20px);
}

.switch-row strong,
.switch-row small {
    display: block;
    overflow-wrap: anywhere;
}

.switch-row small {
    margin-top: 4px;
    color: var(--muted);
}

.user-table {
    display: grid;
    gap: 10px;
}

.user-table > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 12px;
    align-items: center;
    padding: 13px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.42);
}

.user-table span,
.user-table small {
    color: var(--muted);
}

.chat-page {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 22px;
    min-width: 0;
}

.chat-shell {
    display: grid;
    grid-template-rows: auto minmax(360px, 1fr) auto;
    gap: 16px;
    height: calc(100vh - 44px);
    padding: 18px;
    border-radius: var(--radius);
}

.chat-header,
.chat-input-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chat-header h2 {
    margin-bottom: 0;
    font-size: 26px;
}

.chat-history-toggle {
    display: none;
    min-height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.78);
    border-radius: 999px;
    padding: 8px 14px;
    color: #274151;
    background: rgba(255, 255, 255, 0.56);
}

.status-dot {
    color: var(--success);
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: auto;
    padding: 8px;
}

.chat-message {
    display: flex;
}

.chat-message > div {
    max-width: min(720px, 86%);
    padding: 14px 16px;
    border-radius: 20px;
    line-height: 1.65;
    white-space: pre-wrap;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.user > div {
    color: white;
    background: linear-gradient(145deg, #0f8cff, #00a6d6);
}

.chat-message.assistant > div {
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid rgba(255, 255, 255, 0.76);
}

.chat-input-row textarea {
    min-height: 52px;
    max-height: 160px;
}

.chat-input-row .primary-button {
    flex: 0 0 92px;
}

.chat-history-panel {
    position: sticky;
    top: 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: calc(100vh - 44px);
    padding: 18px;
    border-radius: var(--radius);
    overflow: hidden;
}

.history-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.history-heading h2 {
    margin-bottom: 0;
    font-size: 23px;
}

.icon-button {
    display: none;
    width: 38px;
    height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.78);
    border-radius: 999px;
    color: #274151;
    background: rgba(255, 255, 255, 0.56);
    cursor: pointer;
}

.new-chat-button {
    flex: 0 0 auto;
}

.chat-session-list {
    display: grid;
    gap: 10px;
    overflow: auto;
    padding-right: 2px;
}

.chat-session-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: stretch;
    padding: 10px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.62);
}

.chat-session-item.active {
    background: rgba(255, 255, 255, 0.72);
    border-color: rgba(15, 140, 255, 0.24);
}

.chat-session-open,
.chat-session-delete {
    border: 0;
    background: transparent;
    cursor: pointer;
}

.chat-session-open {
    min-width: 0;
    padding: 4px;
    text-align: left;
}

.chat-session-open strong,
.chat-session-open small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-session-open strong {
    color: var(--ink);
    font-size: 15px;
}

.chat-session-open small {
    margin-top: 5px;
    color: var(--muted);
    font-size: 12px;
}

.chat-session-delete {
    align-self: center;
    min-height: 32px;
    padding: 0 10px;
    border-radius: 999px;
    color: var(--danger);
    background: rgba(255, 255, 255, 0.46);
}

.empty-history {
    padding: 18px 10px;
    color: var(--muted);
    text-align: center;
}

.chat-history-scrim {
    display: none;
}

@media (max-width: 860px) {
    .app-shell {
        padding: 12px;
    }

    .sidebar {
        position: fixed;
        inset: auto 12px 12px;
        z-index: 20;
        height: auto;
        padding: 10px;
        border-radius: 24px;
        width: auto;
    }

    .sidebar .brand,
    .sidebar-footer {
        display: none;
    }

    .nav-list {
        display: flex;
        gap: 8px;
        margin-top: 0;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .nav-list::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        justify-content: center;
        min-width: 74px;
        min-height: 52px;
        padding: 10px;
        font-size: 12px;
    }

    .nav-item svg {
        width: 20px;
        height: 20px;
    }

    .nav-item span {
        display: none;
    }

    .main-surface {
        padding-left: 0;
        padding-bottom: 88px;
    }

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

    .module-row {
        grid-template-columns: 1fr;
    }

    .user-table > div {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .chat-page {
        display: block;
    }

    .chat-shell {
        height: calc(100vh - 112px);
        min-height: 520px;
    }

    .chat-history-toggle,
    .icon-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .chat-history-panel {
        position: fixed;
        inset: auto 12px 92px 12px;
        z-index: 40;
        height: min(72vh, 620px);
        transform: translateY(calc(100% + 120px));
        transition: transform 220ms var(--ease-out);
    }

    .chat-history-panel.open {
        transform: translateY(0);
    }

    .chat-history-scrim {
        position: fixed;
        inset: 0;
        z-index: 35;
        display: block;
        pointer-events: none;
        opacity: 0;
        background: rgba(21, 35, 44, 0.24);
        transition: opacity 180ms var(--ease-out);
    }

    .chat-history-scrim.open {
        pointer-events: auto;
        opacity: 1;
    }

    .chat-input-row {
        align-items: stretch;
    }

    .chat-input-row .primary-button {
        flex-basis: 74px;
    }
}

@media (max-width: 520px) {
    .module-card {
        min-height: 186px;
    }

    .login-card {
        padding: 22px;
    }

    .chat-message > div {
        max-width: 94%;
    }
}

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

@media (prefers-reduced-transparency: reduce) {
    .glass-panel {
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}
