/* =========================================================
   WhatsApp Inbox Dashboard — styles
   ========================================================= */

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

:root {
    --green:        #25D366;
    --green-dark:   #128C7E;
    --bg:           #f0f2f5;
    --panel:        #ffffff;
    --border:       #e4e7ea;
    --text:         #111b21;
    --muted:        #667781;
    --bubble-in:    #ffffff;
    --bubble-out:   #d9fdd3;
    --shadow:       0 1px 2px rgba(11,20,26,0.13);
}

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    height: 100%;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: transparent;
}

/* ============ Login ============ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #d4f5e0 0%, #f0f2f5 100%);
    padding: 20px;
}
.login-box {
    background: var(--panel);
    width: 100%;
    max-width: 380px;
    padding: 32px 28px;
    border-radius: 12px;
    box-shadow: 0 6px 30px rgba(0,0,0,0.08);
}
.login-logo {
    text-align: center;
    margin-bottom: 24px;
}
.login-logo h1 {
    margin: 8px 0 2px;
    font-size: 22px;
}
.login-logo p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}
.login-box label {
    display: block;
    margin-bottom: 14px;
}
.login-box label span {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.login-box input[type="text"],
.login-box input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    transition: border-color .15s;
}
.login-box input:focus {
    border-color: var(--green);
}
.login-box button[type="submit"] {
    width: 100%;
    padding: 12px;
    background: var(--green);
    color: #fff;
    border-radius: 6px;
    font-weight: 600;
    margin-top: 8px;
    transition: background .15s;
}
.login-box button[type="submit"]:hover {
    background: var(--green-dark);
}
.login-error {
    background: #fde2e2;
    color: #7a1818;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 14px;
    font-size: 14px;
}

/* ============ Top bar ============ */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 54px;
    padding: 0 18px;
    background: var(--green-dark);
    color: #fff;
}
.top-bar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.top-bar .brand span {
    font-weight: 600;
    font-size: 16px;
}
.top-bar .brand small {
    opacity: .85;
    font-size: 12px;
    margin-left: 4px;
}
.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.top-actions button,
.top-actions .logout-link {
    color: #fff;
    background: rgba(255,255,255,0.12);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 13px;
    text-decoration: none;
    transition: background .15s;
}
.top-actions button:hover,
.top-actions .logout-link:hover {
    background: rgba(255,255,255,0.25);
}

/* ============ Layout ============ */
.inbox-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.layout {
    flex: 1;
    display: grid;
    grid-template-columns: 360px 1fr;
    overflow: hidden;
    min-height: 0;
}

