/* ==================================================================
   WhatsApp Marketing — design system
   Layered on Bootstrap 5.3. Tokens first, then components.
   ================================================================== */

:root {
    --app-sidebar-width: 248px;

    /* Brand: a deep teal-green that reads as WhatsApp without imitating it. */
    --brand-500: #0f8a72;
    --brand-600: #0b6f5c;
    --brand-700: #085546;
    --brand-050: #e6f4f0;

    --radius-sm: .5rem;
    --radius-md: .75rem;
    --radius-lg: 1rem;

    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);

    /* Bootstrap overrides so the whole kit picks up the brand. */
    --bs-primary: var(--brand-500);
    --bs-primary-rgb: 15, 138, 114;
    --bs-success: var(--brand-500);
    --bs-success-rgb: 15, 138, 114;
    --bs-link-color: var(--brand-600);
    --bs-link-hover-color: var(--brand-700);
    --bs-border-radius: var(--radius-sm);
    --bs-border-radius-lg: var(--radius-md);
}

[data-bs-theme="light"] {
    --app-surface: #f6f7f9;
    --app-panel: #ffffff;
    --app-hairline: #e7e9ee;
    --app-muted: #667085;
    --app-thread-bg: #eceff1;
    --app-bubble-in: #ffffff;
    --app-bubble-out: #d7f3e3;

    --bs-body-color: #1d2433;
    --bs-body-bg: #f6f7f9;
    --bs-emphasis-color: #101828;
}

[data-bs-theme="dark"] {
    --app-surface: #0f1319;
    --app-panel: #171d26;
    --app-hairline: #262e3a;
    --app-muted: #98a2b3;
    --app-thread-bg: #0b1116;
    --app-bubble-in: #1e2732;
    --app-bubble-out: #105143;

    --bs-body-color: #e4e7ec;
    --bs-body-bg: #0f1319;
    --bs-emphasis-color: #f9fafb;
    --bs-border-color: #262e3a;
}

/* ==================================================================
   Base
   ================================================================== */

body,
.auth-body {
    background-color: var(--app-surface);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -.006em;
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    letter-spacing: -.018em;
    font-weight: 600;
}

.text-body-secondary,
.form-text {
    color: var(--app-muted) !important;
}

/* ==================================================================
   Buttons
   ================================================================== */

.btn {
    --bs-btn-font-weight: 500;
    border-radius: var(--radius-sm);
    transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.btn-success,
.btn-primary {
    --bs-btn-bg: var(--brand-500);
    --bs-btn-border-color: var(--brand-500);
    --bs-btn-hover-bg: var(--brand-600);
    --bs-btn-hover-border-color: var(--brand-600);
    --bs-btn-active-bg: var(--brand-700);
    --bs-btn-active-border-color: var(--brand-700);
    --bs-btn-disabled-bg: var(--brand-500);
    --bs-btn-disabled-border-color: var(--brand-500);
    box-shadow: var(--shadow-xs);
}

.btn-outline-secondary {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-border-color: var(--app-hairline);
    --bs-btn-hover-bg: var(--app-surface);
    --bs-btn-hover-border-color: var(--app-hairline);
    --bs-btn-hover-color: var(--bs-body-color);
    --bs-btn-active-bg: var(--app-surface);
    --bs-btn-active-color: var(--bs-body-color);
    --bs-btn-active-border-color: var(--app-hairline);
    background-color: var(--app-panel);
}

.btn-sm {
    --bs-btn-padding-y: .32rem;
    --bs-btn-padding-x: .7rem;
    --bs-btn-font-size: .8125rem;
}

/* ==================================================================
   Cards, tables, forms
   ================================================================== */

.card {
    background-color: var(--app-panel);
    border-radius: var(--radius-md);
    border-color: var(--app-hairline);
}

.card.shadow-sm {
    box-shadow: var(--shadow-sm) !important;
}

.card-header,
.card-footer {
    background-color: transparent;
    border-color: var(--app-hairline);
    padding-inline: 1.15rem;
}

.card-body {
    padding: 1.15rem;
}

.table {
    --bs-table-border-color: var(--app-hairline);
    margin-bottom: 0;
}

.table > :not(caption) > * > * {
    padding: .75rem 1.15rem;
}

.table thead th {
    background-color: transparent;
    border-bottom: 1px solid var(--app-hairline);
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--app-muted);
    white-space: nowrap;
}

.table-hover > tbody > tr:hover > * {
    --bs-table-accent-bg: transparent;
    background-color: rgba(var(--bs-primary-rgb), .04);
}

