:root {
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --bg-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-teal: #0d9488;
    --accent-teal-hover: #0f766e;
    --accent-orange: #ea580c;
    --accent-green: #16a34a;
    --accent-red: #dc2626;
    --border: #334155;
    
    --msg-user: #334155;
    --msg-assistant: #065f46;
    --msg-admin: #7c2d12;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh; /* fallback for older browsers */
    height: 100dvh;
    overflow: hidden;
}

/* Login Screen */
#login-screen {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-dark);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
#login-screen.active {
    display: flex;
}
.login-card {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    text-align: center;
}
.login-card h2 { margin-bottom: 1.5rem; }
.login-card input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 1rem;
}
.login-card button {
    width: 100%;
    padding: 0.75rem;
    border-radius: 6px;
    border: none;
    background: var(--accent-teal);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

/* App Layout (Mobile First) */
#app-container {
    display: none;
    height: 100vh; /* fallback */
    height: 100dvh;
    width: 100vw;
    position: relative;
    overflow: hidden;
}
#app-container.active {
    display: flex;
}

.sidebar, .main-panel, .right-panel {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 1;
}

/* Base transform hides everything to the right initially */
.sidebar, .main-panel, .right-panel {
    transform: translateX(100%);
}

/* The active view is translated to 0 */
#app-container.view-sidebar .sidebar { transform: translateX(0); z-index: 2; }
#app-container.view-main .main-panel { transform: translateX(0); z-index: 2; }
#app-container.view-info .right-panel { transform: translateX(0); z-index: 2; }

/* Desktop Overrides */
@media (min-width: 992px) {
    #app-container.active {
        flex-direction: row;
    }
    
    .sidebar, .main-panel, .right-panel {
        position: static;
        transform: none !important;
    }
    
    .sidebar {
        width: 320px;
        flex-shrink: 0;
        border-right: 1px solid var(--border);
    }
    
    .main-panel {
        flex: 1;
        background: var(--bg-dark);
    }
    
    .right-panel {
        width: 300px;
        flex-shrink: 0;
        border-left: 1px solid var(--border);
    }
}

.right-panel {
    padding: 1.5rem;
    overflow-y: auto;
}

/* Visibility Utilities */
.mobile-only {
    display: block;
}
.desktop-only {
    display: none;
}

@media (min-width: 992px) {
    .mobile-only {
        display: none !important;
    }
    .desktop-only {
        display: block !important;
    }
}

/* Sidebar */
.sidebar {
    min-height: 0;
    overflow: hidden;
}
.sidebar-header {
    padding: 1.25rem 1rem 0.75rem;
    border-bottom: 1px solid var(--border);
    position: relative;
    flex-shrink: 0;
    overflow: visible;
}
.conversation-list {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    position: relative;
}

.header-menu-container {
    position: relative;
}

.header-menu-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-menu-toggle:hover,
.header-menu-toggle.active {
    background: var(--bg-hover);
    color: var(--text-main);
}

.header-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 220px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: dropdownFadeIn 0.15s ease-out;
}

.header-dropdown-menu.hidden {
    display: none;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.dropdown-item i {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: color 0.15s;
}

.dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.dropdown-item:hover i {
    color: var(--accent-teal);
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}
.search-container {
    position: relative;
    width: 100%;
    margin-top: 0.75rem;
    box-sizing: border-box;
}
.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    width: 16px;
    height: 16px;
    pointer-events: none;
    transition: color 0.2s ease;
}
#search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.55rem 1rem 0.55rem 2.35rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 0.85rem;
    line-height: 1.2;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
#search-input::placeholder {
    color: var(--text-muted);
    font-size: 0.825rem;
}
#search-input:focus {
    border-color: var(--accent-teal);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.2);
    background: var(--bg-panel);
}
.search-container:focus-within .search-icon {
    color: var(--accent-teal);
}


