/* WhatsPogo Web App - WhatsApp-Style CSS */
:root {
    --wa-green: #00b094;
    --wa-green-dark: #006958;
    --wa-green-light: #d9f5c7;
    --wa-teal: #128c7e;
    --wa-teal-dark: #075e54;
    --wa-bg: #efeae2;
    --wa-chat-bg: #e5ddd5;
    --wa-header: #00b094;
    --wa-white: #ffffff;
    --wa-gray: #667781;
    --wa-light-gray: #f0f2f5;
    --wa-border: #e9edef;
    --wa-badge: #25d366;
    --wa-red: #ea0038;
    --wa-blue: #53bdeb;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--wa-bg);
    color: #111b21;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.screen { display: none; height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

.hidden { display: none !important; }

/* ========== LOGIN ========== */
#login-screen {
    background: linear-gradient(135deg, var(--wa-teal-dark), var(--wa-green));
    justify-content: center;
    align-items: center;
}

.login-container {
    background: var(--wa-white);
    border-radius: 16px;
    padding: 40px 32px;
    width: 90%;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,.15);
    text-align: center;
}

.login-logo {
    font-size: 64px;
    margin-bottom: 8px;
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--wa-teal-dark);
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--wa-gray);
    font-size: 14px;
    margin-bottom: 28px;
}

.input-group {
    text-align: left;
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--wa-gray);
    margin-bottom: 6px;
}

.input-group input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--wa-border);
    border-radius: var(--radius);
    font-size: 16px;
    outline: none;
    transition: border-color .2s;
}

.input-group input:focus {
    border-color: var(--wa-green);
}

.error-msg {
    background: #ffeaea;
    color: var(--wa-red);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 12px;
}

.btn-login {
    width: 100%;
    padding: 14px;
    background: var(--wa-green);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}

.btn-login:hover { background: var(--wa-teal); }
.btn-login:disabled { opacity: .6; cursor: not-allowed; }

/* ========== APP HEADER ========== */
.app-header {
    background: url('../img/header-bg.jpg') center 65% / cover no-repeat;
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    min-height: 120px;
    padding-bottom: 10px;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-left h1 {
    font-size: 20px;
    font-weight: 700;
    text-shadow: 0 1px 4px rgba(0,0,0,.5);
}

.header-right {
    display: flex;
    gap: 4px;
}

.header-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    padding: 8px;
    cursor: pointer;
    border-radius: 50%;
    transition: background .2s;
    line-height: 1;
    text-shadow: 0 1px 4px rgba(0,0,0,.5);
}

.header-btn:hover { background: rgba(255,255,255,.15); }
.header-btn.lang-flag { font-size: 24px; }

/* ========== USER DROPDOWN ========== */
.dropdown {
    position: absolute;
    top: 120px;
    right: 8px;
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    min-width: 200px;
    z-index: 200;
    overflow: hidden;
}

.dropdown-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--wa-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.badge {
    background: var(--wa-green);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    text-align: left;
    border: none;
    background: none;
    font-size: 14px;
    cursor: pointer;
    transition: background .2s;
}

.dropdown-item:hover { background: var(--wa-light-gray); }

/* ========== TAB NAVIGATION ========== */
.tab-nav {
    display: flex;
    background: var(--wa-teal);
    border-bottom: 3px solid transparent;
}

.tab {
    flex: 1;
    padding: 12px 8px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: rgba(255,255,255,.7);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}

.tab.active {
    color: white;
    border-bottom-color: white;
}

.tab:hover { color: white; }

/* ========== SEARCH ========== */
.search-bar {
    padding: 8px 12px;
    background: var(--wa-light-gray);
}

.search-bar input {
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    background: white;
    outline: none;
}

/* ========== CONTENT ========== */
.content {
    flex: 1;
    overflow-y: auto;
    background: var(--wa-white);
    -webkit-overflow-scrolling: touch;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== CHAT LIST ========== */
.list { list-style: none; }

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--wa-border);
    cursor: pointer;
    transition: background .15s;
    gap: 12px;
}