.form-control,
.form-select {
    border-color: var(--app-hairline);
    border-radius: var(--radius-sm);
    background-color: var(--app-panel);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), .14);
}

.form-label {
    font-size: .8125rem;
    font-weight: 500;
    margin-bottom: .35rem;
}

.input-group-text {
    background-color: var(--app-surface);
    border-color: var(--app-hairline);
    color: var(--app-muted);
}

.form-check-input:checked {
    background-color: var(--brand-500);
    border-color: var(--brand-500);
}

.badge {
    font-weight: 500;
    letter-spacing: .01em;
    border-radius: 1rem;
    padding: .3em .65em;
}

.alert {
    border-radius: var(--radius-md);
    border-color: transparent;
}

.modal-content {
    border-radius: var(--radius-lg);
    border-color: var(--app-hairline);
    background-color: var(--app-panel);
}

.progress {
    background-color: var(--app-hairline);
    border-radius: 1rem;
}

/* ==================================================================
   Shell
   ================================================================== */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--app-sidebar-width);
    flex: 0 0 var(--app-sidebar-width);
    background: var(--app-panel);
    border-right: 1px solid var(--app-hairline);
    position: sticky;
    top: 0;
    height: 100vh;
}

.app-sidebar-offcanvas {
    width: 272px;
    background: var(--app-panel);
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
}

.app-topbar {
    background: var(--app-panel);
    border-bottom: 1px solid var(--app-hairline);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.05rem 1.15rem;
    border-bottom: 1px solid var(--app-hairline);
    text-decoration: none;
    color: inherit;
}

.app-brand-mark {
    width: 2rem;
    height: 2rem;
    border-radius: .6rem;
    background: linear-gradient(140deg, var(--brand-500), var(--brand-700));
    color: #fff;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    box-shadow: var(--shadow-xs);
}

.app-brand-name {
    font-weight: 600;
    line-height: 1.15;
    font-size: .9375rem;
}

.nav-pills .nav-link {
    color: var(--bs-body-color);
    border-radius: var(--radius-sm);
    padding: .5rem .7rem;
    font-size: .9rem;
    font-weight: 500;
}

.nav-pills .nav-link:hover {
    background-color: rgba(var(--bs-primary-rgb), .07);
}

.nav-pills .nav-link.active {
    background-color: var(--brand-500);
    box-shadow: var(--shadow-xs);
}

.nav-pills .nav-link .app-icon {
    color: var(--app-muted);
}

.nav-pills .nav-link.active .app-icon {
    color: #fff;
}

.sidebar-section {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--app-muted);
    padding: .85rem .7rem .3rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .55rem .6rem;
    border-radius: var(--radius-sm);
    background: var(--app-surface);
}

.avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--brand-050);
    color: var(--brand-700);
    display: grid;
    place-items: center;
    font-size: .8rem;
    font-weight: 600;
    flex: 0 0 auto;
}

[data-bs-theme="dark"] .avatar {
    background: rgba(15, 138, 114, .18);
    color: #6ee7c4;
}

.avatar-lg {
    width: 2.5rem;
    height: 2.5rem;
    font-size: .95rem;
}

/* ==================================================================
   Small pieces
   ================================================================== */

.status-dot {
    display: inline-block;
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: #cbd2dc;
    flex: 0 0 auto;
}

.status-dot.is-on {
    background: #12b76a;
    box-shadow: 0 0 0 3px rgba(18, 183, 106, .18);
}

.status-dot.is-warn {
    background: #f79009;
    box-shadow: 0 0 0 3px rgba(247, 144, 9, .18);
}

.status-dot.is-off {
    background: #cbd2dc;
}

.stat-card {
    color: inherit;
    transition: transform .14s ease, box-shadow .14s ease;
    border: 1px solid transparent;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md) !important;
    border-color: rgba(var(--bs-primary-rgb), .25);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 650;
    letter-spacing: -.03em;
    line-height: 1.1;
}

.stat-label {
    font-size: .78rem;
    color: var(--app-muted);
    font-weight: 500;
}

.min-w-0 { min-width: 0; }
.cursor-pointer { cursor: pointer; }

.app-icon {
    flex: 0 0 auto;
    vertical-align: -.125em;
}

.empty-state-mark {
    width: 3rem;
    height: 3rem;
    margin: 0 auto;
    border-radius: var(--radius-md);
    background: var(--app-surface);
    color: var(--app-muted);
    display: grid;
    place-items: center;
    font-size: 1.1rem;
    letter-spacing: .2rem;
}

.skip-link {
    position: absolute;
    top: .5rem;
    left: .5rem;
    z-index: 1080;
    background: var(--app-panel);
    padding: .5rem .75rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}