.conv-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
}
.conv-item:hover, .conv-item.active {
    background: var(--bg-hover);
}
.conv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.conv-name { font-weight: 600; font-size: 1rem; }
.conv-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: right;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1.3;
}
.conv-preview {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.badges { display: flex; gap: 0.5rem; margin-top: 0.25rem; }
.badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 700;
}
.badge.client { background: var(--accent-teal); color: white; }
.badge.lead { background: var(--bg-dark); color: var(--text-secondary); border: 1px solid var(--border); }
.badge.returning { background: #8b5cf6; color: white; }
.badge.unread { background: var(--accent-orange); color: white; }

.status-dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;
}
.status-dot.bot { background: var(--accent-green); }
.status-dot.human { background: var(--accent-orange); }

.conv-item.escalated {
    border-left: 4px solid var(--accent-red);
}

/* Thread View */
#empty-state { display: none; height: 100%; align-items: center; justify-content: center; text-align: center; color: var(--text-secondary); }
#empty-state.active { display: flex; }
#thread-view { display: none; flex: 1; min-height: 0; flex-direction: column; }
#thread-view.active { display: flex; }

.thread-header {
    padding: 0.75rem 1rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-height: 0;
}
.contact-info {
    min-width: 0;
    flex-shrink: 1;
}
.contact-name-row { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.contact-name-row h2 {
    font-size: 1.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.contact-info p { color: var(--text-secondary); font-size: 0.875rem; }
.icon-btn { background: none; border: none; color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; flex-shrink: 0; }
.icon-btn:hover { color: var(--text-primary); }

/* Thread & Conversations Refresh Buttons */
#thread-refresh-btn, #conversations-refresh-btn {
    padding: 6px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}
#thread-refresh-btn:hover, #conversations-refresh-btn:hover {
    background: var(--hover);
    color: var(--accent);
}
#thread-refresh-btn svg, #conversations-refresh-btn svg {
    width: 18px;
    height: 18px;
}
#thread-refresh-btn.spinning svg, #conversations-refresh-btn.spinning svg {
    animation: spin-refresh 0.6s ease-in-out;
}
@keyframes spin-refresh {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.mode-toggle-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.mode-switch-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.mode-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    white-space: nowrap;
    text-transform: uppercase;
}
.mode-label.bot-mode { color: var(--accent-green); }
.mode-label.human-mode { color: var(--text-secondary); }

.quick-catchup-btn {
    padding: 4px 10px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Switch Toggle */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--accent-green); transition: .3s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: white; transition: .3s; }
input:checked + .slider { background-color: var(--accent-orange); }
input:checked + .slider:before { transform: translateX(18px); }
.slider.round { border-radius: 22px; }
.slider.round:before { border-radius: 50%; }

/* Mobile utility */
.mobile-only { display: none !important; }

.escalation-banner {
    background: rgba(220, 38, 38, 0.2);
    border-bottom: 1px solid var(--accent-red);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    color: #fca5a5;
}
.escalation-banner.hidden { display: none; }
.escalation-banner i { color: var(--accent-red); }
#resolve-escalation-btn {
    margin-left: auto;
    background: var(--accent-red);
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

.message-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    position: relative;
}
.message .time {
    display: block;
    font-size: 0.6rem;
    margin-top: 0.5rem;
    opacity: 0.7;
    text-align: right;
    white-space: nowrap;
}

.msg-user {
    align-self: flex-start;
    background: var(--msg-user);
    border-bottom-left-radius: 2px;
}
.msg-assistant {
    align-self: flex-end;
    background: var(--msg-assistant);
    border-bottom-right-radius: 2px;
}
.msg-admin {
    align-self: flex-end;
    background: var(--msg-admin);
    border-bottom-right-radius: 2px;
}

/* Chat Media Image Styles */
.chat-media-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 280px;
}
.chat-media-wrapper a {
    text-decoration: none;
    display: block;
}
.chat-media-img {
    width: 100%;
    min-height: 140px;
    max-height: 260px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    transition: transform 0.2s ease, filter 0.2s ease;
    cursor: pointer;
    display: block;
}
.chat-media-img:hover {
    filter: brightness(1.08);
    transform: scale(1.015);
}
.chat-media-info {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.chat-media-caption {
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.3;
}
.chat-media-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: #38bdf8;
    text-decoration: none;
    font-weight: 500;
    margin-top: 2px;
}
.chat-media-download-btn:hover {
    text-decoration: underline;
}

