/* ============================================================
   WA Platform — chat-first design system
   ------------------------------------------------------------
   Familiarity is the product requirement here: users already know
   how WhatsApp works, so the layout deliberately follows that
   mental model (list -> thread -> composer, 3-dot menu for
   everything else). Where we differ from WhatsApp, it is because
   this is a business tool: delivery status is more prominent, and
   the menu is organised by job rather than by settings taxonomy.

   Type is Hind so Hindi/Marathi message bodies render on the same
   baseline as English UI labels.
   ============================================================ */

:root {
    --wa:            #0B7B6E;
    --wa-deep:       #075E54;
    --wa-wash:       #DCF4E9;

    --bg:            #EDE8E0;
    --panel:         #FFFFFF;
    --bubble-out:    #DCF4E9;
    --bubble-in:     #FFFFFF;

    --ink:           #14201D;
    --ink-2:         #5F6E69;
    --ink-3:         #8A9691;
    --line:          #E2E6E3;
    --line-strong:   #C8D0CC;
    --danger:        #B42318;
    --danger-bg:     #FBE9E7;

    --r:      14px;
    --r-sm:   10px;
    --r-pill: 999px;
    --tap:    48px;

    --font: 'Hind', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 16.5px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 700; letter-spacing: -0.015em; line-height: 1.2; margin: 0 0 .35em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
p  { margin: 0 0 1em; }
a  { color: var(--wa-deep); }

.wa-muted  { color: var(--ink-2); }
.wa-small  { font-size: .875rem; }
.wa-strong { font-weight: 600; }
.wa-num    { font-variant-numeric: tabular-nums; }

/* ---------- Auth ---------- */
.wa-auth-shell {
    min-height: 100vh; min-height: 100dvh;
    display: flex; flex-direction: column; justify-content: center;
    padding: 40px 20px 56px;
    max-width: 440px; margin: 0 auto; width: 100%;
    background: var(--panel);
}
.wa-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 30px; }
.wa-brand-mark {
    width: 42px; height: 42px; border-radius: 12px;
    background: var(--wa); color: #fff;
    display: grid; place-items: center;
    font-weight: 700; font-size: 1.15rem; flex-shrink: 0;
}
.wa-brand-name { font-weight: 700; font-size: 1.08rem; letter-spacing: -0.01em; }

.wa-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 20px 18px;
}
.wa-card + .wa-card { margin-top: 14px; }

.wa-field { margin-bottom: 16px; }
.wa-field:last-child { margin-bottom: 0; }
.wa-field label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 6px; }

.wa-input, .wa-select, .wa-textarea {
    width: 100%; min-height: var(--tap);
    padding: 12px 14px;
    font-size: 1rem; font-family: inherit; color: var(--ink);
    background: var(--panel);
    border: 1.5px solid var(--line-strong);
    border-radius: var(--r-sm);
}
.wa-input:focus, .wa-select:focus, .wa-textarea:focus {
    outline: none; border-color: var(--wa);
    box-shadow: 0 0 0 3px var(--wa-wash);
}
.wa-hint { font-size: .82rem; color: var(--ink-2); margin-top: 6px; line-height: 1.45; }

