:root {
    --bg-color: #0b141a;
    --header-bg: rgba(32, 44, 51, 0.7);
    /* Translucent for glass effect */
    --msg-incoming: #202c33;
    --msg-outgoing: #005c4b;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --accent: #00a884;
    --accent-hover: #008f6f;
    --modal-bg: rgba(22, 27, 34, 0.75);
    /* Deep glass */
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 900px;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-repeat: repeat;
    background-size: 400px;
    box-shadow: var(--shadow-md);
    position: relative;
    border-left: 1px solid var(--glass-border);
    border-right: 1px solid var(--glass-border);
}

.app-container::before {
    content: "";
    position: absolute;
    inset: 0;
    background-color: rgba(11, 20, 26, 0.96);
    /* Slightly darker tint */
    z-index: 0;
    backdrop-filter: blur(2px);
}

.chat-header,
.chat-area,
.chat-controls {
    position: relative;
    z-index: 1;
}

/* --- Header --- */
.chat-header {
    background-color: var(--header-bg);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
}

.header-profile {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatars {
    position: relative;
    width: 48px;
    height: 48px;
}

.avatars img {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid #202c33;
    /* Match header solid color fallback */
    position: absolute;
    transition: transform 0.2s;
}

.avatars img:hover {
    transform: scale(1.1);
    z-index: 5 !important;
}

#avatar-a {
    top: 0;
    left: 0;
    z-index: 2;
}

#avatar-b {
    bottom: 0;
    right: 0;
    z-index: 1;
}

.header-info h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

#chat-status {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.icon-btn.active {
    background-color: rgba(0, 168, 132, 0.15);
    color: var(--accent);
}

/* --- Chat Area --- */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.message-row {
    display: flex;
    width: 100%;
}

.message-row.msg-a {
    justify-content: flex-start;
}

.message-row.msg-b {
    justify-content: flex-end;
}

.message-row.msg-sys {
    justify-content: center;
    margin: 10px 0;
}

.bubble {
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    position: relative;
    max-width: 70%;
    font-size: 15px;
    line-height: 1.5;
    animation: messageEntry 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: bottom center;
    color: var(--text-primary);
}

.message-row.msg-a .bubble {
    background-color: var(--msg-incoming);
    border-bottom-left-radius: 2px;
    transform-origin: bottom left;
}

.message-row.msg-b .bubble {
    background-color: var(--msg-outgoing);
    border-bottom-right-radius: 2px;
    transform-origin: bottom right;
}

.msg-sys .bubble {
    background: rgba(32, 44, 51, 0.85);
    font-size: 12px;
    color: var(--accent);
    text-align: center;
    padding: 6px 16px;
    border-radius: 20px;
    box-shadow: none;
    backdrop-filter: blur(4px);
    border: 1px solid var(--glass-border);
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

/* Hover Actions */
.msg-actions {
    position: absolute;
    top: -10px;
    right: 10px;
    background: #233138;
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 4px 8px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transform: translateY(5px);
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.bubble:hover .msg-actions {
    opacity: 1;
    transform: translateY(0);
}

.msg-actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
}

.msg-actions button:hover {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.05);
}

/* --- Controls --- */
.chat-controls {
    background-color: var(--header-bg);
    padding: 16px;
    display: flex;
    justify-content: center;
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--glass-border);
}

.control-group {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 650px;
}

.action-btn {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.action-btn:active {
    transform: scale(0.97);
}

.btn-a {
    background-color: #37404a;
    /* Neutral Dark for A */
    color: var(--text-primary);
    flex: 2;
}

.btn-a:hover {
    background-color: #434c56;
}

.btn-b {
    background: linear-gradient(135deg, var(--accent) 0%, #008f6f 100%);
    color: #fff;
    flex: 2;
}

.btn-b:hover {
    filter: brightness(1.1);
}

.btn-a-manual,
.btn-b-manual {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    flex: 0.6;
    border: 1px solid var(--glass-border);
}

.btn-a-manual:hover,
.btn-b-manual:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* --- Modals --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--modal-bg);
    width: 90%;
    max-width: 600px;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-weight: 600;
    font-size: 18px;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input,
select,
textarea {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    background-color: rgba(0, 0, 0, 0.3);
}

.save-btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.save-btn:hover {
    background-color: var(--accent-hover);
}

.cancel-btn {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.cancel-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-primary);
}

.cols {
    display: flex;
    gap: 24px;
}

.col {
    flex: 1;
}

