/* ========================================
   WhatsApp Chat Viewer — Main Stylesheet
   WhatsApp-accurate colors, no gradients
   ======================================== */

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

:root {
    /* Dark theme (default) */
    --bg-primary: #0B141A;
    --bg-secondary: #111B21;
    --bg-header: #1F2C34;
    --bg-bubble-in: #202C33;
    --bg-bubble-out: #005C4B;
    --bg-date-chip: #1D282F;
    --bg-system: #1D282F;
    --bg-input: #2A3942;
    --bg-upload: #111B21;
    --bg-search: #111B21;
    --bg-modal: #1F2C34;
    --bg-tab-active: #2A3942;
    --bg-privacy: #1D282F;
    --bg-guide-tip: #2A3942;
    --bg-guide-note: #1D282F;
    --bg-dropzone: #111B21;
    --bg-dropzone-hover: #1D282F;
    --bg-user-chip: #2A3942;

    --text-primary: #E9EDE0;
    --text-secondary: #8696A0;
    --text-date: #8696A0;
    --text-system: #8696A0;
    --text-header: #E9EDE0;
    --text-upload-title: #E9EDE0;
    --text-upload-desc: #8696A0;
    --text-link: #53BDEB;
    --text-warn: #E9EDE0;

    --border-color: #2A3942;
    --divider: #2A3942;

    --accent: #00A884;
    --accent-hover: #06CF9C;
    --accent-text: #111B21;

    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-modal: 0 8px 32px rgba(0,0,0,0.6);

    --header-height: 56px;
    --border-radius-bubble: 8px;
    --border-radius-ui: 12px;
}

body.light {
    --bg-primary: #EAE8DD;
    --bg-secondary: #F0F2F5;
    --bg-header: #008069;
    --bg-bubble-in: #FFFFFF;
    --bg-bubble-out: #D9FDD3;
    --bg-date-chip: rgba(255,255,255,0.85);
    --bg-system: rgba(255,255,255,0.85);
    --bg-input: #FFFFFF;
    --bg-upload: #F0F2F5;
    --bg-search: #FFFFFF;
    --bg-modal: #FFFFFF;
    --bg-tab-active: #F0F2F5;
    --bg-privacy: #D9FDD3;
    --bg-guide-tip: #E7F7E1;
    --bg-guide-note: #F9F9F9;
    --bg-dropzone: #FFFFFF;
    --bg-dropzone-hover: #F0F2F5;
    --bg-user-chip: #F0F2F5;

    --text-primary: #111B21;
    --text-secondary: #667781;
    --text-date: #667781;
    --text-system: #667781;
    --text-header: #FFFFFF;
    --text-upload-title: #111B21;
    --text-upload-desc: #667781;
    --text-link: #027EB5;
    --text-warn: #111B21;

    --border-color: #D1D7DB;
    --divider: #D1D7DB;

    --accent: #008069;
    --accent-hover: #017561;
    --accent-text: #FFFFFF;

    --shadow: 0 1px 3px rgba(0,0,0,0.15);
    --shadow-modal: 0 8px 32px rgba(0,0,0,0.2);
}

body {
    font-family: 'Roboto', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* =========================================================
   HEADER
   ========================================================= */
#app-header {
    background-color: var(--bg-header);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

#header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--header-height);
    max-width: 1400px;
    margin: 0 auto;
}

#header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

#logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

#app-title {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-header);
    white-space: nowrap;
}

#header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-header);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
    flex-shrink: 0;
}

.icon-btn:hover {
    background-color: rgba(255,255,255,0.1);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

/* =========================================================
   PRIVACY BANNER
   ========================================================= */
#privacy-banner {
    background-color: var(--bg-privacy);
    border-bottom: 1px solid var(--divider);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

#privacy-banner svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: var(--accent);
}

#privacy-banner strong {
    color: var(--text-primary);
}

/* =========================================================
   SEARCH BAR
   ========================================================= */
#search-bar {
    background-color: var(--bg-search);
    border-bottom: 1px solid var(--divider);
    padding: 8px 16px;
    position: sticky;
    top: var(--header-height);
    z-index: 90;
}

#search-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 900px;
    margin: 0 auto;
}

#search-inner svg {
    width: 20px;
    height: 20px;
    fill: var(--text-secondary);
    flex-shrink: 0;
}

#search-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-primary);
}

#search-input::placeholder {
    color: var(--text-secondary);
}

#search-date {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 5px 8px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}

#search-date::-webkit-calendar-picker-indicator {
    filter: invert(0.5);
    cursor: pointer;
}

#search-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 50%;
    transition: background-color 0.15s;
}

#search-close:hover {
    background-color: var(--bg-tab-active);
}

