:root {
    --primary-color: #2563eb;
    --secondary-color: #3b82f6;
    --text-color: #1e293b;
    --light-bg: #f0f9ff;
    --card-bg: rgba(255, 255, 255, 0.95);
    --gradient-bg: linear-gradient(135deg, #e0f2fe 0%, #f0f9ff 100%);
}

body.dark-theme {
    --primary-color: #38bdf8;
    --text-color: #f1f5f9;
    --light-bg: #020617;
    --card-bg: rgba(30, 41, 59, 0.95);
    --gradient-bg: linear-gradient(135deg, #020617 0%, #0f172a 100%);
}

body {
    font-family: Inter, sans-serif;
    margin: 0;
    min-height: 100vh;
    background: var(--gradient-bg);
    color: var(--text-color);
}

/* —— Kompyuter —— */
@media (min-width: 769px) {
    body {
        height: 100vh;
        overflow: hidden;
    }

    .chat-page-wrap {
        max-width: 900px;
        margin: 0 auto;
        padding: 12px 12px 0;
        height: 100vh;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .chat-shell {
        flex: 1;
        min-height: 0;
        margin-bottom: 8px;
    }
}

.chat-page-wrap {
    max-width: 900px;
    margin: 0 auto;
    padding: 12px 12px 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.chat-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.back-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.chat-page-title {
    margin: 0;
    font-size: 1.35rem;
}

.auth-notice {
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.35);
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 12px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.auth-notice a {
    color: var(--primary-color);
    font-weight: 600;
}

.chat-shell {
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border-radius: 16px;
    border: 1px solid rgba(56, 189, 248, 0.2);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.chat-header {
    background: var(--primary-color);
    padding: 16px 20px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header a {
    color: white;
    font-size: 0.85rem;
    opacity: 0.9;
}

#chat-messages {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 0.92rem;
    min-height: 0;
}

.chat-msg {
    padding: 12px 15px;
    border-radius: 15px;
    max-width: 92%;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
    border-radius: 15px 15px 0 15px;
}

.chat-msg.ai {
    align-self: flex-start;
    background: rgba(56, 189, 248, 0.1);
    color: var(--text-color);
    border-radius: 15px 15px 15px 0;
}

.welcome-bubble {
    background: rgba(56, 189, 248, 0.1);
    padding: 12px;
    border-radius: 15px 15px 15px 0;
    align-self: flex-start;
    max-width: 85%;
}

#image-preview-box {
    display: none;
    padding: 10px 16px;
    border-top: 1px solid rgba(56, 189, 248, 0.1);
    flex-shrink: 0;
}

#image-preview-box img {
    max-height: 80px;
    border-radius: 8px;
    border: 1px solid var(--primary-color);
}

.preview-remove {
    margin-left: 8px;
    cursor: pointer;
    color: #ef4444;
    border: none;
    background: transparent;
    font-size: 1.2rem;
}

.chat-input-area {
    padding: 10px 12px;
    flex-shrink: 0;
    border-top: 1px solid rgba(56, 189, 248, 0.15);
    background: var(--card-bg);
}

.chat-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

#user-input-ai {
    flex: 1;
    min-width: 0;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(56, 189, 248, 0.3);
    background: var(--light-bg);
    color: var(--text-color);
    outline: none;
    font-size: 16px;
}

#tutor-input {
    flex: 1;
    min-width: 0;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(56, 189, 248, 0.3);
    background: var(--light-bg);
    color: var(--text-color);
    outline: none;
    font-size: 16px;
}

#send-btn-ai,
#tutor-send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 10px;
    cursor: pointer;
    flex-shrink: 0;
}

#send-btn-ai:disabled,
#tutor-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.file-label {
    cursor: pointer;
    color: var(--primary-color);
    font-size: 1.2rem;
    flex-shrink: 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
    margin-top: 10px;
    margin-bottom: 5px;
    color: var(--primary-color);
}

.message-content ul,
.message-content ol {
    padding-left: 20px;
    margin: 5px 0;
}

.message-content p {
    margin: 5px 0;
}

.msg-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.msg-action-btn {
    padding: 5px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: var(--primary-color);
}

/* ════════════════════════════════
   MOBIL — Asosiy tuzatmalar
   Barcha panel va inputlar
   ekrandan chiqib ketmasin
════════════════════════════════ */
@media (max-width: 768px) {

    /* Butun sahifa ekranga sig'sin */
    html, body {
        height: 100%;
        height: 100dvh;
        overflow: hidden;
        position: fixed;
        width: 100%;
    }

    .chat-page-wrap {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        height: 100%;
        height: 100dvh;
        max-width: 100%;
        padding: 6px 6px 0;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Top bar */
    .chat-top-bar {
        gap: 6px;
        padding-bottom: 4px;
        flex-shrink: 0;
    }

    .back-link {
        font-size: 0;
    }
    .back-link i {
        font-size: 1rem;
    }

    .chat-page-title {
        font-size: 0.95rem;
        flex: 1;
        text-align: center;
        min-width: 0;
    }

    .chat-top-bar a:last-child {
        font-size: 0.7rem;
        white-space: nowrap;
    }

    .auth-notice {
        font-size: 0.78rem;
        padding: 8px 10px;
        margin-bottom: 6px;
        flex-shrink: 0;
    }

    /* Tab panellari flex-ni to'g'ri ulaydi */
    .tab-panel {
        flex: 1;
        min-height: 0;
        display: none;
        flex-direction: column;
        overflow: hidden;
    }
    .tab-panel.active {
        display: flex;
    }

    /* Chat shell — flex container sifatida */
    .chat-shell {
        flex: 1;
        min-height: 0;
        border-radius: 12px;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .chat-header {
        padding: 10px 12px;
        font-size: 0.85rem;
        flex-shrink: 0;
    }

    /* Xabarlar maydoni — qolgan joyni egallaydi */
    #chat-messages,
    #tutor-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 10px;
        padding-bottom: 6px;
    }

    /* Input qismi — pastda qotib turadi, ekrandan tushib ketmaydi */
    .chat-input-area {
        flex-shrink: 0;
        padding: 8px 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
        background: var(--card-bg);
        border-top: 1px solid rgba(56,189,248,0.15);
    }

    /* Tutor shell */
    .tutor-shell {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .tutor-subjects {
        flex-shrink: 0;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .tutor-mode-bar {
        flex-shrink: 0;
    }

    /* Tutor ichidagi chat-shell */
    .tutor-shell .chat-shell {
        flex: 1;
        min-height: 0;
        border-radius: 0 0 12px 12px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Input fields */
    #user-input-ai,
    #tutor-input {
        font-size: 16px; /* iOS zoom oldini olish */
        min-width: 0;
    }
}
