:root {
    --orange: #ffa300;
    --orange-light: #ffb733;
    --black: #0a0a0a;
    --dark: #111111;
    --dark2: #1a1a1a;
    --dark3: #242424;
    --dark4: #2e2e2e;
    --gray: #404040;
    --gray2: #6a6a6a;
    --gray3: #9a9a9a;
    --white: #fafafa;
    --white2: #f0f0f0;
    --green: #1fc070;
    --font: "Fira Sans", sans-serif;
    --mono: "Fira Mono", monospace;
    --sidebar-w: 260px;
    --header-h: 56px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html,
body {
    height: 100%;
    overflow: hidden;
}
@supports (height: 100dvh) {
    html,
    body {
        height: 100dvh;
    }
}
body {
    font-family: var(--font);
    background: var(--black);
    color: var(--white);
    display: flex;
    flex-direction: column;
}

/* ── AUTH ── */
#auth-screen {
    position: fixed;
    inset: 0;
    background: var(--black);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
    animation: fadeIn 0.4s ease;
}
.auth-card {
    background: var(--dark2);
    border: 1px solid var(--dark4);
    border-radius: 16px;
    padding: 40px 32px 32px;
    width: 100%;
    max-width: 400px;
    position: relative;
    overflow: hidden;
}
.auth-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--orange), var(--orange-light));
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}
.auth-logo img {
    flex-shrink: 0;
}
.auth-logo-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--gray3);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    border-left: 1px solid var(--dark4);
    padding-left: 12px;
}
.auth-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 6px;
}
.auth-subtitle {
    font-size: 14px;
    color: var(--gray3);
    margin-bottom: 28px;
    line-height: 1.5;
}
.form-group {
    margin-bottom: 14px;
}
.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray3);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 7px;
}
.form-group input {
    width: 100%;
    background: var(--dark3);
    border: 1px solid var(--dark4);
    border-radius: 8px;
    padding: 11px 14px;
    font-family: var(--font);
    font-size: 15px;
    color: var(--white);
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus {
    border-color: var(--orange);
}
.form-group input::placeholder {
    color: var(--gray2);
}
.auth-error {
    font-size: 13px;
    color: #ff6b6b;
    margin-bottom: 14px;
    display: none;
    padding: 10px 14px;
    background: rgba(255, 107, 107, 0.08);
    border-radius: 6px;
    border-left: 3px solid #ff6b6b;
}
.auth-btn {
    width: 100%;
    padding: 13px;
    background: var(--orange);
    color: var(--black);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition:
        background 0.2s,
        transform 0.1s;
    margin-top: 6px;
}
.auth-btn:hover {
    background: var(--orange-light);
}
.auth-btn:active {
    transform: scale(0.99);
}

/* ── APP ── */
#app {
    display: none;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    animation: fadeIn 0.3s ease;
}

/* ── HEADER ── */
.header {
    background: var(--dark);
    border-bottom: 1px solid var(--dark4);
    height: var(--header-h);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 12px;
    min-width: 0;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}
.btn-menu {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: var(--white);
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 8px;
    transition: background 0.2s;
}
.btn-menu:hover {
    background: var(--dark3);
}
.btn-menu svg {
    width: 20px;
    height: 20px;
}
.header-logo img {
    height: 20px;
    display: block;
}
.header-sep {
    width: 1px;
    height: 18px;
    background: var(--dark4);
    flex-shrink: 0;
}
.header-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--white2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s infinite;
    display: inline-block;
    margin-right: 5px;
    flex-shrink: 0;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.header-user {
    font-size: 13px;
    color: var(--gray3);
    white-space: nowrap;
}
.btn-logout {
    background: var(--dark3);
    border: 1px solid var(--dark4);
    color: var(--gray3);
    font-family: var(--font);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-logout:hover {
    border-color: var(--gray);
    color: var(--white);
}

/* ── LAYOUT ── */
.main {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    position: relative;
}

/* ── OVERLAY ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 50;
    animation: fadeIn 0.2s ease;
}
.sidebar-overlay.open {
    display: block;
}

/* ── SIDEBAR ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--dark);
    border-right: 1px solid var(--dark4);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    transition: transform 0.25s ease;
    z-index: 60;
}
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 12px 8px;
}
.sidebar-scroll::-webkit-scrollbar {
    width: 3px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
    background: var(--dark4);
}
.sidebar-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--gray2);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 0 8px;
    margin-bottom: 8px;
}
.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    background: var(--dark3);
    border: 1px solid var(--dark4);
    border-radius: 8px;
    color: var(--white);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
}
.btn-new-chat:hover {
    background: var(--dark4);
    border-color: var(--orange);
}
.btn-new-chat .plus {
    color: var(--orange);
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}

/* ── CONFIG ── */
.config-panel {
    background: var(--dark2);
    border: 1px solid var(--dark4);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 16px;
}
.config-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--gray2);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 10px;
}
.config-row {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 10px;
}
.config-row label {
    font-size: 11px;
    color: var(--gray3);
}
.config-row input {
    width: 100%;
    background: var(--dark3);
    border: 1px solid var(--dark4);
    border-radius: 6px;
    padding: 7px 10px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--white);
    outline: none;
    min-width: 0;
}
.config-row input:focus {
    border-color: var(--orange);
}
.config-row input::placeholder {
    color: var(--gray2);
}
.btn-config-save {
    width: 100%;
    margin-top: 4px;
    background: var(--dark3);
    border: 1px solid var(--dark4);
    color: var(--gray3);
    font-family: var(--font);
    font-size: 12px;
    padding: 7px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-config-save:hover {
    border-color: var(--gray);
    color: var(--white);
}
.config-saved {
    color: var(--green);
    font-size: 11px;
    display: none;
    margin-top: 6px;
}

/* ── HISTORY ── */
#history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.history-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--gray3);
    cursor: pointer;
    transition: all 0.15s;
    min-width: 0;
}
.history-item:hover {
    background: var(--dark3);
    color: var(--white);
}
.history-item.active {
    background: var(--dark3);
    color: var(--white);
    border-left: 2px solid var(--orange);
    padding-left: 6px;
}
.history-item-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn-delete-conv {
    flex-shrink: 0;
    display: none;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: none;
    border: none;
    color: var(--gray2);
    cursor: pointer;
    padding: 0;
    transition: all 0.15s;
}
.btn-delete-conv svg {
    width: 13px;
    height: 13px;
}
.btn-delete-conv:hover {
    background: rgba(255, 107, 107, 0.15);
    color: #ff6b6b;
}
.history-item:hover .btn-delete-conv {
    display: flex;
}
.history-item.active .btn-delete-conv {
    display: flex;
}