#search-close svg {
    width: 18px;
    height: 18px;
    fill: var(--text-secondary);
}

#search-results-info {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 4px;
    min-height: 16px;
}

/* =========================================================
   UPLOAD SECTION
   ========================================================= */
#upload-section {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--header-height) - 41px);
    padding: 40px 20px;
    background-color: var(--bg-primary);
}

#upload-hero {
    text-align: center;
    max-width: 520px;
    width: 100%;
}

#hero-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    margin-bottom: 16px;
}

#upload-title {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-upload-title);
    margin-bottom: 10px;
}

#upload-desc {
    font-size: 15px;
    color: var(--text-upload-desc);
    line-height: 1.5;
    margin-bottom: 28px;
}

#drop-zone {
    background-color: var(--bg-dropzone);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius-ui);
    padding: 36px 24px;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
    margin-bottom: 16px;
}

#drop-zone:hover,
#drop-zone.drag-over {
    background-color: var(--bg-dropzone-hover);
    border-color: var(--accent);
}

#drop-zone svg {
    width: 48px;
    height: 48px;
    fill: var(--accent);
    margin-bottom: 12px;
}

#drop-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

#drop-subtext {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

#file-input {
    display: none;
}

#file-label {
    display: inline-block;
    background-color: var(--accent);
    color: var(--accent-text);
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s;
    font-family: inherit;
}

#file-label:hover {
    background-color: var(--accent-hover);
}

#how-to-export {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    transition: background-color 0.15s, color 0.15s;
    margin-top: 4px;
}

#how-to-export svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

#how-to-export:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

/* =========================================================
   CHAT INFO BAR
   ========================================================= */
#chat-info {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--divider);
    padding: 12px 20px;
}

#chat-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    max-width: 900px;
    margin: 0 auto 10px;
}

#chat-stats {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

#chat-filename {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

#chat-msgcount {
    font-size: 13px;
    color: var(--text-secondary);
    background-color: var(--bg-date-chip);
    padding: 2px 10px;
    border-radius: 12px;
}

#pov-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

#pov-control label {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

#pov-select {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
}

#users-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 900px;
    margin: 0 auto;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 7px;
    background-color: var(--bg-user-chip);
    border-radius: 20px;
    padding: 5px 12px 5px 5px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #ffffff;
    flex-shrink: 0;
}

/* =========================================================
   CHAT AREA
   ========================================================= */
#chat-area {
    background-image: url("../images/background.png");
    background-repeat: repeat;
    background-size: 350px;
    padding: 12px 20px;
    min-height: 200px;
}

body.light #chat-area {
    background-image: url("../images/backgroundlight.png");
}

#messages-container {
    max-width: 900px;
    margin: 0 auto;
}

/* Date chip */
.date-chip-row {
    display: flex;
    justify-content: center;
    margin: 16px 0 8px;
    position: sticky;
    top: calc(var(--header-height) + 8px);
    z-index: 10;
}

.date-chip {
    background-color: var(--bg-date-chip);
    color: var(--text-date);
    font-size: 12.5px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    user-select: none;
}

/* System message */
.system-row {
    display: flex;
    justify-content: center;
    margin: 4px 0;
}

.system-msg {
    background-color: var(--bg-system);
    color: var(--text-system);
    font-size: 12.5px;
    padding: 5px 12px;
    border-radius: 8px;
    max-width: 80%;
    text-align: center;
    box-shadow: var(--shadow);
}

/* Message rows */
.msg-row {
    display: flex;
    margin-bottom: 2px;
    padding: 0 2px;
}

.msg-row.incoming {
    justify-content: flex-start;
}

.msg-row.outgoing {
    justify-content: flex-end;
}

.msg-row.search-hidden {
    display: none;
}

.msg-row.search-highlight .bubble {
    outline: 2px solid var(--accent);
}

/* Bubbles */
.bubble {
    max-width: 72%;
    min-width: 80px;
    padding: 6px 10px 8px 10px;
    border-radius: var(--border-radius-bubble);
    box-shadow: var(--shadow);
    position: relative;
    word-break: break-word;
}

.msg-row.incoming .bubble {
    background-color: var(--bg-bubble-in);
    border-top-left-radius: 2px;
}

.msg-row.outgoing .bubble {
    background-color: var(--bg-bubble-out);
    border-top-right-radius: 2px;
}

.bubble-sender {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 3px;
    line-height: 1.2;
}

