:root {
    --bg: #0b0d10;
    --panel: #111419;
    --panel-2: #171b21;
    --panel-3: #1e232b;
    --border: #2a3039;
    --text: #f2f4f7;
    --muted: #939ba8;
    --accent: #ffffff;
    --accent-text: #0d0f12;
    --danger: #ef6464;
    --success: #55c98c;
    --shadow: 0 20px 60px rgba(0,0,0,.35);
}

html[data-theme="light"] {
    --bg: #f7f7f8;
    --panel: #ffffff;
    --panel-2: #f1f2f4;
    --panel-3: #e8eaed;
    --border: #dcdfe4;
    --text: #17191d;
    --muted: #6d7480;
    --accent: #17191d;
    --accent-text: #ffffff;
    --shadow: 0 20px 60px rgba(0,0,0,.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
}

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

button,
input,
textarea {
    font: inherit;
}

button {
    color: inherit;
}

.hidden {
    display: none !important;
}

/* LOGIN */

.login-view {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(
            circle at 50% -10%,
            var(--panel-3),
            transparent 42%
        ),
        var(--bg);
}

.login-card {
    width: min(430px, 100%);
    padding: 38px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

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

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

.brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 800;
    font-size: 21px;
}

.brand-mark.small {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 16px;
}

.brand-name {
    font-weight: 700;
    font-size: 18px;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 28px;
}

.login-description {
    margin: 0 0 28px;
    color: var(--muted);
    line-height: 1.55;
}

.login-card label {
    display: block;
    margin: 18px 0 8px;
    font-size: 13px;
    font-weight: 600;
}

.login-card input {
    width: 100%;
    height: 48px;
    padding: 0 14px;
    color: var(--text);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 11px;
    outline: none;
}

.login-card input:focus {
    border-color: var(--muted);
}

.primary-button {
    width: 100%;
    height: 48px;
    margin-top: 24px;
    border: 0;
    border-radius: 11px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
    cursor: pointer;
}

.primary-button:disabled {
    opacity: .55;
    cursor: wait;
}

.form-error {
    min-height: 20px;
    margin-top: 12px;
    color: var(--danger);
    font-size: 13px;
    text-align: center;
}

.login-footer {
    margin-top: 28px;
    color: var(--muted);
    text-align: center;
    font-size: 12px;
}

/* APPLICATION */

.app-view {
    width: 100%;
    height: 100vh;
    display: flex;
}

.sidebar {
    width: 280px;
    flex: 0 0 280px;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-right: 1px solid var(--border);
    z-index: 30;
}

.sidebar-header {
    min-height: 66px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
}

.new-chat-wrap {
    padding: 8px 12px 18px;
}

.new-chat-button {
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 11px;
    cursor: pointer;
    text-align: left;
}

.new-chat-button:hover {
    background: var(--panel-3);
}

.plus {
    font-size: 19px;
}

.sidebar-section-title {
    padding: 0 16px 9px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.conversation-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 2px 0;
    border-radius: 9px;
}

.conversation-open {
    min-width: 0;
    flex: 1;
    padding: 10px 10px;
    border: 0;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.conversation-title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 13px;
}

.conversation-item:hover,
.conversation-item.active {
    background: var(--panel-2);
}

.delete-chat {
    width: 30px;
    height: 30px;
    margin-right: 5px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    opacity: 0;
}

.conversation-item:hover .delete-chat {
    opacity: 1;
}

.delete-chat:hover {
    color: var(--danger);
    background: var(--panel-3);
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.user-box {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--panel-3);
    font-weight: 700;
}

.user-info {
    min-width: 0;
    flex: 1;
}

.user-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 600;
}

.user-role {
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
}

.sidebar-actions {
    display: flex;
    gap: 5px;
    margin-top: 12px;
}

.icon-button {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 9px;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 17px;
}

.icon-button:hover {
    color: var(--text);
    background: var(--panel-2);
}

/* MAIN */

.main {
    min-width: 0;
    flex: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.topbar {
    min-height: 66px;
    display: flex;
    align-items: center;
    padding: 0 22px;
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,.03);
}

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

.topbar-title {
    max-width: 650px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 14px;
    font-weight: 650;
}

.model-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    color: var(--muted);
    font-size: 10px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