/* Image Lightbox Modal */
#media-lightbox-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
#media-lightbox-modal.active {
    opacity: 1;
    pointer-events: auto;
}
.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.lightbox-img {
    max-width: 100%;
    max-height: 82vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.lightbox-actions {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.lightbox-close-btn {
    position: absolute;
    top: -40px;
    right: 0;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
}
.lightbox-close-btn:hover {
    opacity: 1;
}

.reply-box {
    padding: 1rem 1.5rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
}
#reply-form {
    display: flex;
    gap: 0.5rem;
}
#reply-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    outline: none;
}
#reply-input:disabled { opacity: 0.5; cursor: not-allowed; }
#reply-submit {
    width: 42px; height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--accent-teal);
    color: white;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
#reply-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.reply-warning { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.5rem; text-align: center;}
.hidden { display: none !important; }

/* Right Panel */
.panel-section { margin-bottom: 2rem; }
.panel-section h3 { font-size: 0.85rem; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 1rem; letter-spacing: 0.05em;}
.details-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.85rem;
}
.details-row { display: flex; justify-content: space-between; margin-bottom: 0.5rem; }
.details-row:last-child { margin-bottom: 0; }
.details-label { color: var(--text-secondary); }

.command-group { margin-bottom: 1.5rem; }
.command-group h4 { font-size: 0.75rem; color: var(--accent-teal); margin-bottom: 0.5rem; }
.cmd-btn {
    width: 100%;
    text-align: left;
    padding: 0.75rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.cmd-btn:hover { background: var(--bg-hover); border-color: var(--accent-teal); }

/* Modals */
.modal {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7); z-index: 100;
    align-items: center; justify-content: center;
}
.modal.active { display: flex; }
.modal-content {
    background: var(--bg-panel); padding: 2rem; border-radius: 12px;
    width: 90%; max-width: 400px; max-height: 90vh; overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.25rem; }
.modal-content h3 { margin-bottom: 1.5rem; }
.modal-content input[type="text"] {
    width: 100%; padding: 0.75rem; margin-bottom: 1rem; border-radius: 6px;
    border: 1px solid var(--border); background: var(--bg-dark); color: white;
}
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.5rem; cursor: pointer;}
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; }
.btn-secondary { padding: 0.5rem 1rem; background: transparent; border: 1px solid var(--border); color: white; border-radius: 6px; cursor: pointer;}
.btn-primary { padding: 0.5rem 1rem; background: var(--accent-teal); border: none; color: white; border-radius: 6px; cursor: pointer;}
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.6; cursor: not-allowed; }

.cmd-param-input {
    margin-bottom: 1rem;
}
.cmd-param-input label {
    display: block; font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 0.25rem;
}
/* Settings Modal */
.settings-modal {
    width: 900px;
    max-width: 90vw !important;
    height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.settings-layout {
    display: flex;
    flex-direction: column;
    height: calc(100% - 60px);
    border-top: 1px solid var(--border);
    overflow: hidden;
}

.settings-sidebar {
    width: 100%;
    flex: 1;
    border-bottom: 1px solid var(--border);
    border-right: none;
    background: var(--bg-dark);
    overflow-y: auto;
    padding: 16px;
}

@media (min-width: 768px) {
    .settings-layout {
        flex-direction: row;
    }
    .settings-sidebar {
        width: 300px;
        flex: none;
        border-right: 1px solid var(--border);
        border-bottom: none;
    }
}

@media (max-width: 768px) {
    #settings-modal.view-editor .settings-sidebar {
        display: none;
    }
    #settings-modal.view-editor .settings-editor {
        display: block !important;
    }
}