.sidebar-footer {
    padding: 14px 12px;
    border-top: 1px solid var(--dark4);
    flex-shrink: 0;
}
.sidebar-info {
    font-size: 11px;
    color: var(--gray2);
    line-height: 1.6;
}
.sidebar-info a {
    color: var(--orange);
    text-decoration: none;
}

/* ── CHAT ── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}
.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 0;
}
.messages::-webkit-scrollbar {
    width: 4px;
}
.messages::-webkit-scrollbar-thumb {
    background: var(--dark4);
    border-radius: 2px;
}

/* ── WELCOME ── */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    min-height: 100%;
}
.welcome-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--dark2);
    border: 1px solid var(--dark4);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}
.welcome-title {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
}
.welcome-title span {
    color: var(--orange);
}
.welcome-sub {
    font-size: 14px;
    color: var(--gray3);
    max-width: 340px;
    line-height: 1.6;
    margin-bottom: 32px;
}
.suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-width: 480px;
    width: 100%;
}
.suggestion {
    background: var(--dark2);
    border: 1px solid var(--dark4);
    border-radius: 10px;
    padding: 12px 14px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--white);
    font-family: var(--font);
}
.suggestion:hover {
    border-color: var(--orange);
    background: var(--dark3);
}
.suggestion-title {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 3px;
}
.suggestion-sub {
    font-size: 12px;
    color: var(--gray3);
}

/* ── MESSAGES ── */
.msg-row {
    max-width: 720px;
    margin: 0 auto 20px;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s ease;
}
.msg-row.user {
    align-items: flex-end;
}
.msg-row.assistant {
    align-items: flex-start;
}
.msg-sender {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 7px;
}
.msg-row.user .msg-sender {
    color: var(--orange);
}
.msg-row.assistant .msg-sender {
    color: var(--gray3);
}
.msg-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 600;
    flex-shrink: 0;
}
.msg-row.user .msg-avatar {
    background: var(--orange);
    color: var(--black);
}
.msg-row.assistant .msg-avatar {
    background: var(--dark3);
    border: 1px solid var(--dark4);
    color: var(--white);
}
.msg-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.65;
    word-break: break-word;
}
.msg-row.user .msg-bubble {
    background: var(--orange);
    color: var(--black);
    border-bottom-right-radius: 4px;
}
.msg-row.assistant .msg-bubble {
    background: var(--dark2);
    border: 1px solid var(--dark4);
    color: var(--white);
    border-bottom-left-radius: 4px;
}
.msg-bubble pre {
    background: var(--dark3);
    border: 1px solid var(--dark4);
    border-radius: 6px;
    padding: 10px;
    font-family: var(--mono);
    font-size: 12px;
    overflow-x: auto;
    margin-top: 8px;
    white-space: pre-wrap;
}

/* ── TYPING ── */
.typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}
.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--gray2);
    animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) {
    animation-delay: 0.2s;
}
.typing span:nth-child(3) {
    animation-delay: 0.4s;
}

/* ── INPUT ── */
.input-area {
    padding: 12px 16px 16px;
    background: var(--black);
    border-top: 1px solid var(--dark4);
    flex-shrink: 0;
}
.input-box {
    max-width: 720px;
    margin: 0 auto;
    background: var(--dark2);
    border: 1px solid var(--dark4);
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    transition: border-color 0.2s;
}
.input-box:focus-within {
    border-color: var(--orange);
}
#user-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--white);
    font-family: var(--font);
    font-size: 15px;
    resize: none;
    max-height: 140px;
    min-height: 24px;
    line-height: 1.5;
    padding: 2px 0;
}
#user-input::placeholder {
    color: var(--gray2);
}
.btn-send {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--orange);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
.btn-send:hover {
    background: var(--orange-light);
}
.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.input-hint {
    max-width: 720px;
    margin: 7px auto 0;
    font-size: 11px;
    color: var(--gray2);
    text-align: center;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
    .btn-menu {
        display: flex;
    }
    .header-user {
        display: none;
    }
    .header-logo {
        display: none;
    }
    .header-sep {
        display: none;
    }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .suggestions {
        grid-template-columns: 1fr;
    }
    .msg-bubble {
        max-width: 92%;
    }
    .input-hint {
        display: none;
    }
}
@media (max-width: 480px) {
    .auth-card {
        padding: 32px 20px 24px;
    }
    .welcome-title {
        font-size: 19px;
    }
    .welcome-sub {
        font-size: 13px;
    }
}

/* ── ANIMATIONS ── */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}
@keyframes bounce {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}
