/* ---------- App shell: phone (single pane, swaps screens) below 860px,
   WhatsApp-Web-style two-pane sidebar+chat layout at/above it ---------- */

#app-shell {
    position: relative;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg-app);
}

#app-body {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}
.screen.active { opacity: 1; pointer-events: auto; }

.chat-placeholder { display: none; }
.chat-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* Width alone isn't a safe signal: a phone in landscape (or with "Desktop site" mode
   toggled) can easily exceed 860px. Require an actual mouse (hover+fine pointer) too,
   so real phones/tablets always stay on the single-pane layout regardless of width. */
@media (min-width: 860px) and (hover: hover) and (pointer: fine) {
    #app-shell { max-width: 1600px; margin: 0 auto; }
    #app-body { flex-direction: row; }

    .screen {
        position: static;
        opacity: 1 !important;
        pointer-events: auto !important;
        height: 100%;
    }
    #screen-list {
        width: 380px;
        flex-shrink: 0;
        border-right: 1px solid var(--border-subtle);
    }
    #screen-chat { flex: 1; min-width: 0; }

    #btn-back { display: none; }

    #screen-chat.no-chat #chat-placeholder { display: flex; }
    #screen-chat.no-chat #chat-content { display: none; }
}

.chat-placeholder {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 6px;
    color: var(--text-secondary);
    background: var(--bg-wallpaper);
    padding: 24px;
}
.chat-placeholder-logo { width: 64px; height: 64px; opacity: 0.5; margin-bottom: 8px; }
.chat-placeholder p { margin: 0; font-size: 15px; }
.chat-placeholder .hint { font-size: 13px; }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-on-accent);
    font-size: 20px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); }
.icon-btn:active { background: rgba(255,255,255,0.2); }

/* ---------- List screen ---------- */

.list-header {
    background: var(--bg-header);
    color: var(--text-on-accent);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.list-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 19px;
    font-weight: 500;
}
.brand-logo { width: 26px; height: 26px; }

.chat-list {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-panel);
}

.chat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
    transition: background-color 0.1s;
}
.chat-card:hover { background: var(--bg-card-hover); }
.chat-card:hover .chat-card-delete { opacity: 1; }
.chat-card.selected { background: var(--bg-card-hover); }

.chat-card-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 16px;
}

.chat-card-body { flex: 1; min-width: 0; }
.chat-card-top, .chat-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.chat-card-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-card-time, .chat-expiry {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.chat-card-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-card-delete {
    background: none;
    border: none;
    font-size: 16px;
    opacity: 0;
    cursor: pointer;
    padding: 6px;
    transition: opacity 0.15s;
}
@media (hover: none) {
    .chat-card-delete { opacity: 0.6; }
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
    padding: 24px;
    background: var(--bg-panel);
}
.empty-state .hint { font-size: 13px; }

.fab-upload {
    position: absolute;
    right: 20px;
    bottom: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 28px;
    box-shadow: var(--shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}
.fab-upload:hover { transform: scale(1.06); }

/* ---------- Chat screen header ---------- */

.chat-header {
    background: var(--bg-header);
    color: var(--text-on-accent);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    z-index: 5;
}
.chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-title {
    font-weight: 500;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-header-subtitle {
    font-size: 12px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#view-as-select {
    max-width: 100%;
    margin-top: 2px;
    font-size: 11px;
    background: transparent;
    color: var(--text-on-accent);
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 6px;
    padding: 1px 4px;
}
#view-as-select option { color: #000; }

.filter-banner {
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.filter-banner button {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    border-radius: 6px;
    padding: 3px 10px;
    cursor: pointer;
    font-size: 12px;
}

/* ---------- Messages viewport ---------- */

.messages-viewport {
    flex: 1;
    overflow-y: auto;
    position: relative;
    background-color: var(--bg-wallpaper);
    background-image: var(--wallpaper-image);
    background-repeat: repeat;
    background-size: 400px;
}

.messages-list {
    padding: 10px 10px 16px;
    display: flex;
    flex-direction: column;
}

.sentinel { height: 1px; }

.sticky-date {
    position: sticky;
    top: 8px;
    z-index: 3;
    align-self: center;
    margin: 0 auto 8px;
    width: fit-content;
    background: var(--pill-bg);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.empty-messages {
    margin: auto;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
    padding: 40px 20px;
}

.fab-scroll-bottom {
    position: absolute;
    right: 16px;
    bottom: 84px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    border: none;
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: 16px;
    z-index: 4;
}

.chat-input-bar {
    flex-shrink: 0;
    padding: 8px 10px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-subtle);
}
.chat-input-fake {
    background: var(--input-bg);
    color: var(--text-secondary);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 13px;
    text-align: center;
}

/* ---------- Overlays: sheet, modal, toast ---------- */

.sheet-overlay, .modal-overlay {
    position: absolute;
    inset: 0;
    background: var(--overlay-bg);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 20;
}
.modal-overlay { align-items: center; }

.sheet {
    width: 100%;
    background: var(--bg-panel);
    border-radius: 16px 16px 0 0;
    padding: 10px 18px 20px;
    box-shadow: var(--shadow);
}
.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border-subtle);
    border-radius: 2px;
    margin: 4px auto 14px;
}
.sheet h3 { margin: 0 0 12px; font-size: 16px; }

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}
.chip {
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-primary);
    border-radius: 16px;
    padding: 7px 14px;
    font-size: 13px;
    cursor: pointer;
}
.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.custom-range { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.custom-range label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.custom-range input {
    background: var(--input-bg);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 8px;
    font-size: 13px;
}

.month-buckets-section { margin-top: 4px; }
.month-buckets-section h4 {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.month-buckets {
    max-height: 220px;
    overflow-y: auto;
    border-top: 1px solid var(--border-subtle);
}
.month-bucket-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 10px 4px;
    font-size: 13.5px;
    cursor: pointer;
    text-align: left;
}
.month-bucket-row:hover { background: var(--bg-card-hover); }
.month-bucket-row.active { color: var(--accent); font-weight: 500; }
.month-bucket-count { color: var(--text-secondary); font-size: 12px; }

.sheet-actions, .modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 4px;
}

.btn-primary, .btn-secondary, .btn-danger {
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 13px;
    cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--input-bg); color: var(--text-primary); }
.btn-danger { background: var(--danger); color: #fff; }

.modal {
    width: min(340px, calc(100% - 40px));
    background: var(--bg-panel);
    border-radius: 14px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.modal p { font-size: 14px; margin: 0 0 16px; }

.upload-modal { text-align: center; }
.dropzone {
    border: 2px dashed var(--border-subtle);
    border-radius: 12px;
    padding: 28px 16px;
    cursor: pointer;
    margin-bottom: 16px;
    transition: border-color 0.15s, background-color 0.15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--bg-card-hover); }
.dropzone p { margin: 4px 0; font-size: 14px; }
.dropzone .hint { font-size: 12px; color: var(--text-secondary); }

.upload-progress { margin-bottom: 16px; }
.progress-bar {
    height: 8px;
    background: var(--input-bg);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.2s;
}
#progress-text { font-size: 13px; color: var(--text-secondary); margin: 0; }

.toast-container {
    position: absolute;
    left: 0; right: 0;
    bottom: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 30;
    pointer-events: none;
}
.toast {
    background: #323232;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
    max-width: 85%;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
