/* WhatsApp Archived Chats - Simple viewer */

:root {
    --wa-green: #00a884;
    --wa-green-dark: #008069;
    --wa-outgoing: #d9fdd3;
    --wa-incoming: #ffffff;
    --wa-bg: #efeae2;
    --wa-header: #008069;
    --wa-text: #111b21;
    --wa-muted: #667781;
    --wa-system-bg: #ffffff;
    --radius: 8px;
    --shadow: 0 1px 0.5px rgba(11,20,26,.13);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f0f2f5;
    color: var(--wa-text);
    line-height: 1.4;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ========== Layout ========== */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    min-height: 100vh;
    background: #fff;
    box-shadow: 0 0 20px rgba(0,0,0,.08);
}

.app-header {
    background: var(--wa-header);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header h1 {
    font-size: 1.15rem;
    font-weight: 500;
}

.back-btn {
    color: #fff;
    font-size: 1.3rem;
    padding: 4px 8px;
    margin-right: 4px;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: 24px;
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s;
}

.btn-primary {
    background: var(--wa-green);
    color: #fff;
}
.btn-primary:hover { background: var(--wa-green-dark); }

.btn-sm {
    padding: 7px 14px;
    font-size: 0.85rem;
}

/* ========== Chat list ========== */
.chat-list {
    padding: 8px 0;
}

.chat-item-wrap {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f0f2f5;
    position: relative;
}
.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 14px;
    flex: 1;
    transition: background .1s;
}
.chat-item:hover { background: #f5f6f6; }
.delete-btn {
    padding: 12px 14px;
    color: #999;
    font-size: 1.1rem;
    opacity: 0.5;
    transition: opacity .15s, color .15s;
}
.delete-btn:hover { opacity: 1; color: #c62828; }

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--wa-green);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 500;
    flex-shrink: 0;
    text-transform: uppercase;
}

.chat-info { flex: 1; min-width: 0; }
.chat-title {
    font-weight: 500;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-meta, .chat-date {
    font-size: 0.82rem;
    color: var(--wa-muted);
    margin-top: 2px;
}
.chevron {
    color: #ccc;
    font-size: 1.4rem;
}

/* ========== Empty ========== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--wa-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h2 { color: var(--wa-text); margin-bottom: 8px; }
.empty-state.small { padding: 40px 20px; }

/* ========== Import ========== */
.import-page { padding: 24px 16px; }
.card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
    max-width: 520px;
    margin: 0 auto;
}
.card h2 { margin-bottom: 8px; font-size: 1.25rem; }
.hint { color: var(--wa-muted); font-size: 0.9rem; margin-bottom: 12px; }
.hint-list {
    margin: 0 0 20px 18px;
    color: var(--wa-muted);
    font-size: 0.88rem;
}
.hint-list li { margin-bottom: 4px; }

