/* =========================================================
   Bachelor Mess Manager - Design System
   ========================================================= */
:root {
    --color-primary: #0f766e;
    --color-primary-dark: #0b544e;
    --color-primary-light: #e6f4f2;
    --color-accent: #f59e0b;
    --color-danger: #dc2626;
    --color-danger-light: #fee2e2;
    --color-success: #16a34a;
    --color-success-light: #dcfce7;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-bg: #f7f8fa;
    --color-surface: #ffffff;
    --sidebar-width: 250px;
    --radius: 10px;
    --font: 'Segoe UI', 'Noto Sans Bengali', Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
}

a { text-decoration: none; color: inherit; transition: color .15s ease, opacity .15s ease; }
/* Plain "← ... ফিরে যান" style back-links: subtle arrow-shift on hover */
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--color-primary); font-weight: 600; transition: gap .15s ease; }
.back-link:hover { gap: 10px; color: var(--color-primary-dark); }

/* ---------- Auth pages (login / register / OTP) ---------- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    padding: 20px;
}
.auth-box {
    background: var(--color-surface);
    padding: 36px 32px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 35px rgba(0,0,0,0.2);
}
.auth-title { margin: 0 0 4px; font-size: 24px; color: var(--color-primary-dark); text-align: center; }
.auth-subtitle { margin: 0 0 24px; color: var(--color-text-muted); text-align: center; font-size: 14px; }
.auth-form label { display: block; margin: 14px 0 6px; font-size: 14px; font-weight: 600; }
.auth-form input {
    width: 100%; padding: 11px 12px; border: 1px solid var(--color-border);
    border-radius: 8px; font-size: 15px; font-family: var(--font);
}
.auth-form input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
/* space between the last input and the submit button */
.auth-form button[type="submit"] { margin-top: 22px; }
.auth-links { margin-top: 18px; text-align: center; font-size: 14px; color: var(--color-text-muted); }
.auth-links a { color: var(--color-primary); font-weight: 600; }
.auth-links span { margin: 0 8px; }
.auth-divider { text-align: center; margin: 18px 0; position: relative; color: var(--color-text-muted); font-size: 13px; }
.auth-divider::before, .auth-divider::after {
    content: ''; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--color-border);
}
.auth-divider::before { left: 0; } .auth-divider::after { right: 0; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; padding: 10px 18px; border-radius: 8px; border: none;
    font-size: 14px; font-weight: 600; cursor: pointer; font-family: var(--font);
    transition: transform .15s cubic-bezier(.2,.8,.2,1), box-shadow .15s ease, background-color .15s ease, opacity .15s ease;
    will-change: transform;
}
.btn-block { width: 100%; text-align: center; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); transform: translateY(-2px); box-shadow: 0 8px 18px rgba(15,118,110,.28); }
.btn-outline { background: transparent; border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-bg); transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0,0,0,.08); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(220,38,38,.28); filter: brightness(1.05); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(22,163,74,.28); filter: brightness(1.05); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:active { transform: translateY(0) scale(.97); box-shadow: none; transition-duration: .05s; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: var(--color-danger-light); color: #991b1b; }
.alert-success { background: var(--color-success-light); color: #14532d; }
.alert-info { background: var(--color-primary-light); color: var(--color-primary-dark); }

/* ---------- App shell / layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: #0b2a27;
    color: #fff;
    flex-shrink: 0;
    transition: margin-left .2s ease;
    overflow-y: auto;
}
.app-shell.sidebar-hidden .sidebar { margin-left: calc(-1 * var(--sidebar-width)); }

.sidebar-brand { padding: 20px; font-size: 18px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-nav { display: flex; flex-direction: column; padding: 10px 0; }
.sidebar-nav a {
    padding: 12px 20px; color: rgba(255,255,255,0.8); font-size: 14px; border-left: 3px solid transparent;
    transition: background-color .18s ease, color .18s ease, padding-left .18s ease, border-left-color .18s ease;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; padding-left: 24px; }
/* Menu Management dropdown groups (created from Support Portal) */
.sidebar-group summary {
    padding: 12px 20px; color: rgba(255,255,255,0.8); font-size: 14px; cursor: pointer;
    list-style: none; transition: background-color .18s ease, color .18s ease;
}
.sidebar-group summary::-webkit-details-marker { display: none; }
.sidebar-group summary:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-group summary::after { content: '▸'; float: right; transition: transform .18s ease; }
.sidebar-group[open] summary::after { transform: rotate(90deg); }
.sidebar-group a { padding-left: 40px; font-size: 13px; }
.sidebar-nav a.active { background: rgba(255,255,255,0.1); color: #fff; border-left-color: var(--color-accent); font-weight: 600; }

.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex; align-items: center; gap: 14px;
    background: var(--color-surface); border-bottom: 1px solid var(--color-border);
    padding: 14px 20px; position: sticky; top: 0; z-index: 10;
}
.menu-toggle {
    background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 8px;
    width: 38px; height: 38px; cursor: pointer; font-size: 16px;
    transition: background-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.menu-toggle:hover { background: var(--color-primary-light); transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,.08); }
.menu-toggle:active { transform: scale(.92); }
.page-title { margin: 0; font-size: 18px; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-badge { font-size: 13px; color: var(--color-text-muted); }

.content-area { padding: 24px; flex: 1; }

/* ---------- Cards / Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
    padding: 18px 20px;
}
.stat-card .stat-label { font-size: 13px; color: var(--color-text-muted); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; color: var(--color-primary-dark); }

.card {
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
    padding: 20px; margin-bottom: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { margin: 0; font-size: 16px; }

/* ---------- Forms (data entry) ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--color-border); border-radius: 7px;
    font-family: var(--font); font-size: 14px;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light);
}
.form-actions { margin-top: 18px; display: flex; gap: 10px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th, table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); text-align: left; white-space: nowrap; }
table.data-table th { background: var(--color-bg); font-weight: 600; color: var(--color-text-muted); font-size: 12px; text-transform: uppercase; }
table.data-table tr:hover td { background: var(--color-primary-light); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-active { background: var(--color-success-light); color: #14532d; }
.badge-inactive { background: var(--color-danger-light); color: #991b1b; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--color-text-muted); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .sidebar { position: fixed; height: 100vh; z-index: 30; margin-left: calc(-1 * var(--sidebar-width)); }
    .app-shell.mobile-open .sidebar { margin-left: 0; }
    .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }
    .app-shell.mobile-open .sidebar-backdrop { display: block; }
}

/* ---------- Password-confirm modal (delete/edit protection) ---------- */
.pw-modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.pw-modal-box { background: #fff; border-radius: 12px; padding: 24px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.pw-modal-box h3 { margin: 0 0 8px; font-size: 17px; }
.pw-modal-box p { margin: 0 0 14px; color: var(--color-text-muted, #666); font-size: 14px; }
.pw-modal-box input[type="password"] { width: 100%; padding: 10px 12px; border: 1px solid var(--color-border, #ddd); border-radius: 8px; font-size: 14px; }
.pw-modal-error { color: #b91c1c; font-size: 13px; margin-top: 8px; }
.pw-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Ad banner / interstitial (custom campaign popup) ----------
   Fixed 4:5 portrait card so the background image (recommended 1080x1350 px)
   is shown in full, identically on phones and desktop.
   Layout inside the card, top -> bottom:  Title / Content / CTA button.        */
.ad-banner-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.68); z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.ad-banner-box {
    position: relative; overflow: hidden; border-radius: 18px;
    background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-dark) 100%) center / cover no-repeat;
    background-size: cover; background-position: center center; background-repeat: no-repeat; /* any image size is scaled + centre-cropped to fill the card */
    aspect-ratio: var(--ad-r, .8);
    /* width never lets the 4:5 card grow taller than the screen */
    width: min(100%, 440px, calc((100vh - 24px) * var(--ad-r, .8)));
    width: min(100%, 440px, calc((100dvh - 24px) * var(--ad-r, .8)));
    box-shadow: 0 25px 60px rgba(0,0,0,.4);
}
.ad-banner-scrim {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    background: linear-gradient(to bottom, rgba(0,0,0,.50) 0%, rgba(0,0,0,.12) 28%, rgba(0,0,0,0) 50%, rgba(0,0,0,.18) 72%, rgba(0,0,0,.55) 100%);
}
.ad-banner-body {
    flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px;
    padding: 18px; color: #fff;
}
/* 1) Title — pinned to the very top (right padding keeps clear of the skip button) */
.ad-banner-body h3 {
    margin: 0; padding-right: 40px; color: #fff; font-size: 21px; line-height: 1.3;
    text-shadow: 0 1px 4px rgba(0,0,0,.6); overflow-wrap: anywhere;
}
/* 2) Content — directly under the title, scrolls if it is long */
.ad-banner-content {
    flex: 0 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    background: rgba(0,0,0,.34); border-radius: 12px; padding: 10px 12px;
    font-size: 14px; line-height: 1.5; color: #f3f4f6;
}
.ad-banner-body p { margin: 0 0 8px; color: #f3f4f6; font-size: 14px; white-space: pre-line; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.ad-banner-content p:last-child, .ad-banner-content ul:last-child { margin-bottom: 0; }
/* 3) CTA button — stays at the bottom */
.ad-banner-body > .btn { margin-top: auto; align-self: flex-start; flex-shrink: 0; }
.ad-banner-skip {
    position: absolute; top: 10px; right: 10px; z-index: 2; background: rgba(0,0,0,.55); color: #fff;
    border: none; border-radius: 999px; width: 34px; height: 34px; cursor: not-allowed; font-size: 14px;
}
.ad-banner-skip.ready { cursor: pointer; background: rgba(0,0,0,.78); }

.sidebar-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: rgba(255,255,255,.45); padding: 14px 20px 4px; }

/* ---------- Required field labels (red asterisk) ---------- */
.form-group label.required::after { content: " *"; color: #dc2626; font-weight: 700; }

.ad-banner-content p { margin: 0 0 8px; }
.ad-banner-content ul { margin: 0 0 10px; padding-left: 20px; }
.ad-banner-content li { margin-bottom: 4px; }

/* ---------- Adsterra banner ads ----------
   A banner is an ordinary block in the page flow: it scrolls together with the reports and
   text, takes its own space (nothing is covered) and sits where Support Portal placed it.   */
.ad-slot { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; }
.ad-slot-item {
    position: relative; overflow: hidden; isolation: isolate; contain: layout paint style;
    display: flex; align-items: center; justify-content: center;
    margin: 0; padding: 0; border: 0; line-height: 0; background: transparent; max-width: 100%;
}
.ad-slot-item > * { max-width: 100%; margin: 0; }
.ad-slot-item iframe, .ad-slot-item img { display: block; max-width: 100%; border: 0; }
.ad-slot-inline { margin: 0 0 20px; }                 /* between sections (cards already carry 20px below) */
.ad-slot-bottom { padding: 0 24px 24px; }              /* end of page, above the bottom menu buttons */
.ad-slot-auth { width: 100%; max-width: 440px; margin-top: 16px; }
.ad-slot-auth .ad-slot-item { background: var(--color-surface); border-radius: 12px; }

/* ---------- Market entry: itemized product rows (responsive) ---------- */
.product-row {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, .8fr) minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 10px; align-items: end;
    margin-bottom: 12px; width: 100%;
}
.pr-field { min-width: 0; }
.pr-field label { display: block; font-size: 12px; font-weight: 600; color: var(--color-text-muted); margin-bottom: 4px; }
.product-row input, .product-row select {
    min-width: 0; width: 100%; box-sizing: border-box;
    padding: 10px 12px; border: 1.5px solid var(--color-border); border-radius: 8px;
    font-family: var(--font); font-size: 14px; background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.product-row input:focus, .product-row select:focus {
    outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light);
}
.pr-remove { height: 41px; padding: 0 14px; }
.pr-remove-text { display: none; }
.add-product-btn { margin-top: 4px; }
.itemized-total { margin-top: 12px; font-weight: 600; }
@media (max-width: 768px) {
    /* each product becomes its own mini card:  [ name ]  [ qty | unit ]  [ amount | remove ] */
    .product-row {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas: "name name" "qty unit" "amount remove";
        gap: 12px; padding: 14px; margin-bottom: 14px;
        background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 14px;
    }
    .pr-name { grid-area: name; }
    .pr-qty { grid-area: qty; }
    .pr-unit { grid-area: unit; }
    .pr-amount { grid-area: amount; }
    .pr-remove { grid-area: remove; width: 100%; height: 46px; color: var(--color-danger); border-color: #fecaca; background: #fff; }
    .pr-remove-text { display: inline; }
    .product-row input, .product-row select { height: 46px; font-size: 16px; }
    .add-product-btn { width: 100%; height: 46px; border-style: dashed; color: var(--color-primary); }
    .itemized-total { text-align: right; font-size: 16px; padding: 12px 4px 0; }
}

/* =========================================================
   Reports — cards sit SIDE BY SIDE on wide screens, and stack
   one under another on phones.
   ========================================================= */
.report-grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px; margin-bottom: 20px; align-items: start;
}
.report-grid > .card { margin-bottom: 0; min-width: 0; }
.report-grid h3 { margin: 0 0 14px; font-size: 16px; }
.report-tabs { display: flex; border-bottom: 1px solid var(--color-border); overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.report-tabs::-webkit-scrollbar { display: none; }
.report-tab { white-space: nowrap; flex: 0 0 auto; }
.split-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }

/* Desktop: account block + bottom bar are mobile-only */
.sidebar-user { display: none; }
.bottom-nav { display: none; }

/* =========================================================
   MOBILE — app-style layout (phones)
   ========================================================= */
@media (max-width: 768px) {
    html { -webkit-text-size-adjust: 100%; }
    body { background: #eef3f2; -webkit-tap-highlight-color: transparent; }

    /* reports: one under another */
    .report-grid, .split-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }

    /* ---- App bar (top) ---- */
    .topbar {
        padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
        gap: 12px; border-bottom: 0;
        background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
        box-shadow: 0 2px 10px rgba(11,84,78,.25);
    }
    .menu-toggle { background: rgba(255,255,255,.16); border-color: transparent; color: #fff; width: 40px; height: 40px; border-radius: 12px; }
    .menu-toggle:hover { background: rgba(255,255,255,.26); box-shadow: none; transform: none; }
    .page-title { color: #fff; font-size: 17px; font-weight: 700; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* topbar shows ONLY the subscription status (or the "buy" button); name + logout live in the menu */
    .topbar-right { display: flex; flex-shrink: 0; gap: 8px; }
    .topbar-right .user-badge, .topbar-right .topbar-logout { display: none; }
    .topbar-right .topbar-sub { font-size: 12px; padding: 6px 10px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
    .topbar-right .topbar-buy { min-height: 36px; padding: 7px 12px; font-size: 12.5px; background: var(--color-accent); color: #3b2300; border-radius: 999px; box-shadow: 0 1px 4px rgba(0,0,0,.2); }

    /* room for the bottom tab bar (the docked ad, if any, sits between content and the bar) */
    :root { --bn-total: calc(70px + env(safe-area-inset-bottom)); }
    .main-content { padding-bottom: var(--bn-total); }
    .ad-slot-bottom { padding: 0 14px 14px; }
    .ad-slot-inline { margin-bottom: 14px; }
    .content-area { padding: 14px; }

    /* ---- Cards & stats ---- */
    .card { border: 0; border-radius: 16px; padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(15,23,42,.07), 0 4px 14px rgba(15,23,42,.04); }
    .card-header { flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
    .card h3 { font-size: 15px; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .stat-card { border: 0; border-radius: 14px; padding: 14px; box-shadow: 0 1px 3px rgba(15,23,42,.07); }
    .stat-card .stat-label { font-size: 12px; }
    .stat-card .stat-value { font-size: 20px; overflow-wrap: anywhere; }

    /* ---- Forms: big tap targets, 16px text (stops iOS zoom-on-focus) ---- */
    .form-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .form-grid[style*="repeat(4"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .form-group input, .form-group select, .form-group textarea,
    .auth-form input { font-size: 16px; padding: 11px 12px; min-height: 46px; border-radius: 10px; }
    .form-group textarea { min-height: 90px; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; text-align: center; }
    .btn { min-height: 44px; padding: 11px 18px; border-radius: 10px; }
    .btn-sm { min-height: 38px; }
    .btn:hover { transform: none; box-shadow: none; }
    /* inline "filter" bars (display:flex;align-items:end) wrap instead of overflowing */
    .card[style*="display:flex"], form[style*="display:flex"] { flex-wrap: wrap; }
    .card[style*="display:flex"] > .form-group, form[style*="display:flex"] > .form-group { flex: 1 1 100%; }

    /* ---- Tables scroll sideways inside their card ---- */
    .table-wrap { margin: 0 -4px; -webkit-overflow-scrolling: touch; }
    table.data-table { font-size: 13px; }
    table.data-table th, table.data-table td { padding: 10px 10px; }

    /* ---- Slide-in menu (drawer) ---- */
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; height: 100%; height: 100dvh;
        width: min(84vw, 310px); z-index: 160;
        display: flex; flex-direction: column;
        margin-left: 0; transform: translateX(-102%); visibility: hidden;
        transition: transform .25s ease, visibility 0s linear .25s;
        box-shadow: none; border-radius: 0 20px 20px 0;
    }
    .app-shell.mobile-open .sidebar { margin-left: 0; transform: translateX(0); visibility: visible; transition: transform .25s ease; box-shadow: 8px 0 30px rgba(0,0,0,.35); }
    .sidebar-backdrop { display: block; opacity: 0; pointer-events: none; z-index: 155; background: rgba(0,0,0,.5); transition: opacity .25s ease; position: fixed; inset: 0; }
    .app-shell.mobile-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    .sidebar-brand { padding-top: calc(20px + env(safe-area-inset-top)); flex-shrink: 0; }
    .sidebar-nav { flex: 1 0 auto; }
    .sidebar-nav a { padding: 13px 20px; font-size: 15px; }

    /* account block pinned to the bottom of the menu: avatar+name, subscription, LOGOUT (all same width, centred) */
    .sidebar-user {
        display: flex; flex-direction: column; align-items: stretch; gap: 10px;
        position: sticky; bottom: 0; margin-top: auto; flex-shrink: 0;
        background: #08201e; border-top: 1px solid rgba(255,255,255,.12);
        padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    }
    .sidebar-user-info { display: flex; align-items: center; gap: 12px; }
    .sidebar-user-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--color-accent); color: #3b2300; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
    .sidebar-user-text { min-width: 0; flex: 1; text-align: left; }
    .sidebar-user-name { font-weight: 600; font-size: 14px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .sidebar-user-role { font-size: 12px; color: rgba(255,255,255,.55); }
    .sidebar-sub, .sidebar-logout { display: block; width: 100%; text-align: center; box-sizing: border-box; }
    .sidebar-sub { padding: 10px 12px; border-radius: 12px; font-size: 13px; font-weight: 600; line-height: 1.4; }
    .sidebar-sub.is-active { background: rgba(34,197,94,.16); color: #bbf7d0; }
    .sidebar-sub.is-expired { background: rgba(245,158,11,.2); color: #fde68a; }
    .sidebar-logout { padding: 12px; border-radius: 12px; background: rgba(220,38,38,.16); color: #fecaca; font-weight: 700; font-size: 14px; }
    .sidebar-logout:active { background: rgba(220,38,38,.3); }

    /* ---- Bottom tab bar: every tab is a clearly visible coloured button ---- */
    .bottom-nav {
        display: flex; gap: 8px; align-items: stretch;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
        height: var(--bn-total); box-sizing: border-box;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
        background: var(--color-surface); border-top: 1px solid var(--color-border);
        box-shadow: 0 -4px 18px rgba(15,23,42,.08);
    }
    .bottom-nav-item {
        flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        padding: 4px 2px; font-family: var(--font); font-size: 11.5px; font-weight: 700;
        background: var(--color-primary-light); color: var(--color-primary-dark);
        border: 1px solid rgba(15,118,110,.22); border-radius: 14px;
        transition: transform .12s ease, background-color .12s ease;
    }
    .bn-icon { font-size: 20px; line-height: 1; }
    .bn-label { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .bottom-nav-item.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; box-shadow: 0 3px 8px rgba(15,118,110,.35); }
    .bottom-nav-item:active { transform: scale(.95); }

    /* ---- Password-confirm modal sits above everything incl. ads ---- */
    .pw-modal-overlay { z-index: 220; }

    /* ---- Ad popup: slightly larger type for thumbs ---- */
    .ad-banner-body h3 { font-size: 20px; }
}

/* Larger phones in landscape / tablets keep the 2-column report grid; very small phones tighten up */
@media (max-width: 380px) {
    .stat-card .stat-value { font-size: 18px; }
    .bn-label { font-size: 10px; }
    .content-area { padding: 12px; }
}

/* Campaign form: background preview shows the exact 4:5 crop users will see */
.ad-bg-preview { display: block; width: 140px; aspect-ratio: 4 / 5; object-fit: cover; margin-top: 8px; border-radius: 10px; border: 1px solid var(--color-border); }

/* Password modal above the (desktop) ad slot too */
.pw-modal-overlay { z-index: 220; }

/* Campaign popup on phones — picture fills the whole rounded card (any image size is
   scaled + centre-cropped, no black/empty bars anywhere); the text area sits ON TOP of the
   picture as a light panel at the bottom; round ✕ button just above the card.            */
@media (max-width: 768px) {
    .ad-banner-overlay { padding: calc(64px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom)); align-items: center; justify-content: center; }
    .ad-banner-box {
        width: min(100%, 440px, calc((100vh - 110px) * var(--ad-r, .8))); width: min(100%, 440px, calc((100dvh - 110px) * var(--ad-r, .8)));
        height: auto; max-width: none; aspect-ratio: var(--ad-r, .8);
        border-radius: 16px; overflow: visible; box-shadow: 0 18px 50px rgba(0,0,0,.4);
    }
    .ad-banner-scrim {
        position: absolute; inset: 0; background: none; border-radius: 16px; overflow: hidden;
        display: flex; flex-direction: column; justify-content: flex-start; /* text panel at the TOP of the picture */
    }
    .ad-banner-body {
        flex: 0 1 auto; max-height: 75%; overflow-y: auto; margin: 10px; padding: 14px 16px; gap: 8px;
        background: rgba(255,255,255,.72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
        border-radius: 14px; color: #111827;
    }
    .ad-banner-body h3 { color: #111827; text-shadow: none; padding-right: 0; font-size: 19px; }
    .ad-banner-content { background: none; padding: 0; color: #374151; overflow: visible; flex-shrink: 0; }
    .ad-banner-body > * { flex-shrink: 0; }
    .ad-banner-body p, .ad-banner-content p { color: #374151; text-shadow: none; }
    .ad-banner-body > .btn { align-self: flex-start; margin-top: 4px; }
    .ad-banner-skip {
        top: -52px; right: 0; width: 40px; height: 40px; font-size: 16px;
        background: #fff; color: #111827; box-shadow: 0 2px 8px rgba(0,0,0,.3);
    }
    .ad-banner-skip.ready { background: #fff; }
}

/* No background picture: the card is only as big as its text (no empty coloured area) */
.ad-banner-box.no-bg { aspect-ratio: auto; height: auto; width: min(100%, 440px); }
.ad-banner-box.no-bg .ad-banner-scrim { position: relative; inset: auto; padding-bottom: 0; }
.ad-banner-box.no-bg .ad-banner-body { flex: 0 1 auto; max-height: calc(100vh - 150px); max-height: calc(100dvh - 150px); overflow-y: auto; }

/* =====================================================================
   Support chat — Messenger / WhatsApp style
   ===================================================================== */
.chat-app {
    position: relative; display: flex; flex-direction: column; overflow: hidden;
    height: calc(100vh - 150px); min-height: 440px; max-height: 780px;
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 16px;
    box-shadow: 0 6px 24px rgba(15,23,42,.08); margin-bottom: 20px;
}
.chat-head {
    display: flex; align-items: center; gap: 12px; flex-shrink: 0;
    padding: 10px 14px; color: #fff;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
}
.chat-back { display: none; color: #fff; font-size: 24px; line-height: 1; padding: 4px 8px 4px 0; text-decoration: none; }
.chat-avatar {
    width: 42px; height: 42px; flex-shrink: 0; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--color-accent); color: #3b2300; font-weight: 700; font-size: 18px;
}
.chat-avatar.support { background: #fff; font-size: 22px; }
.chat-head-info { min-width: 0; }
.chat-head-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-sub { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-body {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding: 14px 12px 10px; display: flex; flex-direction: column; gap: 3px;
    background-color: #e9f0ee;
    background-image: radial-gradient(rgba(15,118,110,.07) 1.2px, transparent 1.2px);
    background-size: 18px 18px;
    scroll-behavior: smooth;
}
.chat-empty, .chat-list-empty { margin: auto; text-align: center; color: var(--color-text-muted); font-size: 14px; background: rgba(255,255,255,.75); padding: 10px 16px; border-radius: 12px; }
.chat-date { align-self: center; margin: 10px 0 6px; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #475569; background: rgba(255,255,255,.9); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.chat-row { display: flex; max-width: 100%; }
.chat-row.mine { justify-content: flex-end; }
.chat-row.first { margin-top: 8px; }
.chat-bubble {
    position: relative; max-width: min(78%, 520px); padding: 7px 10px 5px; border-radius: 12px;
    font-size: 14.5px; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere;
    box-shadow: 0 1px 1.5px rgba(0,0,0,.13);
}
.chat-row.theirs .chat-bubble { background: #fff; color: #111827; border-top-left-radius: 4px; }
.chat-row.mine .chat-bubble { background: #d3f3e6; color: #0b2a27; border-top-right-radius: 4px; }
/* little speech-bubble tail on the first message of a run */
.chat-row.first .chat-bubble::before { content: ''; position: absolute; top: 0; width: 10px; height: 12px; }
.chat-row.theirs.first .chat-bubble::before { left: -7px; background: #fff; clip-path: polygon(100% 0, 0 0, 100% 100%); }
.chat-row.mine.first .chat-bubble::before { right: -7px; background: #d3f3e6; clip-path: polygon(0 0, 100% 0, 0 100%); }
.chat-sender { font-size: 12px; font-weight: 700; color: var(--color-primary); margin-bottom: 2px; }
.chat-text { white-space: pre-wrap; }
.chat-link { color: #0369a1; text-decoration: underline; }
.chat-img { display: block; max-width: 100%; width: 240px; max-height: 300px; object-fit: cover; border-radius: 8px; margin-bottom: 4px; cursor: zoom-in; }
.chat-file { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 4px; border-radius: 8px; background: rgba(15,118,110,.1); color: inherit; text-decoration: none; font-weight: 600; font-size: 13.5px; }
.chat-file-icon { font-size: 22px; }
.chat-meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 1px; font-size: 11px; color: #64748b; }
.chat-tick { font-size: 12px; letter-spacing: -2px; color: #94a3b8; }
.chat-tick.read { color: #0ea5e9; }
.chat-tick.failed { color: #dc2626; letter-spacing: 0; }
.chat-row.failed .chat-bubble { opacity: .75; }
.chat-retry { border: 0; background: none; color: #dc2626; font: inherit; font-size: 11px; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0 0 0 6px; }

.chat-jump {
    position: absolute; right: 16px; bottom: 82px; z-index: 5; width: 38px; height: 38px; border-radius: 50%;
    border: 0; background: #fff; color: var(--color-primary-dark); font-size: 18px; cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.chat-jump[hidden], .chat-error[hidden], .chat-attach[hidden] { display: none; }
.chat-error { margin: 0; padding: 7px 14px; font-size: 13px; background: #fee2e2; color: #991b1b; flex-shrink: 0; }

.chat-attach { flex-shrink: 0; padding: 8px 12px 0; background: #f1f5f9; border-top: 1px solid var(--color-border); }
.chat-attach-chip { display: inline-flex; align-items: center; gap: 10px; max-width: 100%; padding: 6px 8px; background: #fff; border: 1px solid var(--color-border); border-radius: 12px; }
.chat-attach-chip img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; }
.chat-attach-icon { font-size: 28px; }
.chat-attach-name { font-size: 13px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-attach-x { border: 0; background: #e2e8f0; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 12px; }

.chat-composer {
    display: flex; align-items: flex-end; gap: 8px; flex-shrink: 0;
    padding: 8px 10px; background: #f1f5f9; border-top: 1px solid var(--color-border);
}
.chat-attach-btn { width: 42px; height: 42px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: #64748b; cursor: pointer; margin: 0; }
.chat-attach-btn:hover { background: #e2e8f0; color: var(--color-primary-dark); }
.chat-composer textarea {
    flex: 1; min-width: 0; min-height: 42px; max-height: 120px; resize: none; box-sizing: border-box;
    padding: 10px 16px; border: 1px solid var(--color-border); border-radius: 22px; background: #fff;
    font-family: inherit; font-size: 15px; line-height: 1.35; outline: none;
}
.chat-composer textarea:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
.chat-send {
    width: 42px; height: 42px; flex-shrink: 0; border: 0; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    background: var(--color-primary); color: #fff; transition: transform .12s ease, opacity .12s ease;
}
.chat-send.is-empty { opacity: .55; }
.chat-send:not(:disabled):active { transform: scale(.9); }

.chat-lightbox { position: fixed; inset: 0; z-index: 400; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.85); cursor: zoom-out; padding: 16px; }
.chat-lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* Support Portal: conversation list + chat side by side */
.chat-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; margin-bottom: 20px; }
.chat-list { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 440px; max-height: 780px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 16px; overflow: hidden; box-shadow: 0 6px 24px rgba(15,23,42,.08); }
.chat-list-head { padding: 14px; border-bottom: 1px solid var(--color-border); }
.chat-list-head h3 { margin: 0 0 10px; font-size: 16px; }
.chat-list-head input { width: 100%; box-sizing: border-box; padding: 9px 14px; border: 1px solid var(--color-border); border-radius: 999px; background: #f1f5f9; font-size: 14px; }
.chat-list-body { flex: 1; overflow-y: auto; }
.chat-thread { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid #f1f5f9; text-decoration: none; color: inherit; }
.chat-thread:hover { background: #f8fafc; }
.chat-thread.active { background: var(--color-primary-light); }
.chat-thread-mid { min-width: 0; flex: 1; }
.chat-thread-top, .chat-thread-bot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-thread-name { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread-time { font-size: 11.5px; color: var(--color-text-muted); flex-shrink: 0; }
.chat-thread-code { font-size: 11.5px; color: var(--color-primary-dark); }
.chat-thread-prev { font-size: 13px; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-unread { flex-shrink: 0; min-width: 20px; height: 20px; padding: 0 6px; box-sizing: border-box; border-radius: 999px; background: #22c55e; color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.chat-pane { min-width: 0; }
.chat-pane .chat-app { margin-bottom: 0; }
.chat-placeholder { height: calc(100vh - 150px); min-height: 440px; max-height: 780px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--color-text-muted); background: var(--color-surface); border: 1px dashed var(--color-border); border-radius: 16px; text-align: center; padding: 20px; }
.chat-placeholder-icon { font-size: 54px; }

/* alert counters: menu badge, ☰ dot, toast, and the 💬 chip in the subscription list */
.menu-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; box-sizing: border-box; margin-left: 6px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 12px; font-weight: 700; line-height: 1; vertical-align: middle; animation: badgePulse 1.6s ease-in-out infinite; }
.menu-badge[hidden] { display: none; }
@keyframes badgePulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.6); } 50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); } }
.menu-toggle { position: relative; }
.menu-toggle.has-alert::after { display: none; content: ''; position: absolute; top: 5px; right: 5px; width: 11px; height: 11px; border-radius: 50%; background: #ef4444; border: 2px solid #fff; }
.support-toast {
    position: fixed; z-index: 300; top: 74px; left: 50%; transform: translateX(-50%); width: min(92vw, 380px);
    display: flex; align-items: center; gap: 12px; padding: 12px 14px; box-sizing: border-box;
    background: #fff; color: #111827; text-decoration: none; border-radius: 14px; border-left: 5px solid #ef4444;
    box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: toastIn .3s ease;
}
.support-toast-icon { font-size: 26px; }
.support-toast-text { display: flex; flex-direction: column; min-width: 0; }
.support-toast-text small { color: #64748b; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.chat-chip { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: #f1f5f9; text-decoration: none; font-size: 12px; }
.chat-chip.has-new { background: #ef4444; color: #fff; }

@media (max-width: 768px) {
    .menu-toggle.has-alert::after { display: block; }
    .chat-app { height: calc(100vh - 62px - 28px - var(--bn-total, 70px)); height: calc(100dvh - 62px - 28px - var(--bn-total, 70px)); min-height: 360px; max-height: none; border-radius: 14px; margin-bottom: 14px; }
    .chat-bubble { max-width: 86%; }
    .chat-img { width: 200px; }
    .chat-head-sub { font-size: 11px; }
    .chat-composer { padding-bottom: 8px; }
    .chat-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .chat-layout.has-active .chat-list { display: none; }
    .chat-layout:not(.has-active) .chat-pane { display: none; }
    .chat-list { height: calc(100vh - 62px - 28px - var(--bn-total, 70px)); height: calc(100dvh - 62px - 28px - var(--bn-total, 70px)); max-height: none; }
    .chat-placeholder { display: none; }
    .chat-back { display: block; }
    .support-toast { top: 70px; }
}

/* Phones: chat = full screen between the top bar and the bottom tab bar (message box always visible) */
@media (max-width: 768px) {
    body.chat-page { overflow: hidden; }
    body.chat-page .ad-slot { display: none; }
    body.chat-page .main-content { padding-bottom: 0; }
    body.chat-page .content-area { padding: 0; }
    body.chat-page .chat-app, body.chat-page .chat-list {
        position: fixed; left: 0; right: 0; top: var(--chat-top, 56px); bottom: var(--chat-bottom, calc(70px + env(safe-area-inset-bottom)));
        height: auto !important; max-height: none; min-height: 0; margin: 0; z-index: 30;
        border-radius: 0; border-left: 0; border-right: 0; box-shadow: none;
    }
    body.chat-page.chat-typing .bottom-nav { display: none; }
    body.chat-page .chat-composer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
    body.chat-page:not(.chat-typing) .chat-composer { padding-bottom: 8px; }
}