.wa-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; min-height: var(--tap);
    padding: 13px 20px;
    font-size: 1rem; font-weight: 700; font-family: inherit; line-height: 1.2;
    border: 1.5px solid transparent; border-radius: var(--r-sm);
    cursor: pointer; text-decoration: none;
}
.wa-btn:active { transform: translateY(1px); }
.wa-btn + .wa-btn { margin-top: 10px; }
.wa-btn-primary   { background: var(--wa); color: #fff; }
.wa-btn-primary:active { background: var(--wa-deep); }
.wa-btn-secondary { background: var(--panel); color: var(--ink); border-color: var(--line-strong); }
.wa-btn-danger    { background: var(--danger-bg); color: var(--danger); }

.wa-alert { padding: 13px 15px; border-radius: var(--r-sm); font-size: .92rem; margin-bottom: 16px; line-height: 1.45; }
.wa-alert div + div { margin-top: 4px; }
.wa-alert-error   { background: var(--danger-bg); color: var(--danger); }
.wa-alert-success { background: var(--wa-wash); color: var(--wa-deep); }

.wa-form-footer { text-align: center; margin-top: 20px; font-size: .93rem; color: var(--ink-2); }
.wa-form-footer a { font-weight: 700; text-decoration: none; }

/* ============================================================
   Chat app shell
   ============================================================ */

.wa-app {
    height: 100vh; height: 100dvh;
    display: flex; flex-direction: column;
    background: var(--bg);
    max-width: 640px; margin: 0 auto;
}

.wa-app-header {
    background: var(--wa-deep);
    color: #fff;
    padding: 0 6px 0 18px;
    min-height: 58px;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    flex-shrink: 0;
}
.wa-app-header .title { font-weight: 700; font-size: 1.12rem; letter-spacing: -0.01em; }

.wa-header-icon-btn {
    background: none; border: none; color: #fff;
    width: var(--tap); height: var(--tap);
    display: grid; place-items: center;
    cursor: pointer; border-radius: var(--r-sm);
    text-decoration: none; flex-shrink: 0;
}
.wa-header-icon-btn:active { background: rgba(255,255,255,.14); }

/* ---------- Search ---------- */
.wa-search-bar { padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.wa-search-bar input {
    width: 100%; min-height: 42px;
    padding: 10px 15px;
    border-radius: var(--r-pill);
    border: 1.5px solid var(--line);
    background: var(--bg);
    font-family: inherit; font-size: .96rem;
}
.wa-search-bar input:focus { outline: none; border-color: var(--wa); }

/* ---------- Chat list ---------- */
.wa-chat-list { flex: 1; overflow-y: auto; background: var(--panel); }

.wa-chat-list-item {
    display: flex; align-items: center; gap: 13px;
    padding: 11px 16px;
    min-height: 72px;
    text-decoration: none; color: inherit;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}
.wa-chat-list-item:last-child { border-bottom: none; }
.wa-chat-list-item:active { background: var(--bg); }

.wa-avatar {
    width: 48px; height: 48px; border-radius: 50%;
    background: var(--wa-wash); color: var(--wa-deep);
    display: grid; place-items: center;
    font-weight: 700; font-size: 1.05rem; flex-shrink: 0;
}
.wa-avatar-sm { width: 38px; height: 38px; font-size: .9rem; }

.wa-chat-list-meta { flex: 1; min-width: 0; }
.wa-chat-list-name { font-weight: 600; font-size: .99rem; line-height: 1.3; }
.wa-chat-list-preview {
    color: var(--ink-2); font-size: .88rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wa-chat-list-time { font-size: .74rem; color: var(--ink-3); flex-shrink: 0; align-self: flex-start; padding-top: 3px; }

/* ---------- FAB ---------- */
.wa-fab {
    position: fixed; bottom: 22px; right: 20px;
    width: 58px; height: 58px; border-radius: 50%;
    background: var(--wa); color: #fff;
    display: grid; place-items: center;
    box-shadow: 0 6px 18px rgba(11,123,110,.36);
    text-decoration: none; z-index: 25;
}
.wa-fab:active { background: var(--wa-deep); }

/* ---------- Thread ---------- */
.wa-thread-header {
    display: flex; align-items: center; gap: 11px;
    padding: 8px 14px;
    min-height: 58px;
    background: var(--wa-deep); color: #fff;
    flex-shrink: 0;
}
.wa-thread-header .name { font-weight: 600; font-size: 1rem; line-height: 1.25; }
.wa-thread-header .status { font-size: .78rem; opacity: .82; font-variant-numeric: tabular-nums; }
.wa-back-btn {
    background: none; border: none; color: #fff;
    width: 40px; height: 40px;
    display: grid; place-items: center;
    cursor: pointer; margin-left: -8px;
}

.wa-thread {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px 18px;
    display: flex; flex-direction: column; gap: 5px;
}

.wa-bubble-row { display: flex; }
.wa-bubble-row.out { justify-content: flex-end; }

.wa-bubble {
    max-width: 80%;
    padding: 8px 11px 6px;
    border-radius: 12px;
    font-size: .95rem;
    line-height: 1.45;
    box-shadow: 0 1px 1px rgba(0,0,0,.07);
    word-break: break-word;
}
.wa-bubble.in  { background: var(--bubble-in);  border-top-left-radius: 3px; }
.wa-bubble.out { background: var(--bubble-out); border-top-right-radius: 3px; }

.wa-bubble-time {
    font-size: .68rem;
    color: var(--ink-3);
    text-align: right;
    margin-top: 3px;
    font-variant-numeric: tabular-nums;
    display: flex; align-items: center; justify-content: flex-end; gap: 4px;
}
.wa-bubble-status { font-size: .72rem; letter-spacing: -1px; }
.wa-status-read   { color: #2E86DE; }
.wa-status-failed { color: var(--danger); letter-spacing: 0; }

.wa-date-divider {
    align-self: center;
    background: rgba(20,32,29,.07);
    color: var(--ink-2);
    font-size: .74rem;
    font-weight: 600;
    padding: 4px 13px;
    border-radius: var(--r-pill);
    margin: 8px 0;
}

/* ---------- Composer ---------- */
.wa-composer {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}
.wa-composer textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 11px 16px;
    font-size: .97rem;
    font-family: inherit;
    line-height: 1.4;
    background: var(--panel);
    max-height: 110px;
    min-height: 44px;
}
.wa-composer textarea:focus { outline: none; border-color: var(--wa); }
.wa-send-btn {
    width: 46px; height: 46px; border-radius: 50%;
    border: none; background: var(--wa); color: #fff;
    display: grid; place-items: center;
    cursor: pointer; flex-shrink: 0;
}
.wa-send-btn:disabled { opacity: .5; }

/* ---------- 3-dot menu sheet ---------- */
.wa-menu-overlay {
    position: fixed; inset: 0;
    background: rgba(20,32,29,.45);
    z-index: 40;
    opacity: 0; pointer-events: none;
    transition: opacity .18s ease;
}
.wa-menu-overlay.open { opacity: 1; pointer-events: auto; }

.wa-menu-sheet {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(80vw, 330px);
    background: var(--panel);
    z-index: 41;
    transform: translateX(100%);
    transition: transform .2s ease;
    overflow-y: auto;
    display: flex; flex-direction: column;
}
.wa-menu-sheet.open { transform: translateX(0); }

.wa-menu-header {
    padding: 22px 20px 18px;
    background: var(--wa-deep);
    color: #fff;
}
.wa-menu-header .wa-avatar { background: rgba(255,255,255,.18); color: #fff; margin-bottom: 12px; }
.wa-menu-header .wa-muted { color: rgba(255,255,255,.75); }

.wa-menu-section-label {
    padding: 16px 20px 6px;
    font-size: .75rem; font-weight: 700;
    color: var(--ink-3);
}

.wa-menu-item {
    display: flex; align-items: center; gap: 15px;
    padding: 14px 20px;
    min-height: var(--tap);
    text-decoration: none; color: var(--ink);
    font-size: .96rem; font-weight: 500;
}
.wa-menu-item:active { background: var(--bg); }
.wa-menu-item svg { flex-shrink: 0; color: var(--ink-2); }

/* ---------- Status pill (WABA connection) ---------- */
.wa-status-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: var(--r-pill);
    font-size: .8rem; font-weight: 700;
}
.wa-status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.wa-connected     { background: var(--wa-wash); color: var(--wa-deep); }
.wa-not-connected { background: #F0F2F1; color: var(--ink-2); }

/* ---------- Empty state ---------- */
.wa-empty-state {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    padding: 50px 30px;
    color: var(--ink-2);
    background: var(--panel);
}
.wa-empty-state p { margin: 0 0 6px; }
.wa-empty-title { font-weight: 600; color: var(--ink); font-size: 1.02rem; }

/* Scrollable settings-style page body inside the app shell */
.wa-scroll-body { flex: 1; overflow-y: auto; padding: 18px; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* ============================================================
   Wati-inspired working tools
   A business inbox is not a personal one: conversations need to be
   sortable, and the monthly send quota needs to be visible before
   it runs out mid-campaign.
   ============================================================ */

.wa-label {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: var(--r-pill);
    font-size: .7rem;
    font-weight: 700;
    background: var(--wa-wash);
    color: var(--wa-deep);
    white-space: nowrap;
    flex-shrink: 0;
}
.wa-label-lead     { background: #E5EBFB; color: #1D4ED8; }
.wa-label-customer { background: #E1F2EB; color: #0F7B5A; }
.wa-label-followup { background: #FBEEDA; color: #A65A08; }
.wa-label-closed   { background: #EEF1F0; color: #5F6E69; }

.wa-chat-list-name { display: flex; align-items: center; gap: 7px; }
.wa-chat-list-name > span:first-child {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Label filter row above the chat list */
.wa-filters {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding: 10px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    scrollbar-width: none;
    flex-shrink: 0;
}
.wa-filters::-webkit-scrollbar { display: none; }
.wa-filter {
    flex-shrink: 0;
    padding: 6px 13px;
    border-radius: var(--r-pill);
    border: 1.5px solid var(--line-strong);
    background: var(--panel);
    color: var(--ink);
    font-size: .84rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.wa-filter.active { background: var(--wa-deep); border-color: var(--wa-deep); color: #fff; }
.wa-filter-count { opacity: .6; margin-left: 5px; font-variant-numeric: tabular-nums; }

/* Quota meter */
.wa-meter { margin-top: 12px; }
.wa-meter-head { display: flex; justify-content: space-between; gap: 12px; font-size: .87rem; margin-bottom: 7px; }
.wa-meter-label { font-weight: 600; }
.wa-meter-value { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.wa-meter-track { height: 8px; border-radius: var(--r-pill); background: var(--bg); overflow: hidden; }
.wa-meter-fill { height: 100%; background: var(--wa); border-radius: var(--r-pill); }
.wa-meter-warn .wa-meter-fill { background: #A65A08; }
.wa-meter-full .wa-meter-fill { background: var(--danger); }

/* Contact detail strip inside a thread */
.wa-thread-meta {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    font-size: .85rem;
}
.wa-thread-meta form { display: flex; gap: 8px; align-items: center; flex: 1; }
.wa-thread-meta select {
    flex: 1;
    min-height: 38px;
    padding: 7px 10px;
    border: 1.5px solid var(--line-strong);
    border-radius: 9px;
    font-family: inherit;
    font-size: .87rem;
    background: var(--panel);
}

.wa-phone-input { display: flex; align-items: stretch; }
.wa-phone-cc {
    display: flex; align-items: center;
    padding: 0 13px;
    background: var(--bg);
    border: 1.5px solid var(--line-strong);
    border-right: none;
    border-radius: var(--r-sm) 0 0 var(--r-sm);
    color: var(--ink-2);
    font-weight: 600;
}
.wa-phone-input .wa-input { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