.settings-cmd-item {
    padding: 12px 16px;
    margin-bottom: 8px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-cmd-item:hover {
    border-color: var(--accent-teal);
}

.settings-cmd-item.active {
    background: var(--bg-hover);
    border-color: var(--accent-teal);
}

.settings-cmd-item .cmd-name {
    font-weight: 600;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-cmd-item .cmd-cat {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.settings-cmd-item .status-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(22, 163, 74, 0.2);
    color: #86efac;
    border: 1px solid rgba(22, 163, 74, 0.4);
}

.settings-cmd-item .status-badge.inactive {
    background: rgba(220, 38, 38, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(220, 38, 38, 0.4);
}

.settings-editor {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.settings-editor .form-group {
    margin-bottom: 20px;
}

.settings-editor label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.settings-editor .hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: normal;
}

.settings-editor input[type="text"],
.settings-editor textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
}

.settings-editor input[type="text"]:focus,
.settings-editor textarea:focus {
    border-color: var(--accent-teal);
    outline: none;
}

.settings-editor .form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 30px;
}

/* ── Bungalow Codes ── */
.bungalow-modal {
    max-width: 1100px;
    width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.bungalow-grid-wrapper {
    flex: 1;
    overflow: auto;
    margin-top: 1rem;
}

.bungalow-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 750px;
}

.bungalow-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.bungalow-table th {
    background: var(--bg-dark);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.bungalow-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bungalow-table td.notes-cell {
    max-width: 200px;
}

.bungalow-table tbody tr {
    transition: background 0.15s;
}

.bungalow-table tbody tr:hover {
    background: var(--bg-hover);
}

.bungalow-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.bungalow-table tbody tr:nth-child(even):hover {
    background: var(--bg-hover);
}

.bungalow-actions {
    display: flex;
    gap: 4px;
    white-space: nowrap;
}

.bungalow-actions button {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    transition: all 0.15s;
}

.bungalow-actions button:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.bungalow-actions .btn-delete:hover {
    color: var(--accent-red);
    border-color: var(--accent-red);
}

.bungalow-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.bungalow-name-cell {
    font-weight: 600;
    color: var(--accent-teal) !important;
}

.bungalow-code-cell {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    letter-spacing: 0.08em;
}

/* Cards hidden on desktop, shown on mobile */
.bungalow-card { display: none; }

/* ── Responsive / Mobile ── */
@media (max-width: 768px) {
    .mobile-only { display: flex !important; }

    .thread-header {
        padding: 0.5rem 0.75rem;
        flex-wrap: nowrap;
        gap: 0.25rem;
    }

    .contact-info {
        flex: 1;
        min-width: 0;
    }

    .contact-name-row h2 {
        font-size: 1rem;
        max-width: 120px;
    }

    .contact-info p {
        font-size: 0.75rem;
    }

    /* Compact the toggle on mobile */
    .mode-toggle-container {
        gap: 0.25rem;
    }

    .mode-switch-group {
        gap: 0.2rem;
    }

    .mode-label {
        font-size: 0.6rem;
    }

    .switch {
        width: 34px;
        height: 18px;
    }

    .slider:before {
        height: 12px;
        width: 12px;
    }

    input:checked + .slider:before {
        transform: translateX(16px);
    }

    .quick-catchup-btn {
        padding: 3px 6px;
        font-size: 0.7rem;
    }

    .quick-catchup-btn i {
        width: 12px !important;
        height: 12px !important;
    }

    .conv-time {
        font-size: 0.65rem;
    }

    .message .time {
        font-size: 0.55rem;
    }

    .message {
        max-width: 85%;
    }

    /* Bungalow modal – full screen on mobile */
    .bungalow-modal {
        width: 100vw;
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        padding: 1rem;
    }

    .bungalow-modal .modal-header h2 {
        font-size: 1.1rem;
    }

    /* Switch to card layout on mobile instead of table */
    .bungalow-table {
        display: none;
    }

    .bungalow-grid-wrapper {
        margin-top: 0.75rem;
    }

    /* Card-based rendering for mobile — injected via JS */
    .bungalow-card {
        display: block;
        background: var(--bg-dark);
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 1rem;
        margin-bottom: 0.75rem;
    }

    .bungalow-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.75rem;
    }

    .bungalow-card-header .bungalow-card-name {
        font-weight: 700;
        font-size: 1rem;
        color: var(--accent-teal);
    }

    .bungalow-card-row {
        display: flex;
        justify-content: space-between;
        padding: 4px 0;
        font-size: 0.85rem;
        border-bottom: 1px solid rgba(255,255,255,0.05);
    }

    .bungalow-card-row:last-child {
        border-bottom: none;
    }

    .bungalow-card-label {
        color: var(--text-secondary);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }

    .bungalow-card-value {
        color: var(--text-primary);
        font-weight: 500;
        text-align: right;
        max-width: 60%;
        word-break: break-word;
    }

    .bungalow-card-value.code {
        font-family: 'Courier New', monospace;
        font-weight: 700;
        letter-spacing: 0.08em;
    }

    .bungalow-card-notes {
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid var(--border);
        font-size: 0.8rem;
        color: var(--text-secondary);
        line-height: 1.4;
    }

    /* Bungalow form: stack 2-col grids */
    #bungalow-form-modal .modal-content {
        width: 95%;
        max-width: 95%;
        padding: 1.5rem;
    }

    #bungalow-form-modal [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
    }
}