.bubble-text {
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

body.light .msg-row.outgoing .bubble-text {
    color: #111B21;
}

.bubble-time {
    font-size: 11px;
    color: var(--text-date);
    text-align: right;
    margin-top: 3px;
    line-height: 1;
}

body.light .msg-row.outgoing .bubble-time {
    color: #667781;
}

/* Media in bubbles */
.bubble-media {
    margin: 4px 0 4px 0;
    border-radius: 6px;
    overflow: hidden;
    max-width: 100%;
}

.bubble-media img {
    max-width: 280px;
    max-height: 280px;
    width: 100%;
    object-fit: cover;
    border-radius: 6px;
    display: block;
    cursor: pointer;
}

.bubble-media img.sticker {
    max-width: 140px;
    max-height: 140px;
    background: transparent;
    object-fit: contain;
    border-radius: 0;
}

.bubble-media video {
    max-width: 280px;
    width: 100%;
    border-radius: 6px;
    display: block;
}

.bubble-media audio {
    width: 100%;
    min-width: 200px;
}

.media-omitted {
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    padding: 2px 0;
}

.media-file-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: rgba(0,0,0,0.15);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-link);
    text-decoration: none;
    margin: 4px 0;
    word-break: break-all;
}

.media-file-link svg {
    width: 20px;
    height: 20px;
    fill: var(--text-link);
    flex-shrink: 0;
}

/* No results */
#no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    gap: 12px;
}

#no-results svg {
    width: 48px;
    height: 48px;
    fill: var(--text-secondary);
    opacity: 0.5;
}

#no-results p {
    font-size: 15px;
}

/* =========================================================
   GUIDE MODAL
   ========================================================= */
#guide-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
}

#guide-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg-modal);
    border-radius: var(--border-radius-ui);
    box-shadow: var(--shadow-modal);
    z-index: 201;
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#guide-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--divider);
}

#guide-header h2 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

#guide-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 50%;
    transition: background-color 0.15s;
}

#guide-close:hover {
    background-color: var(--bg-tab-active);
}

#guide-close svg {
    width: 20px;
    height: 20px;
    fill: var(--text-secondary);
}

#guide-tabs {
    display: flex;
    border-bottom: 1px solid var(--divider);
    padding: 0 20px;
}

.guide-tab {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    font-family: inherit;
}

.guide-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

#guide-content {
    padding: 20px;
    overflow-y: auto;
}

.guide-panel {
    display: none;
}

.guide-panel.active {
    display: block;
}

.guide-tip {
    background-color: var(--bg-guide-tip);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 10px 14px;
    font-size: 13.5px;
    color: var(--text-primary);
    margin-bottom: 16px;
    line-height: 1.5;
}

.guide-note {
    background-color: var(--bg-guide-note);
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 12px;
    line-height: 1.5;
}

.guide-steps {
    padding-left: 20px;
}

.guide-steps li {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.6;
    margin-bottom: 8px;
}

.guide-steps strong {
    color: var(--text-primary);
}

/* =========================================================
   TOAST
   ========================================================= */
#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: #2A3942;
    color: #E9EDE0;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 300;
    white-space: nowrap;
    max-width: 90vw;
    text-align: center;
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 600px) {
    #app-title {
        font-size: 15px;
    }

    #logo {
        width: 28px;
        height: 28px;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
    }

    .icon-btn svg {
        width: 20px;
        height: 20px;
    }

    #upload-section {
        padding: 24px 16px;
        min-height: calc(100vh - var(--header-height) - 41px);
    }

    #upload-title {
        font-size: 22px;
    }

    #drop-zone {
        padding: 28px 16px;
    }

    #chat-info {
        padding: 10px 14px;
    }

    #chat-meta {
        flex-direction: column;
        align-items: flex-start;
    }

    #chat-area {
        padding: 8px 10px;
        background-size: 250px;
    }

    .bubble {
        max-width: 88%;
    }

    .bubble-media img {
        max-width: 220px;
        max-height: 220px;
    }

    .bubble-media video {
        max-width: 220px;
    }

    #guide-modal {
        max-height: 92vh;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        border-radius: var(--border-radius-ui) var(--border-radius-ui) 0 0;
    }

    #search-inner {
        gap: 6px;
    }

    #search-date {
        font-size: 12px;
        padding: 4px 6px;
    }

    #privacy-banner {
        font-size: 12px;
        padding: 8px 14px;
    }
}

@media (min-width: 1200px) {
    #messages-container {
        max-width: 780px;
    }

    #chat-info {
        padding: 14px 40px;
    }

    #chat-meta {
        max-width: 780px;
    }

    #users-list {
        max-width: 780px;
    }

    #search-inner {
        max-width: 780px;
    }
}

/* Image lightbox */
#lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

#lightbox img {
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 4px;
}

#lightbox-close {
    position: fixed;
    top: 16px;
    right: 16px;
    background: rgba(0,0,0,0.5);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#lightbox-close svg {
    width: 22px;
    height: 22px;
    fill: #fff;
}