.file-drop {
    border: 2px dashed #c5c9cc;
    border-radius: 12px;
    padding: 28px 16px;
    text-align: center;
    margin-bottom: 18px;
    position: relative;
    transition: border-color .15s, background .15s;
}
.file-drop.dragover {
    border-color: var(--wa-green);
    background: #f0faf7;
}
.file-drop input[type=file] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.file-drop .icon { font-size: 2rem; display: block; margin-bottom: 8px; }
.file-drop .text { display: block; font-weight: 500; }
.file-drop .sub { display: block; font-size: 0.85rem; color: var(--wa-muted); margin-top: 4px; }

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.92rem;
}
.alert-error { background: #fdecea; color: #c62828; }
.alert-success { background: #e8f5e9; color: #2e7d32; }

/* ========== Chat view (WhatsApp style) ========== */
.chat-view-body {
    background: #0b141a;
    margin: 0;
    height: 100vh;
    overflow: hidden;
}

.chat-view {
    max-width: 900px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--wa-bg);
    /* WhatsApp background pattern (subtle) */
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cfc5' fill-opacity='0.35'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-header {
    background: var(--wa-header);
    color: #fff;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.chat-header .back-btn {
    font-size: 1.4rem;
    line-height: 1;
    padding: 6px;
}

.header-info { flex: 1; min-width: 0; }
.header-title {
    font-size: 1.05rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.header-sub {
    font-size: 0.75rem;
    opacity: 0.85;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px 20px;
    scroll-behavior: smooth;
}

.date-separator {
    text-align: center;
    margin: 14px 0 10px;
}
.date-separator span {
    display: inline-block;
    background: #e1f2fa;
    color: #54656f;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.system-msg {
    text-align: center;
    margin: 8px 0;
}
.system-msg span {
    display: inline-block;
    background: #e1f2fa;
    color: #54656f;
    font-size: 0.78rem;
    padding: 5px 12px;
    border-radius: 8px;
    max-width: 85%;
    box-shadow: var(--shadow);
}

.system-banner {
    text-align: center;
    background: #d9fdd3;
    color: #008069;
    font-size: 0.85rem;
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 6px;
}

.message-row {
    display: flex;
    margin-bottom: 3px;
    padding: 0 4px;
}
.message-row.outgoing { justify-content: flex-end; }
.message-row.incoming { justify-content: flex-start; }

.bubble {
    max-width: 75%;
    padding: 6px 9px 4px;
    border-radius: 8px;
    position: relative;
    box-shadow: var(--shadow);
    word-wrap: break-word;
}

.incoming .bubble {
    background: var(--wa-incoming);
    border-top-left-radius: 0;
}
.outgoing .bubble {
    background: var(--wa-outgoing);
    border-top-right-radius: 0;
}

.sender-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #e35d6a; /* vary or fixed */
    margin-bottom: 2px;
}

.msg-text {
    font-size: 0.95rem;
    white-space: pre-wrap;
    line-height: 1.35;
}

.msg-time {
    font-size: 0.68rem;
    color: var(--wa-muted);
    text-align: right;
    margin-top: 2px;
    float: right;
    margin-left: 10px;
    line-height: 1.5;
}

/* Media */
.media-attachment { margin-bottom: 4px; }
.media-img {
    max-width: 100%;
    max-height: 280px;
    border-radius: 6px;
    display: block;
    cursor: pointer;
}
.media-video {
    max-width: 100%;
    max-height: 280px;
    border-radius: 6px;
    background: #000;
}
.media-audio {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 200px;
}
.media-audio audio { width: 100%; height: 36px; }
.audio-label { font-size: 0.8rem; color: var(--wa-muted); }

.media-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,.05);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #027eb5;
}
.media-omitted, .media-missing {
    font-size: 0.88rem;
    color: var(--wa-muted);
    padding: 4px 0;
}
.media-missing small { display: block; font-size: 0.75rem; }

/* View only bar */
.view-only-bar {
    flex-shrink: 0;
    background: #f0f2f5;
    border-top: 1px solid #e0e0e0;
    padding: 10px 16px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--wa-muted);
}

/* Responsive */
@media (max-width: 600px) {
    .bubble { max-width: 85%; }
    .app-container { box-shadow: none; }
}

/* ========== Loading Overlay ========== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 20, 26, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.loading-box {
    background: #fff;
    border-radius: 16px;
    padding: 36px 40px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    max-width: 320px;
    width: 90%;
}

.loading-box h3 {
    margin: 18px 0 6px;
    font-size: 1.2rem;
    color: #111b21;
}

.loading-box #loadingText {
    color: #667781;
    font-size: 0.92rem;
    margin-bottom: 12px;
}

.countdown {
    font-size: 1.8rem;
    font-weight: 600;
    color: #00a884;
    margin: 8px 0 12px;
    font-variant-numeric: tabular-nums;
}

.loading-hint {
    font-size: 0.8rem;
    color: #999;
}

/* Spinner */
.spinner {
    width: 52px;
    height: 52px;
    margin: 0 auto;
    border: 4px solid #e0e0e0;
    border-top-color: #00a884;
    border-radius: 50%;
    animation: spin 0.85s linear infinite;
}

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

/* Better document attachment card */
.media-file {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,.06);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #027eb5;
    text-decoration: none;
    max-width: 100%;
    word-break: break-word;
}
.media-file:hover {
    background: rgba(0,0,0,.1);
}
.outgoing .media-file {
    background: rgba(0,0,0,.08);
    color: #056162;
}

/* Media button in chat header */
.header-media-btn {
    color: #fff;
    font-size: 1.35rem;
    padding: 6px 10px;
    text-decoration: none;
    opacity: 0.9;
    line-height: 1;
}
.header-media-btn:hover { opacity: 1; }
