:root {
    --bg: #071521;
    --bg-soft: #0c2032;
    --panel: rgba(11, 28, 43, 0.92);
    --panel-strong: rgba(16, 37, 57, 0.98);
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.14);
    --text: #eef6ff;
    --muted: #a5bbcf;
    --accent: #19c7b5;
    --accent-strong: #0ca89a;
    --accent-warm: #f6b94b;
    --danger: #ef7a7a;
    --success: #36d39a;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
    --radius-lg: 24px;
    --radius-sm: 14px;
    font-family: "Trebuchet MS", "Segoe UI Variable", "Gill Sans", sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    min-height: 100%;
    background:
        radial-gradient(circle at top left, rgba(25, 199, 181, 0.16), transparent 28%),
        radial-gradient(circle at top right, rgba(246, 185, 75, 0.16), transparent 20%),
        linear-gradient(180deg, #071521 0%, #0a1b29 100%);
    color: var(--text);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 34px 34px;
    pointer-events: none;
    opacity: 0.25;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: #6ce4d7;
}

img {
    max-width: 100%;
    display: block;
}

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

.page-auth,
.page-install,
.page-admin {
    padding: 28px;
}

.auth-layout,
.install-layout,
.admin-layout {
    max-width: 1200px;
    margin: 0 auto;
}

.auth-layout {
    min-height: calc(100vh - 56px);
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 28px;
    align-items: center;
}

.auth-layout.single-column {
    grid-template-columns: minmax(320px, 560px);
    justify-content: center;
}

.hero-panel,
.card,
.install-card {
    background: var(--panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.hero-panel {
    padding: 42px;
}

.hero-panel h1 {
    font-size: clamp(2.2rem, 5vw, 4rem);
    margin-bottom: 12px;
}

.hero-panel p {
    color: var(--muted);
    font-size: 1.05rem;
    max-width: 54ch;
}

.hero-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 26px;
}

.hero-list span,
.hero-badge,
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
}

.hero-badge {
    color: var(--accent-warm);
    margin-bottom: 18px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.72rem;
}

.card,
.install-card {
    padding: 28px;
}

.auth-card {
    max-width: 520px;
    width: 100%;
    justify-self: end;
}

.field,
.checkbox-field,
.file-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field span,
.checkbox-field span {
    color: var(--muted);
    font-size: 0.95rem;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font: inherit;
    outline: none;
    transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    border-color: rgba(25, 199, 181, 0.7);
    background: rgba(255, 255, 255, 0.06);
    transform: translateY(-1px);
}

.checkbox-field {
    flex-direction: row;
    align-items: center;
}

.checkbox-field input {
    width: auto;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 0;
    border-radius: 14px;
    padding: 14px 18px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: #06211c;
    box-shadow: 0 18px 32px rgba(25, 199, 181, 0.22);
}

.btn-secondary {
    background: rgba(246, 185, 75, 0.12);
    color: #ffd68a;
    border: 1px solid rgba(246, 185, 75, 0.28);
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    border: 1px solid var(--line);
}

.btn-danger {
    background: rgba(239, 122, 122, 0.12);
    color: #ffc2c2;
    border: 1px solid rgba(239, 122, 122, 0.3);
}

.btn-block {
    width: 100%;
}

.icon-btn {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
}

.muted {
    color: var(--muted);
}

.stack-md {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.auth-footer {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 18px;
    flex-wrap: wrap;
}

.flash {
    padding: 14px 16px;
    border-radius: 14px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
}

.flash-success {
    background: rgba(54, 211, 154, 0.12);
    border-color: rgba(54, 211, 154, 0.32);
}

.flash-error {
    background: rgba(239, 122, 122, 0.12);
    border-color: rgba(239, 122, 122, 0.32);
}

.install-card {
    max-width: 760px;
    margin: 8vh auto 0;
}

.checklist {
    display: grid;
    gap: 12px;
    margin: 24px 0;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--line);
}

.check-item span {
    min-width: 54px;
    font-weight: 700;
    text-align: center;
    padding: 6px 10px;
    border-radius: 999px;
}

.check-item.ok span {
    background: rgba(54, 211, 154, 0.18);
    color: #9cffd1;
}

.check-item.bad span {
    background: rgba(239, 122, 122, 0.18);
    color: #ffc3c3;
}

.install-note {
    margin-top: 22px;
    color: var(--muted);
    line-height: 1.65;
}

.chat-shell {
    height: 100vh;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    position: relative;
}