:focus-visible {
    outline: 2px solid var(--brand-500);
    outline-offset: 2px;
}

/* ==================================================================
   Inbox
   ================================================================== */

.inbox-row {
    min-height: calc(100vh - 9.5rem);
}

.conversation-list {
    max-height: calc(100vh - 13.5rem);
    overflow-y: auto;
}

.conversation-list .list-group-item {
    border-color: var(--app-hairline);
    padding: .7rem 1rem;
    background-color: transparent;
}

.conversation-list .list-group-item:hover {
    background-color: rgba(var(--bs-primary-rgb), .05);
}

.conversation-list .list-group-item.active {
    background-color: var(--brand-500);
    border-color: var(--brand-500);
}

.chat-card {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 9.5rem);
}

.chat-thread {
    flex: 1 1 auto;
    overflow-y: auto;
    background-color: var(--app-thread-bg);
    padding: 1rem 1.15rem;
}

.chat-bubble {
    max-width: min(75%, 32rem);
    margin-bottom: .45rem;
    padding: .45rem .65rem .3rem;
    border-radius: var(--radius-md);
    background: var(--app-bubble-in);
    box-shadow: var(--shadow-xs);
    word-wrap: break-word;
}

.chat-bubble.is-outgoing {
    margin-left: auto;
    background: var(--app-bubble-out);
}

[data-bs-theme="dark"] .chat-bubble {
    color: #e9edef;
}

.chat-text {
    white-space: pre-wrap;
    font-size: .9rem;
    line-height: 1.45;
}

.chat-meta {
    display: flex;
    gap: .3rem;
    justify-content: flex-end;
    align-items: center;
    font-size: .68rem;
    color: var(--app-muted);
    margin-top: .1rem;
}

.chat-tag {
    font-size: .62rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
    color: var(--brand-600);
    margin-bottom: .15rem;
}