/* ── Pricing Management Styles ── */
.pricing-modal-content {
    max-width: 1200px;
    width: 95vw;
    height: 90vh;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.pricing-tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    overflow-x: auto;
    white-space: nowrap;
}

.pricing-tab-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.pricing-tab-btn:hover {
    color: var(--text-primary);
}

.pricing-tab-btn.active {
    color: var(--accent-teal);
    border-bottom-color: var(--accent-teal);
}

.pricing-tab-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pricing-tab-panel {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    overflow-y: auto;
    position: relative;
}

.pricing-tab-panel.active {
    display: flex;
}

/* Tab loading overlay */
.pricing-tab-panel.tab-loading {
    pointer-events: none;
}

.pricing-tab-panel.tab-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(8, 12, 20, 0.55);
    border-radius: 8px;
    z-index: 5;
}

.pricing-tab-panel.tab-loading::before {
    content: '';
    position: absolute;
    top: 45%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid rgba(20, 184, 166, 0.25);
    border-top-color: var(--accent-teal);
    border-radius: 50%;
    animation: hbb-tab-spin 0.7s linear infinite;
    z-index: 6;
}

@keyframes hbb-tab-spin {
    to { transform: rotate(360deg); }
}

/* Conversation list / thread loading spinner */
.list-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    padding: 1.5rem 0;
}

.list-loading::before {
    content: '';
    width: 28px;
    height: 28px;
    border: 3px solid rgba(20, 184, 166, 0.25);
    border-top-color: var(--accent-teal);
    border-radius: 50%;
    animation: hbb-tab-spin 0.7s linear infinite;
}

.list-loading-error {
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
    font-size: 0.85rem;
}

.pricing-grid-wrapper {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.pricing-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 750px;
}

.pricing-table thead {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-dark);
}

.pricing-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.pricing-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}

.pricing-table tbody tr:hover {
    background: var(--bg-hover);
}

.matrix-table input.matrix-price-input {
    width: 80px;
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.85rem;
    text-align: right;
}

.matrix-table input.matrix-price-input.modified {
    border-color: var(--accent-orange);
    background: rgba(234, 88, 12, 0.15);
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
}

.btn-delete {
    background: rgba(220, 38, 38, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(220, 38, 38, 0.3);
}

.btn-delete:hover {
    background: var(--accent-red);
    color: white;
}

.form-select-sm {
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 0.8rem;
}

/* Seasons List */
.seasons-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.season-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.season-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

.season-card-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-teal);
}

.season-card-code {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-left: 4px;
}

.season-card-priority {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 10px;
    background: var(--bg-hover);
    padding: 2px 6px;
    border-radius: 4px;
}