.chat-item:hover { background: var(--wa-light-gray); }
.chat-item:active { background: #e4e6e8; }
.chat-item.selected { background: #d4edda; border-left: 3px solid var(--wa-green); }

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    flex-shrink: 0;
}

.chat-avatar.group { background: var(--wa-teal); }
.chat-avatar.private { background: #6b9b8e; }

.chat-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 2px;
}

.chat-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 12px;
    color: var(--wa-gray);
    flex-shrink: 0;
    margin-left: 8px;
}

.chat-preview-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-preview {
    font-size: 13px;
    color: var(--wa-gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-last-time {
    font-size: 12px;
    color: var(--wa-gray);
}

.chat-ago-tag {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: var(--wa-teal-dark);
    background: #e0f2ef;
    padding: 1px 8px;
    border-radius: 10px;
    margin-left: 8px;
}

.chat-badge {
    background: var(--wa-badge);
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-radius: 10px;
    padding: 0 6px;
    margin-left: 8px;
    flex-shrink: 0;
}

/* ========== MESSAGE LIST ========== */
.message-item {
    padding: 10px 16px;
    border-bottom: 1px solid var(--wa-border);
    cursor: pointer;
    transition: background .15s;
}

.message-item:hover { background: var(--wa-light-gray); }
.message-item:active { background: #e4e6e8; }
.message-item.selected { background: #d4edda; border-left: 3px solid var(--wa-green); }

.msg-sender {
    font-size: 13px;
    font-weight: 700;
    color: var(--wa-green-dark);
    margin-bottom: 2px;
}

.msg-chat {
    font-size: 12px;
    color: var(--wa-gray);
    margin-bottom: 2px;
}

.msg-group-tag {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: var(--wa-teal-dark);
    background: #e8f0fe;
    padding: 1px 8px;
    border-radius: 10px;
    margin-left: 8px;
}

.sender-link {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: transparent;
    transition: text-decoration-color .2s;
}

.sender-link:hover {
    text-decoration-color: var(--wa-green-dark);
}

.sender-msg-item {
    padding: 10px 20px;
    border-bottom: 1px solid var(--wa-border);
}

.sender-msg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.sender-msg-time {
    font-size: 12px;
    color: var(--wa-gray);
}

.sender-msg-text {
    font-size: 14px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.msg-text {
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--wa-gray);
    flex-wrap: wrap;
}

.msg-meta .sentiment { font-size: 13px; }
.msg-meta .star { color: #f4b400; }
.msg-meta .attach { color: var(--wa-gray); }
.msg-meta .flag { font-size: 13px; }
.msg-meta .read { color: var(--wa-blue); font-weight: 600; }
.msg-meta .time { margin-left: auto; }

/* ========== CHAT DETAIL MESSAGES ========== */
.message-list {
    padding: 8px 12px;
    background: var(--wa-chat-bg);
    min-height: 100%;
}

.msg-bubble {
    max-width: 85%;
    padding: 8px 12px;
    margin-bottom: 4px;
    border-radius: 8px;
    position: relative;
    cursor: pointer;
    word-wrap: break-word;
}

.msg-bubble.incoming {
    background: white;
    border-top-left-radius: 0;
    margin-right: auto;
}

.msg-bubble.outgoing {
    background: var(--wa-green-light);
    border-top-right-radius: 0;
    margin-left: auto;
}

.msg-bubble.selected { outline: 2px solid var(--wa-green); outline-offset: 2px; }

.msg-bubble .bubble-sender {
    font-size: 12px;
    font-weight: 700;
    color: var(--wa-green-dark);
    margin-bottom: 2px;
}

.msg-bubble .bubble-text {
    font-size: 14px;
    line-height: 1.4;
}

.msg-bubble .bubble-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    font-size: 11px;
    color: var(--wa-gray);
}

.msg-bubble .bubble-footer .read { color: var(--wa-blue); }

/* ========== MODAL ========== */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,.4);
}

.modal-content {
    position: relative;
    background: white;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp .25s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--wa-border);
    background: var(--wa-light-gray);
}

.modal-header h2 { font-size: 18px; }

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--wa-gray);
    padding: 4px 8px;
    border-radius: 50%;
}

