* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: #111318;
    color: #eeeeee;
}

button,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

#app {
    height: 100vh;
    display: flex;
    overflow: hidden;
}

#sidebar {
    width: 280px;
    flex: 0 0 280px;
    background: #191c22;
    border-right: 1px solid #30343d;
    display: flex;
    flex-direction: column;
}

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

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

.new-chat {
    margin: 0 12px 12px;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid #3c424e;
    background: #242832;
    color: #fff;
}

.new-chat:hover {
    background: #303642;
}

#conversationList {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.conversation {
    padding: 11px 12px;
    margin: 3px 0;
    border-radius: 9px;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.conversation:hover {
    background: #252a33;
}

.conversation.active {
    background: #303640;
}

.sidebar-bottom {
    padding: 12px 16px;
    border-top: 1px solid #30343d;
    font-size: 13px;
    color: #aeb5c0;
}

#main {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

#topbar {
    min-height: 64px;
    padding: 10px 16px;
    border-bottom: 1px solid #30343d;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #15181e;
}

#modelSelect {
    min-width: 180px;
    max-width: 350px;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid #3a404b;
    background: #22262e;
    color: #fff;
}

#deleteConversation {
    margin-left: auto;
    padding: 9px 14px;
    border: 1px solid #4a3033;
    border-radius: 8px;
    background: #2b2022;
    color: #f0d9da;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 160px;
}

#welcome {
    max-width: 700px;
    margin: 15vh auto 0;
    text-align: center;
    color: #aeb5c0;
}

#welcome h1 {
    margin-bottom: 5px;
    font-size: 38px;
    color: #f3f3f3;
}

.message {
    max-width: 850px;
    margin: 0 auto 22px;
    display: flex;
}

.message.user {
    justify-content: flex-end;
}

.bubble {
    max-width: 88%;
    padding: 13px 16px;
    border-radius: 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.5;
}

.message.user .bubble {
    background: #2f5f92;
    color: white;
    border-bottom-right-radius: 5px;
}

.message.assistant .bubble {
    background: #20242b;
    border: 1px solid #30353f;
    border-bottom-left-radius: 5px;
}

#composer {
    position: absolute;
    left: 280px;
    right: 0;
    bottom: 0;
    padding: 12px 20px 14px;
    background:
        linear-gradient(
            transparent,
            #111318 22%
        );
}

.composer-row {
    max-width: 900px;
    margin: 0 auto;
    padding: 8px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #22262e;
    border: 1px solid #3a404b;
    border-radius: 16px;
}

#prompt {
    flex: 1;
    resize: none;
    max-height: 180px;
    min-height: 42px;
    padding: 10px;
    border: 0;
    outline: none;
    background: transparent;
    color: #fff;
}

#attachButton,
#sendButton,
#menuButton,
#closeSidebar {
    border: 0;
    border-radius: 9px;
    background: #343a45;
    color: white;
}

#attachButton {
    width: 42px;
    height: 42px;
    font-size: 24px;
}

#sendButton {
    min-width: 70px;
    height: 42px;
    padding: 0 15px;
    background: #356ca5;
}

#sendButton:disabled {
    opacity: .45;
    cursor: default;
}

#attachments {
    max-width: 900px;
    margin: 0 auto 7px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.attachment {
    padding: 6px 9px;
    border-radius: 8px;
    background: #292e37;
    border: 1px solid #3b424d;
    font-size: 12px;
}

.attachment button {
    margin-left: 6px;
    border: 0;
    background: transparent;
    color: #ccc;
}

.hint {
    max-width: 900px;
    margin: 6px auto 0;
    text-align: center;
    color: #777f8b;
    font-size: 11px;
}

.mobile-only {
    display: none;
}

