:root {
    --bg: #eef3f7;
    --bg-strong: #dfe8ef;
    --surface: #ffffff;
    --surface-soft: #f7fafc;
    --surface-tint: #edf7f6;
    --ink: #17212b;
    --muted: #657282;
    --line: #d8e0e7;
    --line-strong: #c0ccd8;
    --accent: #d9672c;
    --accent-strong: #9e4218;
    --accent-warm: #116466;
    --danger: #b3261e;
    --success: #15784f;
    --shadow: 0 18px 45px rgba(26, 42, 58, 0.12);
    --shadow-soft: 0 8px 24px rgba(26, 42, 58, 0.08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(217, 103, 44, 0.1) 0%, transparent 38%),
        linear-gradient(315deg, rgba(199, 85, 54, 0.08) 0%, transparent 34%),
        linear-gradient(180deg, var(--bg) 0%, #f8fafc 100%);
    color: var(--ink);
    font-family: "Aptos", "Bahnschrift", "Segoe UI", sans-serif;
    letter-spacing: 0;
}

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

button,
select,
input,
textarea {
    border-radius: var(--radius);
    border: 1px solid var(--line);
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(17, 100, 102, 0.22);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
}

.auth-screen,
.app-shell {
    min-height: 100vh;
}

.auth-screen {
    display: grid;
    place-items: center;
    padding: 28px;
}

.auth-card {
    width: min(980px, 100%);
    min-height: 520px;
    display: grid;
    grid-template-columns: 1fr minmax(320px, 430px);
    overflow: visible;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(216, 224, 231, 0.9);
    border-radius: 14px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.auth-intro {
    position: relative;
    padding: 34px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background:
        linear-gradient(150deg, rgba(217, 103, 44, 0.14), transparent 50%),
        linear-gradient(320deg, rgba(17, 100, 102, 0.08), transparent 46%),
        var(--surface-soft);
}

.auth-intro::after {
    content: "";
    position: absolute;
    inset: 18px;
    border: 1px solid rgba(216, 224, 231, 0.75);
    border-radius: 10px;
    pointer-events: none;
}

.auth-panel {
    padding: 34px;
    display: grid;
    align-content: center;
    background: var(--surface);
    border-left: 1px solid var(--line);
}

.brand-lockup {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 0;
}

.brand-lockup.small {
    margin-bottom: 0;
}

.brand-lockup h1,
.brand-lockup h2,
.brand-lockup p {
    margin: 0;
}

.brand-lockup h1 {
    font-size: clamp(2.6rem, 5vw, 5.2rem);
    line-height: 0.92;
}

.brand-lockup h2 {
    font-size: 1.12rem;
}

.brand-lockup p {
    color: var(--muted);
    margin-top: 4px;
}

.logo-mark {
    width: 56px;
    height: 56px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent) 0%, #f19a3f 100%);
    color: white;
    font-size: 1.7rem;
    font-weight: 800;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 10px 24px rgba(217, 103, 44, 0.22);
}

.sidebar .logo-mark {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    font-size: 1.35rem;
}

.auth-grid {
    display: grid;
    gap: 14px;
}

.panel,
.account-box,
.composer,
.dialog-content,
.topbar,
.message-card,
.chat-item {
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
}

.panel {
    border: none;
    box-shadow: none;
    padding: 0;
    display: grid;
    gap: 12px;
    position: relative;
}

.panel h2 {
    margin: 0 0 4px;
    font-size: 1.8rem;
    line-height: 1;
}

label {
    color: var(--ink);
    font-weight: 700;
    font-size: 0.92rem;
}

input,
textarea,
select {
    width: 100%;
    padding: 12px 13px;
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
}

input:hover,
textarea:hover,
select:hover {
    border-color: #9eb0c2;
}

textarea {
    resize: vertical;
}

.primary-button,
.secondary-button,
.ghost-button {
    min-height: 42px;
    padding: 10px 14px;
    border-radius: var(--radius);
    transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover {
    transform: translateY(-1px);
}

.primary-button {
    background: linear-gradient(135deg, var(--accent) 0%, #e88b39 100%);
    color: white;
    border: none;
    box-shadow: 0 10px 20px rgba(217, 103, 44, 0.18);
    font-weight: 800;
}

.secondary-button {
    background: var(--surface-tint);
    color: var(--accent-strong);
    border-color: rgba(217, 103, 44, 0.22);
    font-weight: 700;
}

.muted-button {
    background: #f4f7fa;
    color: var(--ink);
    border-color: var(--line);
}

.ghost-button {
    background: transparent;
    color: var(--ink);
}

.register-details {
    display: grid;
    gap: 10px;
}

.register-details summary {
    list-style: none;
}

.register-details summary::-webkit-details-marker {
    display: none;
}

.auth-toggle-button {
    display: grid;
    place-items: center;
    margin-top: 2px;
    text-align: center;
}

.register-details[open] .auth-toggle-button {
    border-color: rgba(217, 103, 44, 0.35);
    background: #fff5ef;
}

.register-popup {
    margin-top: 10px;
}

.register-popup-inner {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
    box-shadow: none;
    padding: 14px;
    display: grid;
    gap: 10px;
}

.register-popup-inner h2 {
    margin: 0;
    font-size: 1.25rem;
}

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

.register-actions button {
    flex: 1 1 140px;
}

.ghost-button.danger {
    color: var(--danger);
    border-color: rgba(179, 38, 30, 0.22);
}

.notice {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: var(--radius);
}

.notice.error {
    background: #fff0ee;
    border: 1px solid #f0b5ae;
    color: #851f17;
}

.app-shell {
    display: grid;
    grid-template-columns: 310px 1fr;
    background:
        linear-gradient(90deg, rgba(217, 103, 44, 0.06), transparent 32%),
        var(--bg);
}

.sidebar {
    min-height: 100vh;
    padding: 18px;
    border-right: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.account-box {
    padding: 14px;
    border-radius: var(--radius);
    box-shadow: none;
}

.account-name {
    font-weight: 800;
}

.account-tier {
    color: var(--muted);
    margin-top: 4px;
    line-height: 1.35;
    font-size: 0.92rem;
}

.usage-box {
    margin-top: 14px;
    display: grid;
    gap: 12px;
}

.usage-item {
    display: grid;
    gap: 6px;
}

.usage-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.86rem;
    color: var(--muted);
}

.usage-header strong {
    color: var(--ink);
}

.usage-bar {
    width: 100%;
    height: 7px;
    border-radius: 999px;
    background: #e7edf2;
    overflow: hidden;
}

.usage-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent) 0%, var(--accent-warm) 100%);
    transition: width 0.18s ease;
}

