* {
    box-sizing: border-box;
}

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

body {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
}

/* APP */

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

/* SIDEBAR */

.sidebar {
    width: 260px;
    min-width: 260px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #f8f8f8;
    border-right: 1px solid #e5e5e5;
}

/* SIDEBAR HEADER */

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: 85px;
    flex-shrink: 0;
    padding: 20px 16px;
}

/* SIDEBAR LOGO */

.sidebar .logo {
    width: 45px;
    height: 45px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.sidebar .logo a {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar .logo img {
    display: block;
    object-fit: contain;
}

.sidebar .logo img.logo-light {
    width: 55px;
    height: 55px;
}

.sidebar .logo img.logo-dark {
    width: 25px;
    height: 25px;
}

/* THEME BUTTON */

.sidebar .theme-toggle {
    flex-shrink: 0;
    width: auto;
    padding: 8px 10px;
    background-color: transparent;
    color: #333333;
    border: 1px solid #dddddd;
    border-radius: 9px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    cursor: pointer;
}

.sidebar .theme-toggle:hover {
    background-color: #eeeeee;
}

/* SIDEBAR CONTENT */

.sidebar-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 12px;
    padding: 0px 8px 8px;
    overflow-y: auto;
}

/* NEW CHAT */

.sidebar-content>button {
    width: 100%;
    height: 42px;
    flex-shrink: 0;
    padding: 0 12px;
    background-color: white;
    border: 1px solid #e0e0e0;
    border-radius: 9px;
    color: black;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    text-align: center;
    cursor: pointer;
}

.sidebar-content>button:hover {
    background-color: #f1f1f1;
}

/* CONVERSATION LIST */

.conversation-list {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* CONVERSATION ITEMS */

.conversation-list>li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 40px;
    padding: 0 12px;
    background-color: transparent;
    border-radius: 9px;
}

.conversation-list>li:hover {
    background-color: #eeeeee;
}

/* SELECTED CONVERSATION */

.conversation-list>li[aria-current="page"] {
    background-color: #e5e5e5;
}

/* CONVERSATION TITLE */

.conversation-list li button:first-child {
    flex: 1;
    min-width: 0;
    padding: 10px 0;
    background-color: transparent;
    border: none;
    color: black;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

/* DELETE BUTTON */

.conversation-list li button:last-child {
    flex-shrink: 0;
    margin-left: 8px;
    padding: 6px 2px;
    background-color: transparent;
    border: none;
    color: #888888;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
}

.conversation-list li:hover button:last-child {
    opacity: 1;
}

.conversation-list li button:last-child:hover {
    color: #111111;
}

/* SIDEBAR ACCOUNT */

.sidebar-account {
    flex-shrink: 0;
    margin-top: auto;
    padding: 12px 16px;
    border-top: 1px solid #e5e5e5;
}

/* SIDEBAR LOGIN */

.sidebar-account>button:not(.sidebar-user) {
    display: block;
    width: 100%;
    height: 38px;
    padding: 0 12px;
    background-color: #111111;
    color: white;
    border: none;
    border-radius: 8px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.sidebar-account>button:not(.sidebar-user):hover {
    background-color: #333333;
}

/* SIDEBAR USERNAME */

.sidebar-account .sidebar-user {
    display: inline;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    background-color: transparent;
    color: black;
    border: none;
    border-radius: 0;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: normal;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.sidebar-account .sidebar-user:hover {
    background-color: transparent;
    color: black;
}

/* MAIN PAGE */

.main {
    flex: 1;
    min-width: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* HEADER */

.header {
    height: 60px;
    flex-shrink: 0;
    padding: 12px 16px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #dddddd;
}

.header button {
    padding: 9px 16px;
    background-color: white;
    color: black;
    border: 1px solid #dddddd;
    border-radius: 9px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    cursor: pointer;
}

.header button:last-child {
    background-color: #111111;
    color: white;
    border-color: #111111;
}

/* HOMEPAGE */

main.homepage {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

main.homepage p {
    margin: 0;
    color: #808080;
    font-size: 16px;
}

/* CONVERSATION PAGE */

main.conversation {
    position: relative;
    flex: 1;
    min-height: 0;
    padding: 36px 48px 32px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* MESSAGES */

.messages {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* LOAD OLDER MESSAGES */

.load-older {
    align-self: center;
    margin-bottom: 32px;
    padding: 8px 14px;
    background-color: white;
    border: 1px solid #dddddd;
    border-radius: 18px;
    color: #555555;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
}

.load-older:hover {
    background-color: #f4f4f4;
}

/* MESSAGE CONTAINERS */

.messages>div {
    margin-top: 0;
    margin-bottom: 40px;
    color: black;
    font-size: 16px;
    overflow-wrap: anywhere;
}

/* USER MESSAGES */

.messages>div[aria-label="user"] {
    align-self: flex-end;
    width: fit-content;
    max-width: 500px;
    margin-right: max(0px, calc((100% - 850px) / 2));
    padding: 12px 16px;
    background-color: #f4f4f4;
    border-radius: 18px;
}

.messages>div[aria-label="user"]>p {
    margin: 0;
}

/* ASSISTANT MESSAGES */

.messages>div[aria-label="assistant"] {
    align-self: center;
    width: 850px;
    max-width: 100%;
    padding: 0;
    background-color: white;
}

/* LOADING MESSAGE */

.messages>div[aria-label="loading"] {
    align-self: center;
    width: 850px;
    max-width: 100%;
    color: #888888;
    font-size: 14px;
}

.messages>div[aria-label="loading"]>p {
    margin: 0;
}

/* ERROR MESSAGE */

.messages>div[aria-label="error"] {
    align-self: center;
    width: 850px;
    max-width: 100%;
    margin-bottom: 28px;
    padding: 0;
    background-color: transparent;
    border: none;
    color: #d9534f;
    font-size: 14px;
}

.messages>div[aria-label="error"]>p {
    margin: 0;
}

/* MESSAGE FORM */

main.conversation .message-form {
    position: relative;
    align-self: center;
    flex-shrink: 0;
    width: 850px;
    max-width: 100%;
    min-height: 90px;
    padding: 14px 16px 52px;
    background-color: #f4f4f4;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* MESSAGE TEXTAREA */

main.conversation .message-form textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 0;
    background-color: transparent;
    border: none;
    outline: none;
    resize: none;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    field-sizing: content;
    min-height: 1lh;
    max-height: 10lh;
    overflow-y: auto;
}

/* MODEL PICKER */

main.conversation .message-form select {
    position: absolute;
    right: 85px;
    bottom: 12px;
    width: 165px;
    height: 32px;
    padding: 4px 12px;
    background-color: #f4f4f4;
    border: 1px solid #cccccc;
    border-radius: 18px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
}

/* SEND BUTTON */

main.conversation .message-form button {
    position: absolute;
    right: 14px;
    bottom: 12px;
    height: 32px;
    padding: 0 18px;
    background-color: black;
    color: white;
    border: none;
    border-radius: 18px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.message-form button[type="submit"]:disabled {
    background-color: #b0b0b0;
}

/* MODAL OVERLAY */

.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

/* MODAL */

.modal {
    position: relative;
    width: 90%;
    max-width: 360px;
    padding: 40px;
    background-color: white;
    border-radius: 16px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.modal h1 {
    margin: 0 0 24px;
    font-size: 24px;
    text-align: center;
}

/* CLOSE BUTTON */

.modal .close-button {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    padding: 0;
    background-color: transparent;
    border: none;
    border-radius: 8px;
    color: #888888;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 20px;
    cursor: pointer;
}

.modal:not(.settings-modal) .close-button {
    background-color: #111111;
    color: white;
}

/* MODAL FORMS */

.modal form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal input {
    width: 100%;
    height: 44px;
    padding: 0 16px;
    background-color: white;
    border: 1px solid #e0e0e0;
    border-radius: 9px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
}

.modal form button[type="submit"] {
    width: 100%;
    height: 42px;
    padding: 0 16px;
    background-color: #111111;
    color: white;
    border: none;
    border-radius: 8px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}

.modal form button[type="submit"]:hover {
    background-color: #333333;
}

/* LOGIN / SIGNUP SWITCH */

.modal button:not(.close-button):not([type="submit"]) {
    padding: 0;
    background-color: transparent;
    color: black;
    border: none;
    border-radius: 0;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
}

/* LOGIN / SIGNUP FOOTER */

.modal:not(.settings-modal) form+p,
.modal:not(.settings-modal) form+div {
    text-align: center;
}

.modal:not(.settings-modal) p:not(.modal-error) {
    text-align: center;
}

.modal:not(.settings-modal) .modal-footer,
.modal:not(.settings-modal) .account-switch,
.modal:not(.settings-modal) .auth-switch {
    text-align: center;
}

/* MODAL ERROR */

.modal-error {
    margin: 0 0 12px;
    color: #d9534f;
    font-size: 14px;
}

/* SETTINGS MODAL */

.settings-modal {
    max-width: 420px;
    padding: 40px;
}

.settings-modal h1 {
    margin-bottom: 24px;
    text-align: center;
}

.settings-section {
    margin-top: 0;
    padding-top: 22px;
    border-top: 1px solid #e0e0e0;
}

.settings-section h2 {
    margin: 0 0 12px;
    color: #888888;
    font-size: 14px;
    font-weight: bold;
    text-align: left;
}

/* SETTINGS LOGOUT */

.settings-logout {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.settings-logout button {
    display: block;
    width: 100%;
    height: 44px;
    padding: 0;
    background-color: white;
    color: black;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    font-weight: normal;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.settings-logout button:hover {
    background-color: #f7f7f7;
}

/* SETTINGS LOGOUT BUTTON OVERRIDE */

.settings-modal .settings-logout button {
    display: block;
    width: 100%;
    height: 44px;
    padding: 0;
    background-color: white;
    color: black;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    font-weight: normal;
    text-align: center;
    text-decoration: none;
}

.settings-modal .settings-logout button:hover {
    background-color: #f7f7f7;
}

.modal-error {
    text-align: center;
}

/* RESPONSIVE CHAT */

@media (max-width: 1150px) {
    main.conversation {
        padding-left: 24px;
        padding-right: 24px;
    }

    .messages>div[aria-label="user"] {
        margin-right: 0;
    }
}

@media (max-width: 700px) {
    .sidebar {
        width: 200px;
        min-width: 200px;
    }

    main.conversation .message-form {
        max-width: 100%;
    }

    main.conversation .message-form select {
        right: 75px;
        width: 120px;
    }
}

.success-message {
    color: green;
    text-align: center;
}

/* DARK MODE */

.app[data-theme="dark"] {
    background-color: #171717;
    color: #eeeeee;
}

.app[data-theme="dark"] .sidebar {
    background-color: #202020;
    border-right-color: #333333;
}

.app[data-theme="dark"] .sidebar-content>button,
.app[data-theme="dark"] .header button:not(:last-child) {
    background-color: #303030;
    color: #eeeeee;
    border-color: #444444;
}

.app[data-theme="dark"] .sidebar-content>button:hover,
.app[data-theme="dark"] .conversation-list>li:hover {
    background-color: #353535;
}

.app[data-theme="dark"] .conversation-list>li[aria-current="page"] {
    background-color: #404040;
}

.app[data-theme="dark"] .conversation-list li button:first-child,
.app[data-theme="dark"] .sidebar-account .sidebar-user {
    color: #eeeeee;
}

.app[data-theme="dark"] .conversation-list li button:last-child:hover {
    color: white;
}

.app[data-theme="dark"] .sidebar-account,
.app[data-theme="dark"] .header {
    border-color: #333333;
}

.app[data-theme="dark"] .main,
.app[data-theme="dark"] main.conversation,
.app[data-theme="dark"] main.homepage {
    background-color: #171717;
    color: #eeeeee;
}

.app[data-theme="dark"] .messages>div {
    color: #eeeeee;
}

.app[data-theme="dark"] .messages>div[aria-label="user"] {
    background-color: #303030;
}

.app[data-theme="dark"] .messages>div[aria-label="assistant"] {
    background-color: #171717;
}

.app[data-theme="dark"] .messages>div[aria-label="loading"] {
    color: #aaaaaa;
}

.app[data-theme="dark"] .messages>div[aria-label="error"],
.app[data-theme="dark"] .modal-error {
    color: #ff7777;
}

.app[data-theme="dark"] .load-older {
    background-color: #303030;
    color: #eeeeee;
    border-color: #444444;
}

.app[data-theme="dark"] .load-older:hover {
    background-color: #404040;
}

.app[data-theme="dark"] main.conversation .message-form {
    background-color: #303030;
    border-color: #444444;
}

.app[data-theme="dark"] main.conversation .message-form textarea {
    color: #eeeeee;
}

.app[data-theme="dark"] main.conversation .message-form textarea::placeholder {
    color: #aaaaaa;
}

.app[data-theme="dark"] main.conversation .message-form select {
    background-color: #303030;
    color: #eeeeee;
    border-color: #555555;
}

.app[data-theme="dark"] main.conversation .message-form button:not(:disabled) {
    background-color: #eeeeee;
    color: #171717;
}

.app[data-theme="dark"] .modal {
    background-color: #262626;
    color: #eeeeee;
}

.app[data-theme="dark"] .modal input {
    background-color: #303030;
    color: #eeeeee;
    border-color: #555555;
}

.app[data-theme="dark"] .modal button:not(.close-button):not([type="submit"]) {
    color: #eeeeee;
}

.app[data-theme="dark"] .settings-section,
.app[data-theme="dark"] .settings-logout {
    border-color: #444444;
}

.app[data-theme="dark"] .settings-modal .settings-logout button {
    background-color: #303030;
    color: #eeeeee;
    border-color: #555555;
}

.app[data-theme="dark"] .settings-modal .settings-logout button:hover {
    background-color: #404040;
}

/* DARK MODE SIDEBAR HEADER */

.app[data-theme="dark"] .sidebar .theme-toggle {
    background-color: transparent;
    color: #eeeeee;
    border-color: #444444;
}

.app[data-theme="dark"] .sidebar .theme-toggle:hover {
    background-color: #353535;
}