.modal-close:hover { background: var(--wa-border); }

.modal-body {
    overflow-y: auto;
    padding: 0;
    -webkit-overflow-scrolling: touch;
}

.detail-section {
    padding: 14px 20px;
    border-bottom: 8px solid var(--wa-light-gray);
}

.detail-section h3 {
    font-size: 14px;
    color: var(--wa-green-dark);
    margin-bottom: 10px;
    font-weight: 700;
}

.detail-section .text-content {
    font-size: 15px;
    line-height: 1.5;
    user-select: text;
    -webkit-user-select: text;
}

.detail-section .text-content.muted {
    color: var(--wa-gray);
    font-style: italic;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--wa-border);
}

.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--wa-gray); }
.detail-row .value { font-weight: 500; text-align: right; max-width: 60%; word-break: break-all; }

/* ========== LOADING & EMPTY ========== */
.loading {
    padding: 20px;
    text-align: center;
    color: var(--wa-gray);
}

.load-more {
    padding: 16px;
    text-align: center;
}

.btn-action {
    padding: 10px 24px;
    background: var(--wa-green);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}

.btn-action:hover { background: var(--wa-teal); }

.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--wa-gray);
}

.empty-icon { font-size: 64px; margin-bottom: 12px; }
.empty-state p { margin-bottom: 16px; font-size: 15px; }

.loading-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
    font-size: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin-bottom: 12px;
}

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

/* ========== DASHBOARD ========== */
.dashboard {
    background: var(--wa-light-gray);
    padding: 12px 16px 8px;
    border-bottom: 1px solid var(--wa-border);
}

.dash-header {
    font-size: 14px;
    font-weight: 700;
    color: var(--wa-green-dark);
    margin-bottom: 10px;
}

.dash-cards {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.dash-card {
    flex: 1;
    background: white;
    border-radius: var(--radius);
    padding: 10px 12px;
    text-align: center;
    box-shadow: var(--shadow);
}

.dash-card-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--wa-teal-dark);
    line-height: 1.2;
}

.dash-card-label {
    font-size: 11px;
    color: var(--wa-gray);
    margin-top: 2px;
}

.dash-section {
    background: white;
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
}

.dash-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--wa-green-dark);
    margin-bottom: 8px;
}

.dash-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 80px;
    padding-top: 4px;
}

.dash-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}

.dash-bar-count {
    font-size: 10px;
    color: var(--wa-gray);
    margin-bottom: 2px;
    min-height: 14px;
}

.dash-bar {
    width: 100%;
    max-width: 28px;
    background: var(--wa-green);
    border-radius: 3px 3px 0 0;
    min-height: 3px;
    transition: height .3s ease;
}

.dash-bar-label {
    font-size: 10px;
    color: var(--wa-gray);
    margin-top: 3px;
    font-weight: 600;
}

.dash-row {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}

.dash-half {
    flex: 1;
    min-width: 0;
}

.dash-list-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    font-size: 12px;
    border-bottom: 1px solid var(--wa-border);
}

.dash-list-item:last-child { border-bottom: none; }

.dash-rank {
    color: var(--wa-gray);
    font-weight: 600;
    width: 16px;
    flex-shrink: 0;
}

.dash-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dash-count {
    color: var(--wa-teal-dark);
    font-weight: 700;
    flex-shrink: 0;
}

.dash-mood-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.dash-mood-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 2px 0;
}

.dash-mood-emoji { font-size: 16px; }

.dash-mood-pct {
    color: var(--wa-gray);
    font-weight: 600;
}

/* Dashboard: Today */
.dash-today-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.dash-today-stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.dash-today-stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--wa-teal-dark);
}

.dash-today-stat-label {
    font-size: 11px;
    color: var(--wa-gray);
}

.dash-today-label {
    font-size: 11px;
    color: var(--wa-gray);
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.dash-today-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.dash-today-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 12px;
    padding: 3px 0;
    border-bottom: 1px solid var(--wa-light-gray);
}