.page-chat {
    height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    min-height: 0;
    padding: 24px;
    background: rgba(8, 22, 34, 0.95);
    border-right: 1px solid var(--line);
    backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 20;
}

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

.sidebar h1 {
    font-size: 1.45rem;
    margin: 0;
}

.preset-list {
    display: grid;
    gap: 12px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.preset-card {
    text-align: left;
    width: 100%;
    padding: 16px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.035);
    color: var(--text);
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.preset-card strong {
    display: block;
    margin-bottom: 8px;
    font-size: 1rem;
}

.preset-card span {
    display: block;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.4;
}

.preset-card:hover,
.preset-card.active {
    transform: translateX(2px);
    border-color: rgba(25, 199, 181, 0.48);
    background: linear-gradient(135deg, rgba(25, 199, 181, 0.14), rgba(255, 255, 255, 0.04));
}

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

.sidebar-actions {
    display: grid;
    gap: 10px;
}

.chat-main {
    min-height: 0;
    height: 100vh;
    overflow: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

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

.topbar-title {
    font-size: 1.35rem;
    font-weight: 700;
}

.topbar-subtitle {
    color: var(--muted);
    margin-top: 4px;
}

.chat-board {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow: hidden;
}

.chat-status {
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(246, 185, 75, 0.12);
    border: 1px solid rgba(246, 185, 75, 0.24);
    color: #ffe7b3;
    overflow-wrap: anywhere;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    display: grid;
    align-content: start;
    gap: 16px;
    overflow-y: auto;
    padding-right: 4px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.empty-state {
    min-height: 320px;
    display: grid;
    place-content: center;
    text-align: center;
    border: 1px dashed var(--line-strong);
    border-radius: 20px;
    padding: 30px;
    color: var(--muted);
}

.message {
    padding: 18px;
    border-radius: 20px;
    border: 1px solid var(--line);
    max-width: min(900px, 100%);
    animation: fadeUp 0.25s ease both;
}

.message-user {
    justify-self: end;
    background: linear-gradient(135deg, rgba(25, 199, 181, 0.18), rgba(25, 199, 181, 0.07));
}

.message-assistant {
    justify-self: start;
    background: rgba(255, 255, 255, 0.035);
}

.message-meta {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 0.9rem;
}

.message-text {
    line-height: 1.72;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.message-image {
    margin-top: 14px;
    border-radius: 18px;
    border: 1px solid var(--line);
    max-height: 520px;
    object-fit: contain;
}

.message-audio,
.message-video {
    width: 100%;
    margin-top: 14px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
}

.message-video {
    max-height: 420px;
}

.message-file-card {
    margin-top: 12px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
}

.message-file-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    color: var(--muted);
}

.message-file-meta strong {
    color: var(--text);
    overflow-wrap: anywhere;
}

.message-file-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.message-inline-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.audio-options-panel {
    margin-top: 12px;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
}

.audio-options-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.audio-option-field {
    display: grid;
    gap: 6px;
}

.audio-option-field span {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.audio-option-field select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(5, 23, 37, 0.92);
    color: var(--text);
}

.audio-options-note {
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.45;
}

.btn-file-action {
    padding: 10px 14px;
    min-width: 132px;
}

.message-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.message-sources a {
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    font-size: 0.9rem;
    max-width: 100%;
    overflow-wrap: anywhere;
}

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

.grow {
    width: 100%;
}

.composer-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.file-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.file-pill {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    border: 1px dashed var(--line-strong);
    border-radius: 14px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    font-weight: 700;
}

.file-pill input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-selection {
    flex: 1;
    min-width: 220px;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    color: var(--muted);
    overflow-wrap: anywhere;
}

.admin-topbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 24px;
}

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

.admin-grid {
    display: grid;
    grid-template-columns: minmax(320px, 480px) minmax(0, 1fr);
    gap: 24px;
}

.preset-admin-list {
    display: grid;
    gap: 14px;
}

.preset-admin-item {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
}

.preset-admin-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.preset-admin-actions form {
    margin: 0;
}

.tiny-meta {
    color: var(--muted);
    font-size: 0.88rem;
    margin-top: 8px;
}

.sidebar-overlay {
    display: none;
}

.mobile-only {
    display: none;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1080px) {
    .auth-layout,
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .auth-card {
        justify-self: stretch;
        max-width: none;
    }
}

@media (max-width: 860px) {
    .page-chat {
        padding: 0;
        height: 100vh;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .chat-shell {
        height: 100vh;
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: min(82vw, 312px);
        padding: 18px;
        gap: 16px;
        transform: translateX(-105%);
        transition: transform 0.24s ease;
        box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
    }

    .chat-shell.menu-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.48);
        z-index: 15;
    }

    .chat-shell.menu-open .sidebar-overlay {
        display: block;
    }

    .chat-main {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        height: 100vh;
    }

    .topbar {
        gap: 10px;
        margin-bottom: 12px;
    }

    .topbar-title {
        font-size: 1.15rem;
        line-height: 1.08;
    }

    .topbar-subtitle {
        margin-top: 2px;
        font-size: 0.86rem;
    }

    .icon-btn {
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
    }

    .btn {
        padding: 12px 16px;
    }

    .chat-board {
        min-height: 0;
        gap: 12px;
        padding: 14px;
        border-radius: 20px;
    }

    .chat-status {
        padding: 12px;
        font-size: 0.92rem;
        line-height: 1.35;
    }

    .chat-messages {
        gap: 12px;
        padding-right: 0;
    }

    .message {
        padding: 14px;
        border-radius: 16px;
    }

    .message-meta {
        gap: 8px;
        margin-bottom: 8px;
        flex-wrap: wrap;
        font-size: 0.8rem;
    }

    .message-text {
        font-size: 0.95rem;
        line-height: 1.55;
    }

    .message-sources {
        gap: 8px;
        margin-top: 12px;
    }

    .message-sources a {
        padding: 7px 10px;
        font-size: 0.82rem;
    }

    .composer {
        gap: 10px;
        padding-top: 12px;
    }

    .field span {
        font-size: 0.88rem;
    }

    input,
    textarea,
    select,
    .file-pill,
    .file-selection {
        font-size: 16px;
    }

    textarea {
        min-height: 96px;
    }

    .file-pill {
        min-width: 0;
        padding: 12px 14px;
    }

    .file-selection {
        min-width: 0;
        padding: 12px 14px;
        font-size: 0.95rem;
    }

    .mobile-only {
        display: inline-flex;
    }
}

@supports (height: 100dvh) {
    .page-chat,
    .chat-shell,
    .chat-main,
    .sidebar {
        height: 100dvh;
        min-height: 100dvh;
    }
}

@media (max-width: 640px) {
    .page-auth,
    .page-install,
    .page-admin {
        padding: 16px;
    }

    .hero-panel,
    .card,
    .install-card {
        padding: 20px;
        border-radius: 20px;
    }

    .composer-row,
    .admin-topbar,
    .preset-admin-item,
    .preset-admin-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .message {
        max-width: 100%;
    }

    .chat-main {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .topbar {
        display: grid;
        grid-template-columns: 40px minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
    }

    .topbar > div {
        min-width: 0;
    }

    .topbar-title {
        font-size: 1.08rem;
    }

    .topbar-subtitle {
        font-size: 0.82rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar .btn {
        min-width: 112px;
        padding: 10px 12px;
        font-size: 0.9rem;
        line-height: 1.15;
    }

    .chat-board {
        gap: 10px;
        padding: 12px;
    }

    .chat-status {
        padding: 10px 12px;
        font-size: 0.88rem;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
    }

    .chat-messages {
        gap: 10px;
    }

    .message {
        padding: 12px;
        border-radius: 15px;
    }

    .message-meta {
        font-size: 0.78rem;
    }

    .message-text {
        font-size: 0.93rem;
        line-height: 1.5;
    }

    .message-image {
        max-height: 300px;
    }

    .message-file-card {
        padding: 12px;
    }

    .message-file-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .message-file-actions {
        gap: 8px;
    }

    .message-inline-actions {
        gap: 8px;
    }

    .audio-options-panel {
        padding: 12px;
    }

    .audio-options-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .btn-file-action {
        width: 100%;
        min-width: 0;
        padding: 11px 12px;
    }

    .composer {
        gap: 8px;
        padding-top: 10px;
    }

    .field {
        gap: 6px;
    }

    textarea {
        min-height: 84px;
        padding: 12px 14px;
        resize: none;
    }

    .auth-footer {
        flex-direction: column;
    }

    .composer-row {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .file-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .file-pill {
        width: 100%;
        padding: 12px 10px;
    }

    .file-selection {
        padding: 10px 12px;
        font-size: 0.92rem;
    }

    .composer-row .btn {
        width: 100%;
        padding: 12px 14px;
    }
}