.messages {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.welcome {
    width: min(720px, calc(100% - 32px));
    min-height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 50px 0 120px;
}

.welcome-logo {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 24px;
    font-weight: 800;
}

.welcome h2 {
    margin: 22px 0 8px;
    font-size: 28px;
}

.welcome p {
    max-width: 470px;
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.suggestions {
    width: min(620px, 100%);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 34px;
}

.suggestion {
    min-height: 82px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--panel);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    line-height: 1.4;
    font-size: 13px;
}

.suggestion:hover {
    background: var(--panel-2);
}

.message-row {
    width: 100%;
    padding: 24px 20px;
}

.message-inner {
    width: min(780px, 100%);
    margin: 0 auto;
    display: flex;
    gap: 16px;
}

.message-avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--panel-3);
    font-size: 11px;
    font-weight: 800;
}

.message-row.assistant .message-avatar {
    background: var(--accent);
    color: var(--accent-text);
}

.message-content {
    min-width: 0;
    flex: 1;
    padding-top: 3px;
    line-height: 1.7;
    font-size: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message-row.assistant {
    background: var(--panel);
}

.typing-cursor::after {
    content: "▋";
    display: inline-block;
    margin-left: 2px;
    animation: blink .8s infinite;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* COMPOSER */

.composer-area {
    padding: 14px 20px 18px;
    background:
        linear-gradient(
            transparent,
            var(--bg) 22%
        );
}

.composer {
    width: min(780px, 100%);
    min-height: 56px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 9px 9px 9px 16px;
    border: 1px solid var(--border);
    border-radius: 17px;
    background: var(--panel);
    box-shadow: 0 8px 30px rgba(0,0,0,.08);
}

.composer:focus-within {
    border-color: var(--muted);
}

.composer textarea {
    min-height: 36px;
    max-height: 180px;
    flex: 1;
    resize: none;
    border: 0;
    outline: 0;
    padding: 7px 0;
    background: transparent;
    color: var(--text);
    line-height: 1.5;
}

.composer textarea::placeholder {
    color: var(--muted);
}

.send-button,
.stop-button {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 0;
    border-radius: 11px;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.send-button {
    background: var(--accent);
    color: var(--accent-text);
    font-size: 20px;
}

.send-button:disabled {
    opacity: .35;
    cursor: not-allowed;
}

.stop-button {
    background: var(--panel-3);
    color: var(--text);
}

.composer-note {
    margin-top: 8px;
    color: var(--muted);
    text-align: center;
    font-size: 10px;
}

/* TOAST */

.toast {
    position: fixed;
    top: 18px;
    left: 50%;
    z-index: 100;
    max-width: calc(100% - 30px);
    transform: translate(-50%, -20px);
    padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-3);
    color: var(--text);
    box-shadow: var(--shadow);
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: .2s ease;
}

.toast.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

.sidebar-overlay {
    display: none;
}

.mobile-only {
    display: none;
}

/* SCROLLBARS */

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* MOBILE */

@media (max-width: 760px) {

    .mobile-only {
        display: grid;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(86vw, 300px);
        transform: translateX(-101%);
        transition: transform .22s ease;
        box-shadow: var(--shadow);
    }

    .sidebar.open {
        transform: translateX(0);
    }

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

    .sidebar-overlay.show {
        display: block;
    }

    .topbar {
        gap: 8px;
        padding: 0 12px;
    }

    .message-row {
        padding: 20px 14px;
    }

    .message-inner {
        gap: 11px;
    }

    .composer-area {
        padding: 10px 10px 12px;
    }

    .suggestions {
        grid-template-columns: 1fr;
    }

    .welcome {
        padding-bottom: 70px;
    }

    .welcome h2 {
        font-size: 24px;
    }

    .login-card {
        padding: 28px 22px;
    }

    .delete-chat {
        opacity: 1;
    }
}

/* MyAI safe assistant rich-text rendering */
.message-row.assistant .message-content a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    overflow-wrap: anywhere;
}

.message-row.assistant .message-content a:hover {
    text-decoration-thickness: 2px;
}

.message-row.assistant .message-content code {
    font-family:
        ui-monospace,
        SFMono-Regular,
        Menlo,
        Monaco,
        Consolas,
        "Liberation Mono",
        monospace;
    font-size: 0.92em;
    padding: 0.12em 0.3em;
    border-radius: 4px;
    background: rgba(127, 127, 127, 0.12);
}