.dash-today-item:last-child { border-bottom: none; }

.dash-today-time {
    color: var(--wa-gray);
    font-size: 11px;
    min-width: 36px;
    font-variant-numeric: tabular-nums;
}

.dash-today-sender {
    font-weight: 600;
    color: var(--wa-teal-dark);
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-today-text {
    color: #555;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.dash-today-empty {
    font-size: 12px;
    color: var(--wa-gray);
    padding: 8px 0;
}

/* ========== SETTINGS ========== */
.settings-list { padding: 0; }

.settings-section {
    padding: 16px 20px 8px;
    border-bottom: 8px solid var(--wa-light-gray);
}

.settings-section h3 {
    font-size: 14px;
    color: var(--wa-green-dark);
    margin-bottom: 12px;
    font-weight: 700;
}

.settings-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--wa-border);
}

.settings-item:last-child { border-bottom: none; }
.settings-item span:last-child { color: var(--wa-gray); text-align: right; max-width: 60%; word-break: break-word; }

/* ========== FOOTER ========== */
.app-footer {
    background: var(--wa-light-gray);
    color: var(--wa-gray);
    text-align: center;
    padding: 6px 12px;
    font-size: 11px;
    border-top: 1px solid var(--wa-border);
    flex-shrink: 0;
}

/* ========== RESPONSIVE: DESKTOP (sidebar + content) ========== */
@media (min-width: 768px) {
    body { background: var(--wa-teal-dark); }

    #app-screen {
        max-width: 1200px;
        margin: 0 auto;
        border-left: 1px solid var(--wa-border);
        border-right: 1px solid var(--wa-border);
        box-shadow: 0 0 40px rgba(0,0,0,.15);
        background: white;
        border-radius: var(--radius) var(--radius) 0 0;
        overflow: hidden;
    }

    .app-header {
        padding: 12px 24px;
    }

    .app-header h1 { font-size: 22px; }

    .tab-nav {
        padding: 0 8px;
    }

    .tab {
        font-size: 14px;
        padding: 14px 16px;
    }

    .search-bar {
        padding: 10px 20px;
    }

    .search-bar input {
        max-width: 500px;
        padding: 12px 18px;
        font-size: 15px;
    }

    .content {
        padding: 0;
    }

    .chat-item {
        padding: 14px 24px;
    }

    .chat-avatar {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }

    .chat-name { font-size: 16px; }
    .chat-preview { font-size: 14px; }

    .message-item {
        padding: 12px 24px;
    }

    .msg-text {
        font-size: 15px;
        -webkit-line-clamp: 3;
    }

    .msg-bubble {
        max-width: 65%;
        padding: 10px 14px;
        margin-bottom: 6px;
    }

    .msg-bubble .bubble-text { font-size: 15px; }

    .message-list {
        padding: 12px 20px;
    }

    .modal {
        align-items: center;
    }

    .modal-content {
        border-radius: 16px;
        max-width: 560px;
        max-height: 80vh;
    }

    .settings-section {
        padding: 20px 28px 12px;
    }

    .settings-item { font-size: 15px; }

    .login-container {
        padding: 48px 40px;
        max-width: 420px;
    }

    .dropdown {
        right: 16px;
    }
}

/* ========== RESPONSIVE: LARGE DESKTOP ========== */
@media (min-width: 1024px) {
    .chat-item:hover {
        background: var(--wa-light-gray);
        border-left: 3px solid var(--wa-green);
    }

    .msg-bubble { max-width: 55%; }

    .modal-content { max-width: 640px; }
}

/* ========== RESPONSIVE: SMALL MOBILE ========== */
@media (max-width: 360px) {
    .tab { font-size: 11px; padding: 10px 4px; }
    .chat-avatar { width: 40px; height: 40px; font-size: 16px; }
    .chat-name { font-size: 14px; }
    .app-header h1 { font-size: 18px; }
}

/* ========== SAFE AREA (iPhone notch) ========== */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
    .content {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