.usage-detail {
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.3;
}

.admin-badge {
    margin-top: 10px;
    display: inline-block;
    width: fit-content;
    padding: 4px 9px;
    border-radius: 999px;
    background: #e6f5ee;
    color: var(--success);
    font-size: 0.82rem;
    font-weight: 800;
}

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

.section-label {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.72rem;
    font-weight: 900;
    margin-top: 2px;
}

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

.chat-item {
    border-radius: var(--radius);
    padding: 12px;
    text-align: left;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.72);
}

.chat-item:hover {
    border-color: rgba(217, 103, 44, 0.36);
}

.chat-item.active {
    border-color: rgba(217, 103, 44, 0.52);
    background: #fff5ef;
}

.chat-item-title {
    font-weight: 800;
    margin-bottom: 4px;
}

.chat-item-time {
    color: var(--muted);
    font-size: 0.82rem;
}

.main-shell {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-width: 0;
    min-height: 100vh;
}

.topbar {
    margin: 16px 16px 0;
    padding: 14px 16px;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    box-shadow: none;
}

.topbar h1 {
    margin: 0;
    font-size: 1.35rem;
}

.topbar-actions {
    display: flex;
    gap: 9px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.model-picker {
    min-width: 210px;
    display: grid;
    gap: 5px;
}

.model-picker span {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 800;
}

.status-pill {
    display: inline-block;
    margin-top: 7px;
    padding: 5px 9px;
    border-radius: 999px;
    background: var(--surface-tint);
    color: var(--accent-strong);
    border: 1px solid rgba(217, 103, 44, 0.18);
    font-size: 0.82rem;
    font-weight: 800;
}

.message-list {
    padding: 18px 16px;
    overflow: auto;
    display: grid;
    align-content: start;
    gap: 12px;
}

.message-card {
    padding: 14px;
    border-radius: var(--radius);
    max-width: min(860px, 86%);
    box-shadow: none;
}

.message-card.user {
    justify-self: end;
    background: #fff5ef;
    border-color: rgba(217, 103, 44, 0.22);
}

.message-card.assistant {
    justify-self: start;
}

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

.message-meta strong {
    color: var(--ink);
}

.message-body {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.55;
}

.message-image {
    margin-top: 12px;
    border-radius: var(--radius);
    max-width: min(100%, 560px);
    border: 1px solid var(--line);
}

.composer {
    margin: 0 16px 16px;
    padding: 14px;
    border-radius: var(--radius);
    box-shadow: none;
}

.composer textarea {
    min-height: 86px;
    border-color: var(--line);
    background: var(--surface-soft);
}

.composer-row {
    margin-top: 11px;
    display: flex;
    gap: 9px;
    align-items: center;
    flex-wrap: wrap;
}

.file-label {
    display: inline-flex;
    gap: 10px;
    align-items: center;
    color: var(--muted);
    font-weight: 800;
    cursor: pointer;
    min-height: 42px;
}

.file-label input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.file-button {
    display: inline-grid;
    place-items: center;
    min-height: 42px;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid rgba(217, 103, 44, 0.22);
    background: #fff5ef;
    color: var(--accent-strong);
    font-weight: 800;
}

.file-name-label {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 0.9rem;
}

.hint {
    margin-top: 9px;
    color: var(--muted);
    font-size: 0.86rem;
}

.dialog-card {
    border: none;
    padding: 0;
    border-radius: 10px;
    width: min(720px, calc(100vw - 30px));
}

.dialog-card::backdrop {
    background: rgba(18, 29, 39, 0.48);
}

.dialog-content {
    padding: 20px;
    border-radius: 10px;
    display: grid;
    gap: 10px;
}

.dialog-content h2,
.dialog-content p {
    margin: 0;
}

.dialog-content p {
    color: var(--muted);
}

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

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
}

@media (max-width: 900px) {
    .auth-card {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .auth-intro {
        min-height: 260px;
    }

    .auth-panel {
        border-left: none;
        border-top: 1px solid var(--line);
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions {
        justify-content: stretch;
    }

    .topbar-actions > button,
    .model-picker {
        flex: 1 1 180px;
    }
}

@media (max-width: 560px) {
    .auth-screen {
        padding: 14px;
    }

    .auth-intro,
    .auth-panel {
        padding: 22px;
    }

    .brand-lockup {
        align-items: flex-start;
    }

    .brand-lockup h1 {
        font-size: 2.35rem;
    }

    .message-card {
        max-width: 100%;
    }

    .composer-row > button,
    .composer-row .file-label {
        flex: 1 1 100%;
    }
}