/* ============ Sidebar ============ */
.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.sidebar-search {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    background: #f6f7f9;
}
.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    outline: none;
    background: #fff;
}
.sidebar-search input:focus {
    border-color: var(--green);
}
.contact-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}
.contact-list li {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f3f5;
    cursor: pointer;
    display: flex;
    gap: 12px;
    transition: background .1s;
}
.contact-list li:hover {
    background: #f6f7f9;
}
.contact-list li.active {
    background: #e9f8ef;
}
.contact-list li.empty {
    justify-content: center;
    color: var(--muted);
    cursor: default;
}
.contact-list .avatar {
    flex-shrink: 0;
}
.contact-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.contact-meta .row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 6px;
}
.contact-meta .name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 15px;
}
.contact-meta .time {
    font-size: 11px;
    color: var(--muted);
    flex-shrink: 0;
}
.contact-meta .preview {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.contact-meta .preview.unread {
    color: var(--text);
    font-weight: 500;
}
.badge {
    background: var(--green);
    color: #fff;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    margin-left: 6px;
}

/* ============ Chat area ============ */
.chat {
    position: relative;
    display: flex;
    flex-direction: column;
    background: #efeae2;
    min-height: 0;
    /* WhatsApp-style subtle pattern */
    background-image:
      radial-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
      radial-gradient(rgba(0,0,0,0.02) 1px, transparent 1px);
    background-size: 24px 24px, 48px 48px;
    background-position: 0 0, 12px 12px;
}
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    text-align: center;
    padding: 20px;
}
.chat-empty h2 { margin: 12px 0 6px; font-weight: 500; color: #41525d; }
.chat-empty p { margin: 0; font-size: 14px; }

.chat-active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* The HTML `hidden` attribute must win over the display:flex above. */
.chat-empty[hidden],
.chat-active[hidden] {
    display: none;
}

.chat-header {
    height: 60px;
    background: #f0f2f5;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
}
.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--green-dark);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
    text-transform: uppercase;
}
.chat-name {
    font-weight: 600;
    font-size: 15px;
}
.chat-phone {
    font-size: 12px;
    color: var(--muted);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 10%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ============ Message bubbles ============ */
.msg {
    max-width: 70%;
    padding: 6px 10px 20px;
    border-radius: 8px;
    position: relative;
    box-shadow: var(--shadow);
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14.5px;
    line-height: 1.35;
}
.msg.incoming {
    background: var(--bubble-in);
    align-self: flex-start;
    border-top-left-radius: 2px;
}
.msg.outgoing {
    background: var(--bubble-out);
    align-self: flex-end;
    border-top-right-radius: 2px;
}
.msg .meta {
    position: absolute;
    right: 10px;
    bottom: 4px;
    font-size: 10.5px;
    color: var(--muted);
    display: flex;
    gap: 4px;
    align-items: center;
    white-space: nowrap;
}
.msg .status-icon { font-size: 12px; }
.msg.status-read .status-icon { color: #53bdeb; }
.msg.status-failed .meta { color: #c0392b; }

.msg img.media-image {
    max-width: 100%;
    border-radius: 6px;
    cursor: zoom-in;
    display: block;
}
.msg .media-caption { margin-top: 6px; }
.msg video.media-video {
    max-width: 100%;
    border-radius: 6px;
}
.msg audio.media-audio { width: 100%; }
.msg .media-file {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.05);
    padding: 8px 10px;
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
}
.msg .media-file .file-icon {
    width: 36px;
    height: 36px;
    background: var(--green-dark);
    color: #fff;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.msg .media-file .file-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.msg .media-file .file-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}
.msg .media-file .file-sub {
    font-size: 11px;
    color: var(--muted);
}
.msg .loc-link {
    display: inline-block;
    padding: 6px 10px;
    background: rgba(0,0,0,0.05);
    border-radius: 6px;
    text-decoration: none;
    color: var(--green-dark);
    font-weight: 500;
    font-size: 13px;
}
.day-divider {
    align-self: center;
    background: rgba(255,255,255,0.9);
    color: #41525d;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 10px;
    margin: 10px 0;
    box-shadow: var(--shadow);
}

/* ============ Composer ============ */
.composer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #f0f2f5;
    border-top: 1px solid var(--border);
}
.composer input[type="text"] {
    flex: 1;
    padding: 10px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    outline: none;
    background: #fff;
}
.composer input[type="text"]:focus {
    border-color: var(--green);
}
.composer button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--green-dark);
    color: #fff;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
}
.composer button:hover { background: var(--green); }
.composer #btn-attach,
.composer #btn-template {
    background: #e4e6eb;
    color: #3b4048;
    font-weight: 600;
}
.composer #btn-attach:hover,
.composer #btn-template:hover {
    background: #d2d5da;
}

/* ============ Modals ============ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box {
    background: #fff;
    border-radius: 10px;
    padding: 22px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-box.wide { max-width: 560px; }
.modal-box h3 {
    margin: 0 0 16px;
    font-size: 18px;
}
.modal-box label {
    display: block;
    margin-bottom: 12px;
}
.modal-box label span {
    display: block;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 4px;
}
.modal-box input[type="text"],
.modal-box input[type="file"],
.modal-box select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    background: #fff;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}
.modal-actions button {
    padding: 8px 16px;
    border-radius: 6px;
    background: var(--green-dark);
    color: #fff;
    font-weight: 500;
}
.modal-actions .btn-secondary {
    background: #e4e6eb;
    color: #3b4048;
}

.template-preview {
    background: #f7f8fa;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13px;
    white-space: pre-wrap;
    min-height: 60px;
    color: #3b4048;
    margin-bottom: 12px;
}
.template-vars .var-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.template-vars .var-row label {
    flex: 0 0 80px;
    margin: 0;
    font-size: 12px;
    color: var(--muted);
    text-transform: none;
    letter-spacing: 0;
}
.template-vars .var-row input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* ============ Lightbox ============ */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    padding: 20px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .layout {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: flex;
    }
    .sidebar.hidden-mobile {
        display: none;
    }
    .chat.hidden-mobile {
        display: none;
    }
    .messages {
        padding: 12px 4%;
    }
    .msg {
        max-width: 85%;
    }
    .top-bar .brand small { display: none; }
}