@media (max-width: 760px) {

    #sidebar {
        position: fixed;
        z-index: 20;
        left: -290px;
        top: 0;
        bottom: 0;
        transition: left .2s;
        box-shadow: 5px 0 25px #0008;
    }

    #sidebar.open {
        left: 0;
    }

    .mobile-only {
        display: inline-block;
    }

    #menuButton,
    #closeSidebar {
        width: 40px;
        height: 40px;
    }

    #composer {
        left: 0;
        padding-left: 8px;
        padding-right: 8px;
    }

    #messages {
        padding-left: 10px;
        padding-right: 10px;
    }

    #modelSelect {
        min-width: 0;
        flex: 1;
    }

    .bubble {
        max-width: 95%;
    }

}

/* Bildekvalitet og kontrollrad */

#imageQualityButton {
    height: 42px;
    padding: 0 12px;
    border: 0;
    border-radius: 9px;
    background: #343a45;
    color: white;
    white-space: nowrap;
}

#imageQualityButton.active {
    background: #356ca5;
}

.composer-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}


/* Mobil */
@media (max-width: 760px) {

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

    #prompt {
        width: 100%;
        box-sizing: border-box;
        min-height: 48px;
    }

    .composer-buttons {
        width: 100%;
        display: flex;
        gap: 8px;
    }

    #attachButton {
        flex: 0 0 42px;
    }

    #imageQualityButton {
        flex: 1;
        min-width: 0;
    }

    #sendButton {
        flex: 0 0 auto;
    }
}

/* Mobil composer - alt på én linje */
@media (max-width: 760px) {

    .composer-row {
        flex-direction: row !important;
        align-items: flex-end !important;
        flex-wrap: nowrap !important;
    }

    #prompt {
        flex: 1 1 auto !important;
        width: auto !important;
        min-width: 0 !important;
        min-height: 42px !important;
    }

    .composer-buttons {
        display: flex !important;
        flex: 0 0 auto !important;
        width: auto !important;
        gap: 6px !important;
        align-items: center !important;
    }

    #attachButton {
        flex: 0 0 42px !important;
        width: 42px !important;
    }

    #imageQualityButton {
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: 64px !important;
        padding: 0 8px !important;
        font-size: 13px !important;
    }

    #sendButton {
        flex: 0 0 auto !important;
        min-width: 58px !important;
        padding: 0 10px !important;
    }
}

/* ==================================================
   Composer med egen funksjonslinje
   ================================================== */

.composer-row {
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    align-items: end !important;
    gap: 8px !important;
}

/* Send-knappen flyttes visuelt opp ved tekstfeltet */
.composer-buttons {
    display: contents !important;
}

#prompt {
    grid-column: 1 !important;
    grid-row: 1 !important;
    min-width: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

#sendButton {
    grid-column: 2 !important;
    grid-row: 1 !important;
}

/* Funksjonsknapper under skrivefeltet */
#attachButton {
    grid-column: 1 !important;
    grid-row: 2 !important;
    justify-self: start !important;
}

#imageQualityButton {
    grid-column: 1 !important;
    grid-row: 2 !important;
    justify-self: start !important;
    margin-left: 50px !important;
}


/* Mobil */
@media (max-width: 760px) {

    .composer-row {
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        gap: 8px !important;
    }

    #prompt {
        grid-column: 1 !important;
        grid-row: 1 !important;
        width: 100% !important;
        min-height: 42px !important;
    }

    #sendButton {
        grid-column: 2 !important;
        grid-row: 1 !important;
        height: 42px !important;
    }

    #attachButton {
        grid-column: 1 !important;
        grid-row: 2 !important;
        justify-self: start !important;
        margin: 0 !important;
    }

    #imageQualityButton {
        grid-column: 1 !important;
        grid-row: 2 !important;
        justify-self: start !important;
        margin-left: 50px !important;
    }
}

/* ==================================================
   ENDELIG COMPOSER-LAYOUT
   Øverst: tekst + Send
   Nederst: funksjonsknapper
   ================================================== */

.composer-row,
.function-row {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    background: #22262e;
    border: 1px solid #3a404b;
    border-radius: 16px;
}