/* Animations */
@keyframes messageEntry {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Mobile */
@media (max-width: 768px) {
    .app-container {
        border: none;
        border-radius: 0;
    }

    .cols {
        flex-direction: column;
        gap: 0;
    }

    .bubble {
        max-width: 85%;
    }

    .msg-actions {
        display: flex !important;
        opacity: 1;
        background: transparent;
        position: static;
        margin-top: 8px;
        justify-content: flex-end;
        border: none;
        padding: 0;
        box-shadow: none;
        transform: none;
    }

    .msg-actions button {
        background: rgba(255, 255, 255, 0.05);
        padding: 8px;
        border-radius: 8px;
        margin-left: 8px;
    }

    .control-group {
        flex-direction: column;
    }

    .action-btn {
        padding: 16px;
        font-size: 16px;
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    height: 100vh;
    height: 100dvh;
    /* Mobile Safari fix */
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 900px;
    height: 100%;
    height: 100dvh;
    /* Mobile Safari fix */
    display: flex;
    flex-direction: column;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-repeat: repeat;
    background-size: 400px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    position: relative;
}

.app-container::before {
    content: "";
    position: absolute;
    inset: 0;
    background-color: rgba(11, 20, 26, 0.95);
    /* Tint for dark mode */
    z-index: 0;
}

.chat-header,
.chat-area,
.chat-controls {
    position: relative;
    z-index: 1;
}

/* Header */
.chat-header {
    background-color: var(--header-bg);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.header-profile {
    display: flex;
    align-items: center;
    gap: 15px;
}

.avatars {
    position: relative;
    width: 50px;
    height: 50px;
}

.avatars img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 2px solid var(--header-bg);
    position: absolute;
}

#avatar-a {
    top: 0;
    left: 0;
    z-index: 2;
}

#avatar-b {
    bottom: 0;
    right: 0;
    z-index: 1;
}

.header-info h2 {
    font-size: 16px;
    font-weight: 500;
}

#chat-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
}

.icon-btn:hover,
.icon-btn.active {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

.icon-btn.active {
    color: var(--accent);
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.message-row {
    display: flex;
    width: 100%;
}

.message-row.msg-a {
    justify-content: flex-start;
}

.message-row.msg-b {
    justify-content: flex-end;
}

.message-row.msg-sys {
    justify-content: center;
}

.bubble {
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    position: relative;
    max-width: 65%;
    font-size: 14.2px;
    line-height: 19px;
    animation: fadeIn 0.3s ease;
    cursor: pointer;
}

.bubble:hover .msg-actions {
    display: flex;
}

.msg-a .bubble {
    background-color: var(--msg-incoming);
    border-top-left-radius: 0;
}

.msg-b .bubble {
    background-color: var(--msg-outgoing);
    border-top-right-radius: 0;
}

.msg-sys .bubble {
    background-color: rgba(32, 44, 51, 0.8);
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    border-radius: 8px;
    padding: 5px 10px;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 4px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
}

.msg-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 4px;
    padding: 2px;
    display: none;
    gap: 4px;
}

.msg-actions button {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
}

.msg-actions button:hover {
    color: var(--accent);
}

/* Controls */
.chat-controls {
    background-color: var(--header-bg);
    padding: 10px 16px;
    display: flex;
    justify-content: center;
}

.control-group {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 600px;
}

.action-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 24px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s, opacity 0.2s;
}

.action-btn:active {
    transform: scale(0.98);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-a {
    background-color: #3b4a54;
    color: var(--text-primary);
    flex: 2;
}

.btn-b {
    background-color: var(--accent);
    color: #fff;
    flex: 2;
}

.btn-a-manual {
    background-color: transparent;
    border: 1px solid #3b4a54;
    color: var(--text-primary);
    flex: 0.5;
}

.btn-b-manual {
    background-color: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    flex: 0.5;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.hidden {
    display: none;
}

.modal-content {
    background: var(--msg-incoming);
    width: 90%;
    max-width: 800px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.small-modal {
    max-width: 500px;
    padding: 20px;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.cols {
    display: flex;
    gap: 20px;
}

.col {
    flex: 1;
}

.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    font-size: 13px;
    color: var(--accent);
    margin-bottom: 5px;
    font-weight: 500;
}

input,
select,
textarea {
    width: 100%;
    background-color: var(--bg-color);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 6px;
    font-family: inherit;
}

textarea {
    resize: vertical;
}

.save-btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
}

.cancel-btn {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .cols {
        flex-direction: column;
        gap: 0;
    }

    .col {
        margin-bottom: 20px;
    }

    .chat-header {
        padding: 10px 12px;
    }

    .app-container {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
    }

    .bubble {
        max-width: 85%;
        font-size: 15px;
    }

    /* Larger text/bubbles on mobile */

    .modal-content {
        width: 100%;
        height: 100%;
        max-width: 100%;
        border-radius: 0;
        max-height: 100vh;
    }

    .control-group {
        flex-direction: column;
    }

    /* Stack buttons on mobile */

    .small-modal {
        height: auto;
        border-radius: 12px;
        width: 90%;
    }

    /* Mobile: Show actions always, as there is no hover */
    .bubble .msg-actions {
        display: flex !important;
        opacity: 1;
        background: transparent;
        position: static;
        margin-top: 6px;
        justify-content: flex-end;
        gap: 12px;
        /* Easier to tap */
        border-top: 1px solid rgba(255, 255, 255, 0.05);
        padding-top: 5px;
        min-height: 30px;
        /* Ensure height */
    }

    .msg-actions button {
        font-size: 16px;
        /* Larger icons for touch */
        padding: 8px 10px;
        /* Generous touch target */
        color: var(--text-secondary);
        background: rgba(255, 255, 255, 0.05);
        /* Slight background for button itself for better hit area perception */
        border-radius: 4px;
    }

    .bubble {
        padding-bottom: 8px;
    }

    .chat-controls {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
        /* More generous spacing */
    }
}