/* --- GLOBAL --- */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: #e5e9ef;
    font-family: "Helvetica", sans-serif;
}

body {
    display: flex;
    flex-direction: column;
}

/* --- TOPBAR --- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: #fff;
    border-bottom: 1px solid #dcdcdc;
    gap: 10px;
    position: relative;
}

.topbar .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.topbar .title {
    font-size: 22px;
    font-weight: bold;
    text-align: center;
}

.mobile-link {
    position: absolute;
    right: 15px;
    font-size: 14px;
    color: #0088cc;
    text-decoration: none;
    white-space: nowrap;
}

/* --- CHAT CONTAINER + WIADOMOŚCI --- */
#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px;
    overflow: hidden;
}

#messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
}

/* --- BĄBELKI --- */
.msg {
    max-width: 80%;
    padding: 10px 14px;
    margin: 6px 0;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.3;
}

.user-msg {
    background: #d1f1ff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.bot-msg {
    background: #fff;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* --- INPUT (DOMYŚLNIE NORMALNY FLOW – DESKTOP) --- */
#input-area {
    display: flex;
    padding: 10px;
    background: #fff;
    border-top: 1px solid #dcdcdc;
    gap: 10px;
}

#input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 20px;
    border: 1px solid #ccc;
    font-size: 15px;
    outline: none;
}

#send {
    padding: 0 16px;
    border: none;
    background: #0088cc;
    color: white;
    border-radius: 20px;
    font-size: 15px;
    white-space: nowrap;
}

/* --- README + STOPKA (DESKTOP) --- */
#readme-box {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.readme-tile {
    display: inline-block;
    padding: 12px 20px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    color: #333;
    text-decoration: none;
    transition: 0.2s;
}

.readme-tile:hover {
    background: #e9e9e9;
    border-color: #ccc;
}

.footer {
    text-align: center;
    padding: 10px;
    font-size: 12px;
    color: #666;
    background: #fff;
    border-top: 1px solid #dcdcdc;
    margin-top: auto;
}

/* --- MOBILE: przyklejony input + margines na dół --- */
@media (max-width: 600px) {

    body {
        font-size: 18px;
    }

    .topbar .avatar {
        width: 32px;
        height: 32px;
    }

    .topbar .title {
        font-size: 20px;
    }

    /* input przyklejony do dołu tylko na mobile */
    #input-area {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        box-sizing: border-box;
    }

    /* chat kończy się NAD inputem, nie pod nim */
    #chat-container {
        padding-bottom: 80px; /* miejsce na przyklejony input */
    }

    #input {
        font-size: 18px;
    }

    #send {
        font-size: 16px;
    }

    /* ukryj README i stopkę na mobile */
    #readme-box,
    .footer {
        display: none !important;
    }
}

/* --- MOBILE FIX: usuń overflow:hidden z kontenera --- */
@media (max-width: 600px) {
    #chat-container {
        overflow: visible !important;
        margin-bottom: 90px !important; /* miejsce na input */
    }

    #messages {
        padding-bottom: 20px !important;
    }
}

/* --- MOBILE FINAL FIX: stała wysokość listy wiadomości --- */
@media (max-width: 600px) {

    /* wysokość ekranu minus topbar (60px) minus input (70px) */
    #messages {
        height: calc(100vh - 60px - 70px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* kontener nie może mieć overflow:hidden */
    #chat-container {
        overflow: visible !important;
        padding-bottom: 0 !important;
        margin-bottom: 0 !important;
    }
}

/* --- MOBILE FIX: miejsce na ostatnią linijkę --- */
@media (max-width: 600px) {
    #messages {
        padding-bottom: 90px !important; /* miejsce na input */
    }
}

/* --- MOBILE: duży padding na dole, żeby input NIC nie zasłaniał --- */
@media (max-width: 600px) {
    #messages {
        padding-bottom: 120px !important;
    }
}

/* --- LINIA NAD INPUTEM --- */
#input-area {
    border-top: 1px solid #dcdcdc !important;
}

/* --- OSTATECZNY MOBILE FIX: wymuszone miejsce na dole --- */
@media (max-width: 600px) {
    #messages {
        padding-bottom: 180px !important;   /* DUŻO miejsca na input */
        overflow-y: scroll !important;       /* wymusza normalny scroll */
        display: block !important;           /* wyłącza flex-bugi */
    }

    #chat-container {
        overflow: visible !important;
    }

    #input-area {
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 9999;
    }
}