/* Skrivefelt */
.composer-row {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: flex-end !important;
    gap: 8px !important;
    padding: 8px !important;
}

#prompt {
    flex: 1 1 auto !important;
    grid-column: auto !important;
    grid-row: auto !important;
    width: auto !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
}

#sendButton {
    flex: 0 0 auto !important;
    grid-column: auto !important;
    grid-row: auto !important;
    margin: 0 !important;
}

/* Egen funksjonslinje */
.function-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 58px;
    margin-top: 8px;
    padding: 8px;
}

.function-row #attachButton {
    flex: 0 0 42px !important;
    grid-column: auto !important;
    grid-row: auto !important;
    justify-self: auto !important;
    margin: 0 !important;
}

.function-row #imageQualityButton {
    flex: 0 0 auto !important;
    grid-column: auto !important;
    grid-row: auto !important;
    justify-self: auto !important;
    margin: 0 !important;
}

/* Mobil */
@media (max-width: 760px) {

    .composer-row,
    .function-row {
        width: 100%;
    }

    #prompt {
        flex: 1 1 auto !important;
        min-width: 0 !important;
    }

    #sendButton {
        flex: 0 0 auto !important;
    }

    .function-row {
        flex-wrap: wrap;
    }
}

/* Plass til skrivefelt + funksjonsfelt nederst */
#messages {
    padding-bottom: 245px;
}

@media (max-width: 760px) {
    #messages {
        padding-bottom: 245px;
    }
}


/* ==================================================
   Bildegenerering
   ================================================== */

#generateImageButton {
    height: 42px;
    padding: 0 14px;
    border: 0;
    border-radius: 9px;
    background: #343a45;
    color: white;
    white-space: nowrap;
}

#generateImageButton:hover {
    background: #404754;
}

#generateImageButton:disabled {
    opacity: .55;
    cursor: default;
}

.generated-image {
    display: block;
    width: auto;
    height: auto;
    max-width: min(512px, 100%);
    border-radius: 10px;
}

.message.assistant .bubble:has(.generated-image) {
    padding: 8px;
}

@media (max-width: 760px) {
    #generateImageButton {
        height: 42px;
        padding: 0 10px;
        font-size: 13px;
    }
}


/* ==================================================
   Bildehandlinger
   ================================================== */

.generated-image-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.generated-image-delete {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    padding: 0;
    margin: 0;
    border: 2px solid rgba(255,255,255,.9);
    border-radius: 50%;
    background: #d93025;
    color: #fff;
    font-size: 26px;
    font-weight: bold;
    line-height: 27px;
    cursor: pointer;
    z-index: 20;
    box-shadow: 0 2px 8px rgba(0,0,0,.45);
}

.generated-image-delete:hover {
    background: #ff3b30;
}

.generated-image-delete:disabled {
    opacity: .5;
    cursor: default;
}

.generated-image-download {
    display: block;
    margin-top: 8px;
    padding: 8px 12px;
    border: 0;
    border-radius: 8px;
    background: #343a45;
    color: white;
    cursor: pointer;
}

.generated-image-download:hover {
    background: #404754;
}


/* ==================================================
   Kodeblokker
   ================================================== */

.code-block {
    margin: 10px 0;
    max-width: 100%;
    border: 1px solid #3b414b;
    border-radius: 9px;
    overflow: hidden;
    background: #11151b;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 9px;
    background: #252b34;
}

.code-language {
    font-size: 12px;
    opacity: .8;
}

.code-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.code-action {
    padding: 5px 9px;
    border: 0;
    border-radius: 6px;
    background: #3b4350;
    color: white;
    cursor: pointer;
    font-size: 12px;
}

.code-action:hover {
    background: #4a5362;
}

.code-block pre {
    margin: 0;
    padding: 12px;
    overflow-x: auto;
    white-space: pre;
}

.code-block code {
    font-family:
        "DejaVu Sans Mono",
        monospace;
    font-size: 13px;
    line-height: 1.45;
}