.chat-status.status-read { color: #3b9ede; }
.chat-status.status-failed { color: #d92d20; }
.chat-error { color: #d92d20; }

.chat-daymark {
    text-align: center;
    margin: .9rem 0 .6rem;
}

.chat-daymark span {
    display: inline-block;
    padding: .18rem .6rem;
    border-radius: 1rem;
    font-size: .7rem;
    font-weight: 500;
    background: rgba(0, 0, 0, .07);
}

[data-bs-theme="dark"] .chat-daymark span {
    background: rgba(255, 255, 255, .09);
    color: #e9edef;
}

.chat-daymark-unread span {
    background: var(--brand-500);
    color: #fff;
    font-weight: 600;
}

/* ---- Attachments ---- */

.chat-media-link { display: block; line-height: 0; }

.chat-media-image {
    display: block;
    max-width: 100%;
    width: 15rem;
    max-height: 18rem;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, .05);
}

.chat-media-audio {
    width: min(15rem, 100%);
    height: 2.5rem;
    display: block;
}

.chat-media-file,
.chat-media-pending {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .6rem;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, .05);
    color: inherit;
    text-decoration: none;
    max-width: 15rem;
}

.chat-media-file:hover {
    background: rgba(0, 0, 0, .1);
    color: inherit;
}

.chat-media-pending { color: var(--app-muted); }

[data-bs-theme="dark"] .chat-media-file,
[data-bs-theme="dark"] .chat-media-pending {
    background: rgba(255, 255, 255, .07);
}

.chat-bubble:has(> .chat-media-link:only-child) { padding: .25rem; }

.chat-media-image + .chat-text,
.chat-media-file + .chat-text,
.chat-media-audio + .chat-text { margin-top: .35rem; }

/* ---- Composer ---- */

.composer {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
}

.composer-input {
    resize: none;
    overflow-y: auto;
    max-height: 160px;
    border-radius: 1.25rem;
    padding: .55rem .95rem;
    line-height: 1.45;
}

.composer-send,
.composer-attach,
.composer-quick {
    border-radius: 50%;
    width: 2.6rem;
    height: 2.6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    padding: 0;
    margin: 0;
}

.composer-attach,
.composer-quick {
    cursor: pointer;
    background: var(--app-surface);
    border: 1px solid var(--app-hairline);
    color: var(--app-muted);
}

.composer-attach:hover,
.composer-quick:hover {
    color: var(--brand-600);
    border-color: var(--brand-500);
}

.attach-chip {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    margin-bottom: .5rem;
    border: 1px solid var(--app-hairline);
    border-radius: var(--radius-sm);
    background: var(--app-surface);
}

.quick-reply-menu {
    max-height: 20rem;
    overflow-y: auto;
    min-width: 20rem;
    border-radius: var(--radius-md);
    border-color: var(--app-hairline);
    box-shadow: var(--shadow-lg);
}

.quick-reply-menu .dropdown-item {
    white-space: normal;
    padding: .55rem .9rem;
}

.quick-reply-shortcut {
    font-size: .7rem;
    font-weight: 600;
    color: var(--brand-600);
}

/* ==================================================================
   Campaign builder and tags
   ================================================================== */

.contact-picker-list {
    max-height: 18rem;
    overflow-y: auto;
    background: var(--app-panel);
    border-radius: var(--radius-sm);
}

.contact-option {
    cursor: pointer;
    margin: 0;
    border-color: var(--app-hairline) !important;
}

.contact-option:hover { background-color: rgba(var(--bs-primary-rgb), .05); }
.contact-option:last-child { border-bottom: 0 !important; }

.template-preview {
    background: var(--app-thread-bg);
    border-radius: var(--radius-md);
    padding: 1rem;
    min-height: 8rem;
}

.template-preview .preview-bubble {
    background: var(--app-bubble-out);
    border-radius: var(--radius-md);
    padding: .6rem .75rem;
    box-shadow: var(--shadow-xs);
    white-space: pre-wrap;
    font-size: .9rem;
}

.template-preview .preview-footer {
    color: var(--app-muted);
    font-size: .72rem;
    margin-top: .35rem;
}

.template-preview mark {
    background: #fde68a;
    padding: 0 .2rem;
    border-radius: .2rem;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .72rem;
    font-weight: 500;
    padding: .18rem .55rem;
    border-radius: 1rem;
}

.bulk-bar {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translate(-50%, 180%);
    z-index: 1040;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem .8rem;
    border-radius: var(--radius-md);
    background: #101828;
    color: #fff;
    min-width: min(34rem, calc(100vw - 2rem));
    box-shadow: var(--shadow-lg);
    transition: transform .2s cubic-bezier(.2, .8, .3, 1);
}

.bulk-bar.is-visible { transform: translate(-50%, 0); }

.bulk-bar .form-select-sm {
    background-color: rgba(255, 255, 255, .1);
    border-color: rgba(255, 255, 255, .2);
    color: #fff;
    max-width: 9rem;
}

/* ==================================================================
   Dashboard chart
   ================================================================== */

.activity-chart {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    height: 9rem;
}

.activity-day {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
    text-align: center;
}

.activity-bars {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
    height: 100%;
}

.activity-bar {
    width: 42%;
    min-height: 3px;
    border-radius: .3rem .3rem 0 0;
    transition: height .35s ease;
}

.activity-in { background: #98c9f0; }
.activity-out { background: var(--brand-500); }

.activity-label,
.activity-total {
    font-size: .7rem;
    color: var(--app-muted);
    margin-top: .3rem;
}

.legend-swatch {
    display: inline-block;
    width: .6rem;
    height: .6rem;
    border-radius: .18rem;
}

.legend-in { background: #98c9f0; }
.legend-out { background: var(--brand-500); }

/* ==================================================================
   Auth and error pages
   ================================================================== */

.auth-body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(60rem 30rem at 15% -10%, rgba(15, 138, 114, .1), transparent 60%),
        radial-gradient(50rem 26rem at 95% 105%, rgba(15, 138, 114, .08), transparent 60%);
    pointer-events: none;
}

.auth-card {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--app-hairline);
}

.error-code {
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -.04em;
    color: var(--brand-500);
}

/* ==================================================================
   Responsive and motion
   ================================================================== */

@media (max-width: 991.98px) {
    .inbox-row,
    .chat-card {
        min-height: auto;
        max-height: none;
    }

    .conversation-list { max-height: none; }

    .chat-thread {
        min-height: 55vh;
        max-height: 60vh;
    }

    .quick-reply-menu { min-width: min(20rem, calc(100vw - 2rem)); }
}

@media (prefers-reduced-motion: reduce) {
    .stat-card,
    .bulk-bar,
    .activity-bar,
    .btn {
        transition: none;
    }
}

/* ==================================================================
   Impersonation banner
   ================================================================== */

.impersonation-bar {
    position: sticky;
    top: 0;
    z-index: 1045;
    background: linear-gradient(90deg, #b54708, #dc6803);
    color: #fff;
}

.impersonation-bar .btn-light {
    --bs-btn-color: #b54708;
    font-weight: 600;
}

.impersonation-bar .app-icon {
    flex: 0 0 auto;
}