.periods-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.period-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

.period-notes {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-left: 6px;
}

.overlap-warning-badge {
    font-size: 0.7rem;
    background: rgba(234, 88, 12, 0.2);
    color: #fdba74;
    border: 1px solid rgba(234, 88, 12, 0.4);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    font-weight: 600;
}

/* Promotions List */
.promotions-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.promotion-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.promotion-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.promotion-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    margin-right: 8px;
}

.promo-prices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
    margin-top: 0.5rem;
    background: var(--bg-panel);
    padding: 0.5rem;
    border-radius: 6px;
}

.promo-price-chip {
    font-size: 0.75rem;
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    background: var(--bg-dark);
    border-radius: 4px;
    border: 1px solid var(--border);
}

.pricing-cards-container {
    display: none;
}

@media (max-width: 768px) {
    .pricing-modal-content {
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        padding: 1rem;
    }

    .pricing-table:not(.matrix-table) {
        display: none;
    }

    .pricing-cards-container {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.5rem;
    }

    .pricing-card {
        background: var(--bg-dark);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 0.75rem;
    }

    .pricing-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.5rem;
        border-bottom: 1px solid var(--border);
        padding-bottom: 0.4rem;
    }

    .pricing-card-title {
        font-weight: 700;
        font-size: 0.9rem;
        color: var(--accent-teal);
    }

    .pricing-card-row {
        display: flex;
        justify-content: space-between;
        font-size: 0.8rem;
        padding: 3px 0;
        color: var(--text-secondary);
    }

    .pricing-card-row span:last-child {
        color: var(--text-primary);
    }
}

/* ── Bookings & Template Management Styles ── */
.bookings-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 65vh;
    overflow-y: auto;
    padding-right: 4px;
}

.booking-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.85rem 1.1rem;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.booking-card:hover {
    border-color: var(--accent-teal);
    transform: translateY(-1px);
}

.booking-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.booking-guest-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-right: 0.5rem;
}

.booking-phone {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

.booking-ref {
    font-size: 0.75rem;
    color: var(--accent-teal);
    background: rgba(13, 148, 136, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
}

.booking-total {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent-teal);
}

.booking-card-body {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.booking-status-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.status-pending { background: rgba(234, 179, 8, 0.2); color: #fde047; }
.status-confirmed { background: rgba(13, 148, 136, 0.2); color: #5eead4; }
.status-active, .status-checked_in { background: rgba(234, 88, 12, 0.2); color: #fdba74; }
.status-completed { background: rgba(34, 197, 94, 0.2); color: #86efac; }
.status-cancelled, .status-no_show { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

.booking-unit-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.4rem;
}

.form-label-sm {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.form-input-sm, .form-select-sm {
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 0.85rem;
}

/* Responsive Booking Form Grids */
.booking-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.booking-financials-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

@media (max-width: 768px) {
    .booking-financials-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 520px) {
    .booking-form-grid,
    .booking-financials-grid {
        grid-template-columns: 1fr;
    }

    .booking-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }
}


/* ── Toast Notifications ── */
#toast-container {
    position: fixed;
    top: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    width: 90%;
    max-width: 420px;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 1.15rem;
    border-radius: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 0.88rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    animation: toastSlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    width: 100%;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.toast.toast-exit {
    animation: toastSlideOut 0.3s ease-in forwards;
}

.toast-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.toast-success .toast-icon {
    background: #0d9488;
    color: #fff;
}

.toast-error .toast-icon {
    background: #e53e3e;
    color: #fff;
}

.toast-warning .toast-icon {
    background: #d69e2e;
    color: #fff;
}

.toast-info .toast-icon {
    background: #3182ce;
    color: #fff;
}

.toast-message {
    flex: 1;
    line-height: 1.35;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    font-size: 1.1rem;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.toast-close:hover {
    opacity: 1;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateY(-18px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastSlideOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to   { opacity: 0; transform: translateY(-18px) scale(0.95); }
}
