/* Telegram CRM — modern dark theme (emerald accent), v2 2026-08-19 */

/* ── Bootstrap Dark Mode Variable Overrides ─────────────────────────────── */
[data-bs-theme="dark"] {
    --bs-primary:                  #10b981;
    --bs-primary-rgb:              16, 185, 129;
    --bs-link-color:               #10b981;
    --bs-link-hover-color:         #059669;
    --bs-body-bg:                  #0f172a;
    --bs-body-color:               #e2e8f0;
    --bs-secondary-color:          #94a3b8;
    --bs-secondary-bg:             #1e293b;
    --bs-tertiary-bg:              #263248;
    --bs-border-color:             rgba(255,255,255,0.08);
    --bs-border-color-translucent: rgba(255,255,255,0.08);
    --bs-card-bg:                  #1e293b;
    --bs-card-border-color:        rgba(255,255,255,0.07);
    --bs-modal-bg:                 #1e293b;
    --bs-modal-border-color:       rgba(255,255,255,0.07);

    /* Softer, friendlier corners app-wide (badges, alerts, dropdowns,
       list-groups, form controls) — components below that need a specific
       radius still set it explicitly and win over this default. */
    --bs-border-radius:    10px;
    --bs-border-radius-sm: 7px;
    --bs-border-radius-lg: 14px;
    --bs-border-radius-xl: 18px;

    /* Reusable brand accents */
    --brand:            #10b981;
    --brand-2:           #059669;
    --brand-grad:        linear-gradient(135deg, #10b981 0%, #059669 100%);
    --brand-grad-hover:  linear-gradient(135deg, #059669 0%, #047857 100%);
    --brand-grad-active: linear-gradient(135deg, #047857 0%, #036b52 100%);
    --brand-glow:        rgba(16,185,129,0.35);
    --brand-glow-soft:   rgba(16,185,129,0.18);

    /* Fixed workspace-switcher bar height (2026-09-29) — referenced by
       every element below that anchors itself to the true viewport top
       (.sidebar, .mobile-topbar, .thread-pane on mobile) so they sit
       flush under .app-topbar instead of being covered by it. */
    --topbar-h: 46px;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 0.9rem;
    background: #0f172a;
    color: #e2e8f0;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Admin-only (web/pages/_layout.php adds this class to <body> only when
   $me['is_admin']) — makes room for .app-topbar below without affecting
   non-admin pages, which never render that header at all. */
body.has-app-topbar {
    padding-top: var(--topbar-h);
}

/* ── Fixed workspace switcher (2026-09-29) — YRL CRM / Video CRM /
   ISPmanager, admin-only, always visible on every admin page. Replaces the
   old sidebar "YRL ▾" dropdown (removed from web/pages/_layout.php). Sits
   above everything else (.sidebar and its mobile drawer included, see
   z-index); body.has-app-topbar's padding-top above makes room for it. ── */
.app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    z-index: 300;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0 0.6rem;
    background: #070b16;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
    overflow-x: auto;
    scrollbar-width: none;
}
.app-topbar::-webkit-scrollbar { display: none; }

.app-topbar-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255,255,255,0.5);
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}
.app-topbar-tab i {
    font-size: 0.85rem;
}
.app-topbar-tab:hover {
    background: rgba(255,255,255,0.06);
    color: #e2e8f0;
}
.app-topbar-tab.active {
    background: var(--brand-grad);
    color: #04150d;
    box-shadow: 0 4px 14px -4px var(--brand-glow);
}
.app-topbar-tab.active:hover {
    background: var(--brand-grad);
    color: #04150d;
}
/* Visually separate from the YRL CRM / Video CRM group (2026-09-29, user
   feedback) — pinned to the far right of the bar instead of trailing
   directly after Video CRM. */
.app-topbar-tab--right {
    margin-left: auto;
}

::selection { background: rgba(16,185,129,0.35); color: #fff; }

/* Consistent, friendlier keyboard-focus ring app-wide (replaces the
   browser default outline, which is easy to lose against a dark theme). */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
.sidebar-link:focus-visible,
.analytics-nav-item:focus-visible,
.analytics-nav-sub:focus-visible,
.dialog-item:focus-visible,
.page-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--brand-glow);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    min-height: 100vh;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    flex-shrink: 0;
    background: linear-gradient(180deg, #0a0f1e 0%, #070b16 100%);
    border-right: 1px solid rgba(255,255,255,0.05);
    box-shadow: 6px 0 24px rgba(0,0,0,0.22);
}

/* Admin pages only (.app-topbar sits above) — sticks right below the fixed
   bar instead of under it, and loses exactly that much height so it still
   fits the viewport. */
body.has-app-topbar .sidebar {
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    min-height: calc(100vh - var(--topbar-h));
}

.sidebar-brand {
    white-space: nowrap;
}

.sidebar-section-label {
    font-size: 0.63rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.22);
}

.sidebar-link {
    color: rgba(255,255,255,0.55);
    border-radius: 7px;
    padding: 0.45rem 0.75rem;
    font-size: 0.845rem;
    border-left: 3px solid transparent;
    margin-left: -3px;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
    white-space: nowrap;
}

.sidebar-link:hover {
    background: rgba(16,185,129,0.09);
    color: #10b981;
    transform: translateX(2px);
}

.sidebar-link.active {
    background: linear-gradient(90deg, rgba(16,185,129,0.16) 0%, rgba(16,185,129,0.04) 100%);
    border-left-color: #10b981;
    color: #10b981;
    font-weight: 600;
}

/* ── Main wrapper ────────────────────────────────────────────────────────── */
.main-wrapper {
    min-height: 100vh;
    overflow-x: hidden;
    background:
        radial-gradient(1100px 550px at 12% -8%, rgba(16,185,129,0.05), transparent 60%),
        #0f172a;
}

/* Fade page content in on each full navigation (not touched by any
   AJAX/polling refresh in this app — those only replace inner subtrees). */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.main-wrapper > .p-4 {
    animation: fadeInUp 0.35s ease-out;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card.shadow-sm,
.card.shadow {
    box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 10px 28px -14px rgba(0,0,0,0.55) !important;
}

.card-header {
    border-bottom: 1px solid rgba(255,255,255,0.07);
    background: transparent !important;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #e2e8f0;
    letter-spacing: 0.01em;
}

/* ── bg-light overrides ──────────────────────────────────────────────────── */
.bg-light {
    background-color: #263248 !important;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table {
    --bs-table-bg:          transparent;
    --bs-table-color:       #e2e8f0;
    --bs-table-border-color: rgba(255,255,255,0.06);
    --bs-table-hover-bg:    rgba(255,255,255,0.045);
    --bs-table-striped-bg:  rgba(255,255,255,0.02);
}

.table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.07) !important;
}

.table td {
    vertical-align: middle;
}

.table > tbody > tr {
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.table > tbody > tr:hover {
    box-shadow: inset 3px 0 0 0 rgba(16,185,129,0.55);
}

.table-light {
    --bs-table-bg: transparent;
    --bs-table-color: #64748b;
}

.table-light > * > tr > * {
    background: transparent !important;
    color: #64748b;
}

/* A sticky header needs an opaque background — .table-light above makes
   header cells transparent so they blend into the card in the normal
   (non-sticky) case, but a sticky header stays in place while rows scroll
   underneath it, so transparency lets that scrolling content show through
   the header text instead of being hidden behind it. */
.table-light.sticky-top > tr > * {
    background: #1e293b !important;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    border-radius: 8px;
    font-weight: 500;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease,
                background-image 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover:not(:disabled):not(.disabled) {
    transform: translateY(-1px);
}

.btn:active:not(:disabled):not(.disabled) {
    transform: translateY(0) scale(0.97);
    transition-duration: 0.05s;
}

.btn:disabled, .btn.disabled {
    transform: none !important;
}

.btn-primary {
    --bs-btn-bg:                 #10b981;
    --bs-btn-border-color:       #10b981;
    --bs-btn-hover-bg:           #059669;
    --bs-btn-hover-border-color: #059669;
    --bs-btn-active-bg:          #047857;
    --bs-btn-color:              #fff;
    --bs-btn-hover-color:        #fff;
    --bs-btn-active-color:       #fff;
    font-weight: 500;
    background-image: var(--brand-grad);
    border: none;
}

.btn-primary:hover  { background-image: var(--brand-grad-hover);  box-shadow: 0 8px 20px -6px var(--brand-glow); }
.btn-primary:active { background-image: var(--brand-grad-active); box-shadow: 0 2px 8px -2px var(--brand-glow); }

.btn-outline-primary {
    --bs-btn-color:                  #10b981;
    --bs-btn-border-color:           #10b981;
    --bs-btn-hover-bg:               #10b981;
    --bs-btn-hover-border-color:     #10b981;
    --bs-btn-hover-color:            #fff;
    --bs-btn-active-bg:              #059669;
}

.btn-outline-primary:hover { box-shadow: 0 6px 16px -6px var(--brand-glow); }

.btn-secondary {
    --bs-btn-bg:           #334155;
    --bs-btn-border-color: #334155;
    --bs-btn-hover-bg:     #475569;
    --bs-btn-color:        #e2e8f0;
    --bs-btn-hover-color:  #fff;
}

.btn-outline-secondary {
    --bs-btn-color:              #94a3b8;
    --bs-btn-border-color:       rgba(255,255,255,0.15);
    --bs-btn-hover-bg:           rgba(255,255,255,0.07);
    --bs-btn-hover-border-color: rgba(255,255,255,0.2);
    --bs-btn-hover-color:        #e2e8f0;
}

.btn-outline-danger {
    --bs-btn-color:              #f87171;
    --bs-btn-border-color:       rgba(248,113,113,0.4);
    --bs-btn-hover-bg:           rgba(248,113,113,0.12);
    --bs-btn-hover-color:        #f87171;
    --bs-btn-hover-border-color: rgba(248,113,113,0.6);
}

.btn-outline-danger:hover { box-shadow: 0 6px 16px -6px rgba(248,113,113,0.35); }

.btn-outline-warning {
    --bs-btn-color:              #fbbf24;
    --bs-btn-border-color:       rgba(251,191,36,0.4);
    --bs-btn-hover-bg:           rgba(251,191,36,0.1);
    --bs-btn-hover-color:        #fbbf24;
    --bs-btn-hover-border-color: rgba(251,191,36,0.6);
}

.btn-outline-info {
    --bs-btn-color:              #38bdf8;
    --bs-btn-border-color:       rgba(56,189,248,0.4);
    --bs-btn-hover-bg:           rgba(56,189,248,0.1);
    --bs-btn-hover-color:        #38bdf8;
    --bs-btn-hover-border-color: rgba(56,189,248,0.6);
}

.btn-success {
    --bs-btn-bg:           #10b981;
    --bs-btn-border-color: #10b981;
    --bs-btn-hover-bg:     #059669;
    --bs-btn-color:        #fff;
    --bs-btn-hover-color:  #fff;
    background-image: var(--brand-grad);
    border: none;
}

.btn-success:hover { background-image: var(--brand-grad-hover); box-shadow: 0 8px 20px -6px var(--brand-glow); }

.btn-warning {
    --bs-btn-bg:           #f59e0b;
    --bs-btn-border-color: #f59e0b;
    --bs-btn-hover-bg:     #d97706;
    --bs-btn-color:        #fff;
    --bs-btn-hover-color:  #fff;
}

.btn-warning:hover { box-shadow: 0 8px 20px -6px rgba(245,158,11,0.4); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    font-weight: 500;
    letter-spacing: 0.02em;
}

.badge.bg-success   { background: rgba(16,185,129,0.18)  !important; color: #6ee7b7  !important; box-shadow: inset 0 0 0 1px rgba(16,185,129,0.25); }
.badge.bg-warning   { background: rgba(251,191,36,0.18)  !important; color: #fcd34d  !important; box-shadow: inset 0 0 0 1px rgba(251,191,36,0.25); }
.badge.bg-danger    { background: rgba(248,113,113,0.18) !important; color: #fca5a5  !important; box-shadow: inset 0 0 0 1px rgba(248,113,113,0.25); }
.badge.bg-info      { background: rgba(56,189,248,0.18)  !important; color: #7dd3fc  !important; box-shadow: inset 0 0 0 1px rgba(56,189,248,0.25); }
.badge.bg-secondary { background: rgba(148,163,184,0.15) !important; color: #94a3b8  !important; }
.badge.bg-primary   { background: rgba(16,185,129,0.18)  !important; color: #6ee7b7  !important; box-shadow: inset 0 0 0 1px rgba(16,185,129,0.25); }
.badge.bg-light     { background: rgba(255,255,255,0.08) !important; color: #94a3b8  !important;
                      border-color: rgba(255,255,255,0.1) !important; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    border-left-width: 3px;
}

.alert-info {
    background: rgba(16,185,129,0.08);
    border-color: rgba(16,185,129,0.25);
    border-left-color: #10b981;
    color: #6ee7b7;
}
.alert-info a { color: #10b981; }

.alert-danger {
    background: rgba(248,113,113,0.1);
    border-color: rgba(248,113,113,0.3);
    border-left-color: #f87171;
    color: #fca5a5;
}

.alert-warning {
    background: rgba(251,191,36,0.1);
    border-color: rgba(251,191,36,0.3);
    border-left-color: #fbbf24;
    color: #fcd34d;
}

.alert-success {
    background: rgba(16,185,129,0.1);
    border-color: rgba(16,185,129,0.3);
    border-left-color: #10b981;
    color: #6ee7b7;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-control, .form-select {
    background: #0f172a;
    border-color: rgba(255,255,255,0.12);
    color: #e2e8f0;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.form-control:focus, .form-select:focus {
    background: #0f172a;
    border-color: #10b981;
    color: #e2e8f0;
    box-shadow: 0 0 0 0.2rem rgba(16,185,129,0.18);
}

.form-control::placeholder { color: #475569; }
.form-select option { background: #1e293b; color: #e2e8f0; }
.form-text  { color: #64748b; }
.form-label { color: #cbd5e1; }

.input-group-text {
    background: #263248;
    border-color: rgba(255,255,255,0.12);
    color: #94a3b8;
}

.form-check-input {
    background-color: #0f172a;
    border-color: rgba(255,255,255,0.2);
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-check-input:checked {
    background-color: #10b981;
    border-color: #10b981;
}

.form-check-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(16,185,129,0.18);
}

.form-check-label { color: #cbd5e1; }

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-content {
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 14px;
    box-shadow: 0 24px 60px -12px rgba(0,0,0,0.6);
}

/* Soft "pop" easing on top of Bootstrap's own show/hide transform transition
   — purely a timing-function change, the .fade/.show classes it reacts to
   are still toggled by Bootstrap's modal JS exactly as before. */
.modal.fade .modal-dialog {
    transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1), opacity 0.25s ease;
}

.modal-backdrop.show {
    opacity: 0.65;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.modal-header {
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding: 1rem 1.25rem;
}

.modal-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
}

.modal-title { color: #f1f5f9; font-weight: 600; }

.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
    opacity: 0.5;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.btn-close:hover { opacity: 0.85; transform: rotate(90deg); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination .page-link {
    border-radius: 6px !important;
    margin: 0 1px;
    font-size: 0.8rem;
    padding: 0.3rem 0.65rem;
    background: #1e293b;
    border-color: rgba(255,255,255,0.1);
    color: #94a3b8;
    transition: all 0.15s ease;
}

.pagination .page-link:hover {
    background: #263248;
    color: #10b981;
    border-color: rgba(16,185,129,0.3);
    transform: translateY(-1px);
}

.pagination .page-item.active .page-link {
    background: var(--brand-grad);
    border-color: #10b981;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 4px 12px -4px var(--brand-glow);
}

.pagination .page-item.disabled .page-link {
    background: #1e293b;
    color: #475569;
    border-color: rgba(255,255,255,0.06);
}

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner-border-sm {
    width: 0.9rem;
    height: 0.9rem;
}

/* ── Text utilities ──────────────────────────────────────────────────────── */
.text-muted     { color: #64748b !important; }
.text-secondary { color: #94a3b8 !important; }

/* ── Border tweaks ───────────────────────────────────────────────────────── */
.border           { border-color: rgba(255,255,255,0.1) !important; }
.border-top       { border-top-color:   rgba(255,255,255,0.08) !important; }
.border-secondary { border-color: rgba(255,255,255,0.08) !important; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar             { width: 7px; height: 7px; }
::-webkit-scrollbar-track       { background: transparent; }
::-webkit-scrollbar-thumb       { background: rgba(255,255,255,0.12); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(16,185,129,0.4); }

/* ── Dialogs split-pane layout ───────────────────────────────────────────── */
.dialogs-layout {
    display: flex;
    gap: 12px;
    height: calc(100vh - 172px);
    min-height: 500px;
}

.dialog-list-pane {
    width: 340px;
    flex-shrink: 0;
    overflow-y: auto;
    background: #1e293b;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.07);
    box-shadow: 0 10px 28px -18px rgba(0,0,0,0.6);
}

.dialog-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    border-left: 3px solid transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    user-select: none;
}

.dialog-item:last-child { border-bottom: none; }
.dialog-item:hover       { background: rgba(255,255,255,0.035); }
.dialog-item.active      { background: rgba(16,185,129,0.1); border-left-color: #10b981; }

/* Whole-chat deletion (2026-09-18) — same red used for the individual
   message-deletion tag/border below, kept visually consistent site-wide. */
.dialog-item.dialog-item-deleted            { border-left-color: #ef4444; background: rgba(239,68,68,0.045); }
.dialog-item.dialog-item-deleted:hover      { background: rgba(239,68,68,0.08); }
.dialog-item.dialog-item-deleted .dialog-name { color: #fca5a5; }
/* Currently-open selection state still wins over the deleted tint. */
.dialog-item.active.dialog-item-deleted     { background: rgba(16,185,129,0.1); border-left-color: #10b981; }

.dialog-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}

.dialog-info { flex: 1; min-width: 0; }

.dialog-name {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #e2e8f0;
}

.dialog-meta  { font-size: 0.75rem; color: #64748b; margin-top: 1px; }
.dialog-time  { font-size: 0.72rem; color: #64748b; white-space: nowrap; flex-shrink: 0; }

.dialog-search-snippet {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dialog-search-snippet mark {
    background: rgba(251,191,36,0.3);
    color: #fbbf24;
    padding: 0 1px;
    border-radius: 2px;
}
.dialog-match-count { color: #64748b; margin-left: 2px; }

/* In-thread search highlight — mark.search-hit-current is the one currently
   scrolled to (via the search-nav prev/next buttons); plain search-hit
   marks every other match in the open dialog. */
mark.search-hit {
    background: rgba(251,191,36,0.55);
    color: #1e293b;
    padding: 0 1px;
    border-radius: 2px;
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
mark.search-hit.search-hit-current {
    background: #fbbf24;
    box-shadow: 0 0 0 2px #f59e0b;
}

.search-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 0.72rem;
    color: #94a3b8;
    background: rgba(255,255,255,0.05);
    padding: 2px 4px 2px 8px;
    border-radius: 6px;
    white-space: nowrap;
}
.search-nav button {
    background: none;
    border: none;
    color: #e2e8f0;
    padding: 2px 5px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.15s ease, background-color 0.15s ease;
}
.search-nav button:hover  { color: #fbbf24; background: rgba(251,191,36,0.12); }
.search-nav button:disabled { color: #475569; cursor: default; background: none; }

.thread-pane {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #1e293b;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.07);
    overflow: hidden;
    box-shadow: 0 10px 28px -18px rgba(0,0,0,0.6);
}

.thread-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #475569;
}

.thread-header {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: rgba(255,255,255,0.02);
}

.dialog-avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(16,185,129,0.15);
    flex-shrink: 0;
}

.thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.msg-date-sep {
    text-align: center;
    font-size: 0.72rem;
    color: #475569;
    background: rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 2px 10px;
    align-self: center;
    margin: 8px 0;
}

/* Deep-link jump target (Critical Links "Go to dialog" button, and any
   future open_message=N link) — a brief flash so the landed-on message is
   obvious, fading back to its normal bubble shadow. */
.msg-bubble.msg-jump-highlight { animation: msgJumpFlash 1.8s ease-out; }
@keyframes msgJumpFlash {
    0%   { box-shadow: 0 0 0 3px #f59e0b; }
    70%  { box-shadow: 0 0 0 3px #f59e0b; }
    100% { box-shadow: 0 1px 2px rgba(0,0,0,0.18); }
}

.msg-row      { display: flex; margin-bottom: 2px; }
.msg-incoming { justify-content: flex-start; }
.msg-outgoing { justify-content: flex-end; }

.msg-bubble {
    max-width: 72%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.18);
}

.msg-incoming .msg-bubble {
    background: #263248;
    border: 1px solid rgba(255,255,255,0.07);
    border-bottom-left-radius: 4px;
    color: #e2e8f0;
}

.msg-outgoing .msg-bubble {
    background: var(--brand-grad);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px -2px var(--brand-glow-soft);
}

.msg-sender { font-size: 0.72rem; font-weight: 600; color: #10b981; margin-bottom: 2px; }
.msg-outgoing .msg-sender { color: rgba(255,255,255,.8); }

.msg-time { font-size: 0.68rem; margin-top: 3px; text-align: right; opacity: 0.5; }

/* Individually-deleted message (2026-09-17) — text/media stays visible
   (already synced before the deletion happened), just flagged. Higher
   selector specificity than .msg-incoming/.msg-outgoing .msg-bubble above
   (3 classes vs 2) so the red border wins on both bubble colors without
   needing !important. */
.msg-row.msg-deleted .msg-bubble { border: 1px solid #ef4444; box-shadow: 0 0 0 1px rgba(239,68,68,0.35), 0 1px 2px rgba(0,0,0,0.18); }
.msg-deleted-tag { display: flex; align-items: center; gap: 4px; font-size: 0.68rem; font-weight: 600; color: #ef4444; margin-top: 4px; letter-spacing: .02em; }
.msg-outgoing .msg-deleted-tag { color: #fecaca; }

/* ── Media: load button / spinner / error / previews ─────────────────────── */
.media-slot { margin-bottom: 4px; }

.media-load-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: inherit;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease;
}
.media-load-btn:hover { background: rgba(255,255,255,0.16); transform: translateY(-1px); }

.media-error {
    font-size: 0.78rem;
    color: #f87171;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

/* Distinct from .media-error: a realtime account's own worker is still
   fetching this file in the background (see media_download.php's 202
   REALTIME_QUEUED response) — not a failure, so it deliberately doesn't use
   the red/warning-triangle treatment above. */
.media-pending {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.65);
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.media-photo, .media-video {
    display: block;
    max-width: 280px;
    max-height: 320px;
    border-radius: 10px;
    object-fit: contain;
    background: rgba(0,0,0,0.15);
    box-shadow: 0 4px 16px -6px rgba(0,0,0,0.4);
}

.media-video-note {
    display: block;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    object-fit: cover;
}

.media-sticker {
    display: block;
    width: 140px;
    height: 140px;
    object-fit: contain;
}

.media-audio { width: 240px; height: 36px; }

.media-file-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 8px 10px;
    color: inherit;
    text-decoration: none;
    max-width: 260px;
    transition: background-color 0.15s ease, transform 0.15s ease;
}
.media-file-card:hover { background: rgba(255,255,255,0.12); color: inherit; transform: translateY(-1px); }
.media-file-card i { font-size: 1.3rem; flex-shrink: 0; }
.media-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.82rem;
}
.media-file-size { font-size: 0.7rem; opacity: 0.7; flex-shrink: 0; margin-left: auto; }

.thread-footer {
    padding: 6px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    background: rgba(255,255,255,0.02);
}

.poll-indicator { display: flex; align-items: center; }

/* ── Analytics inner sidebar ─────────────────────────────────────────────── */
.analytics-nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 7px;
    font-size: .845rem;
    text-decoration: none;
    color: #cbd5e1;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* .analytics-sidebar-card is a Bootstrap .card — display:flex,
       flex-direction:column by default — capped with max-height +
       overflow-y:auto so a long group/account list scrolls instead of
       pushing the page taller. Without flex-shrink:0, flex's default
       shrink-to-fit kicks in once the rows' combined natural height
       exceeds that max-height: instead of overflowing and scrolling, every
       row gets uniformly squashed down to a sliver (padding included),
       which is what made the picker look "too narrow" — not an actual
       padding/font-size problem. */
    flex-shrink: 0;
}

.analytics-nav-item:hover  { background: rgba(16,185,129,0.08); color: #10b981; transform: translateX(2px); }
.analytics-nav-item.active { background: rgba(16,185,129,0.14); color: #10b981 !important; font-weight: 500; }
.analytics-nav-item.active .text-muted { color: rgba(16,185,129,.55) !important; }

.analytics-nav-sub {
    font-size: .8rem;
    padding: 5px 10px 5px 30px;
    color: #64748b;
    flex-shrink: 0;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.analytics-nav-sub:hover  { background: rgba(16,185,129,0.05); color: #10b981; }
.analytics-nav-sub.active { background: rgba(16,185,129,0.1);  color: #10b981; font-weight: 500; }

/* "Full acc (+N)" toggle (2026-09-04) — a <button> reusing .analytics-nav-item/
   .analytics-nav-sub's layout, reset to look like the plain nav rows around
   it instead of a default button. */
.analytics-nav-toggle {
    width: 100%;
    border: 0;
    background: none;
    text-align: left;
    font: inherit;
    font-style: italic;
    opacity: .85;
}
.analytics-nav-toggle .chevron { transition: transform 0.15s ease; }
.analytics-nav-toggle.expanded .chevron { transform: rotate(90deg); }

/* ── Analytics grouped KPI cards ─────────────────────────────────────────── */
.kpi-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}

.kpi-card-title {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #64748b;
    font-weight: 700;
}

.kpi-big-value {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1;
    color: #f8fafc;
    letter-spacing: -0.03em;
}

.kpi-stat-row {
    display: flex;
    gap: 0;
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 1.25rem;
    padding-top: 1.25rem;
}

.kpi-stat-item {
    flex: 1;
    padding: 0 0.9rem;
    border-right: 1px solid rgba(255,255,255,0.06);
    min-width: 0;
}

.kpi-stat-item:first-child { padding-left: 0; }
.kpi-stat-item:last-child  { padding-right: 0; border-right: none; }

/* Money values (e.g. "$1,234.00") run longer than plain counts/percentages —
   give that item extra room so it doesn't wrap while its neighbors don't,
   which otherwise throws off the whole row's label alignment. */
.kpi-stat-item--wide { flex: 1.6; }

/* A card's second stat row (2026-11-27): lighter dashed divider, less air. Blank cells keep its
   columns the same width as the row above; the cell before the first blank loses its divider. */
.kpi-stat-row--second { margin-top: 1rem; padding-top: 1rem; border-top-style: dashed; }
.kpi-stat-item--blank { visibility: hidden; }
.kpi-stat-item:has(+ .kpi-stat-item--blank) { border-right: none; }

.kpi-stat-value {
    font-size: 1.05rem;
    font-weight: 600;
    color: #e2e8f0;
    white-space: normal;
    overflow-wrap: break-word;
}

.kpi-stat-label {
    font-size: 0.68rem;
    color: #64748b;
    margin-top: 3px;
    line-height: 1.35;
    white-space: normal;
}

.kpi-footer-row {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-top: 1rem;
    padding-top: 0.9rem;
    border-top: 1px solid rgba(255,255,255,0.06);
    font-size: 0.78rem;
    color: #64748b;
}

.kpi-footer-row .kpi-footer-val {
    font-weight: 600;
    color: #94a3b8;
    margin-left: 4px;
}

/* Standalone metric called out on its own row within a KPI card — e.g. FTD
   Keyword under the FTD card — deliberately louder than kpi-stat-row items
   so it stays legible at a glance. */
.kpi-highlight-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1rem;
    padding: 0.65rem 0.9rem;
    border-radius: 10px;
    background: rgba(251,191,36,0.1);
    border: 1px solid rgba(251,191,36,0.25);
}

.kpi-highlight-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #fbbf24;
    font-weight: 700;
}

.kpi-highlight-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #fbbf24;
    line-height: 1;
}

/* ── FTD Deposits filter bar (2026-09-04 redesign) ────────────────────────── */
.ftd-filter-card {
    background: linear-gradient(180deg, rgba(16,185,129,0.05) 0%, transparent 40%), #1e293b;
}
.ftd-filter-card .card-header { font-size: 0.8rem; }
.ftd-filter-count { font-size: 0.65rem; font-weight: 600; letter-spacing: 0.02em; }

.ftd-filter-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    font-weight: 600;
    margin-bottom: 0.35rem;
}
.ftd-filter-label i { color: #10b981; font-size: 0.8rem; }

/* Chrome/Edge render a native date input's picker-indicator + internal
   segments as if the page were light-themed unless told otherwise — on
   this dark input background that made the calendar icon barely visible. */
.ftd-filter-card input[type="date"] { color-scheme: dark; }

/* ── FTD screenshot thumbnail ────────────────────────────────────────────── */
.ftd-thumb {
    width: 48px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.ftd-thumb:hover { opacity: 0.85; transform: scale(1.06); }

/* ── FTD inline field editing (click-to-edit pencil per cell) ────────────── */
/* Keeps the value + pencil on one line regardless of column width — without
   this, a narrow column (Date, Amount) wraps the pencil onto its own line
   while a wider one (Country, Brand) doesn't, so the icons end up sitting
   at different heights row to row instead of all lining up. */
.ftd-cell-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.ftd-edit-icon {
    cursor: pointer;
    color: #64748b;
    font-size: .78rem;
    vertical-align: middle;
    transition: color 0.15s ease;
    flex-shrink: 0;
}
.ftd-edit-icon:hover { color: #10b981; }
/* A bare max-width with no width/min-width let the input collapse to the
   browser's tiny intrinsic size (worst on number/date inputs) once it sat
   inside a flex row in a narrow column like Amount — barely wide enough to
   show one digit. An explicit width fixes the size regardless of the
   column's own auto-computed width; flex-shrink:0 stops the surrounding
   d-flex row from squeezing it back down to fit a narrow cell (the table
   simply widens that column instead, same as it already does for any other
   wide cell content). */
.ftd-edit-input {
    width: 140px;
    flex-shrink: 0;
}
select.ftd-edit-input { width: 160px; }

/* ── Settings modal panels (Account Settings) ─────────────────────────────── */
.settings-panel {
    background: rgba(255,255,255,0.025);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    padding: 1rem 1.15rem;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.settings-panel:hover {
    border-color: rgba(255,255,255,0.12);
}

/* Standalone (not paired with .settings-panel) — deliberately much lower-key
   than the other panels since it's a rare, destructive action that
   shouldn't compete visually with everyday settings. */
.settings-panel-danger {
    background: rgba(248,113,113,0.05);
    border: 1px solid rgba(248,113,113,0.22);
    border-radius: 10px;
    padding: 0.5rem 0.85rem;
    transition: border-color 0.2s ease;
}

.settings-panel-danger:hover {
    border-color: rgba(248,113,113,0.35);
}

.settings-danger-btn {
    padding: 0.2rem 0.55rem;
    font-size: 0.74rem;
}

.settings-panel-head {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    margin-bottom: 0.85rem;
}

.settings-panel-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: #e2e8f0;
}

.settings-panel-desc {
    font-size: 0.76rem;
    color: #64748b;
    margin-top: 2px;
    line-height: 1.4;
}

/* ── Account Groups: section-header rows inline in the accounts table
   (web/pages/accounts.php) — one per group (alphabetical), plus a trailing
   "Without group" row for ungrouped accounts ─────────────────────────────── */
.group-row-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(16,185,129,0.12);
    color: #10b981;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.account-group-section-row td {
    background: rgba(255,255,255,0.03);
    border-top: 1px solid rgba(255,255,255,0.08);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
}

.account-group-section-row-inactive td {
    background: rgba(255,255,255,0.015);
}

/* ── Dropdowns (Bootstrap component) — themed to match the app rather than
   relying only on Bootstrap's built-in data-bs-theme dark defaults ──────── */
.dropdown-menu {
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    box-shadow: 0 20px 45px -12px rgba(0,0,0,0.55);
    padding: 0.4rem;
}

.dropdown-item {
    border-radius: 7px;
    color: #cbd5e1;
    font-size: 0.85rem;
    padding: 0.45rem 0.7rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: rgba(16,185,129,0.1);
    color: #10b981;
}

.dropdown-item.active,
.dropdown-item:active {
    background: rgba(16,185,129,0.16) !important;
    color: #10b981 !important;
}


/* ── Dialogs page: account switcher (replaces a native <select>, which
   browsers render as an unstyleable OS popup regardless of CSS — a
   Bootstrap dropdown is fully themeable instead) ─────────────────────────── */
.account-switcher-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 220px;
}

.account-switcher-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-switcher-menu {
    min-width: 270px;
    max-width: 320px;
    overflow: hidden;
    padding: 0;
}

.account-switcher-menu .p-2.border-bottom {
    border-color: rgba(255,255,255,0.07) !important;
}

.account-switcher-list {
    max-height: 320px;
    overflow-y: auto;
    padding: 0.4rem;
}

.account-switcher-item {
    border-radius: 7px;
}

/* ── Pretty-select (generic native-<select> facade, see pretty-select.js) ── */
.pretty-select-btn {
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    vertical-align: middle;
}

.pretty-select-menu {
    min-width: 220px;
    max-width: 300px;
    overflow: hidden;
}

.pretty-select-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 0.4rem;
}

.pretty-select-item {
    border-radius: 7px;
    font-size: 0.85rem;
}

/* fullWidth option (2026-09-10, see pretty-select.js) — the trigger button
   fills whatever column it sits in instead of shrinking to its own text,
   matching plain .form-select fields stacked in the same filter panel. */
.pretty-select--full .pretty-select-btn { width: 100%; max-width: none; }

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE & TABLET
   ══════════════════════════════════════════════════════════════════════════ */

/* Mobile top bar (hidden on desktop) */
.mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 100;
    background: #080e1d;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding: 0.6rem 1rem;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}
/* Admin pages only — sticks right below .app-topbar instead of under it. */
/* Deliberately top:0, not var(--topbar-h) (2026-10-06, user report — real
   bug, confirmed with Chrome's own DevTools Protocol via getBoundingClientRect,
   not guessed): .mobile-topbar is a plain block-level child (inside
   .main-wrapper), not a direct flex item like .sidebar is — for that kind
   of child, a sticky element's own "top" offset stacks ON TOP of the
   position body's own padding-top already gives it, instead of being
   absorbed by it, so top:46px rendered it a second 46px lower than the
   fixed .app-topbar's bottom edge (confirmed: top:0 renders flush at
   exactly 46px AND still correctly stays pinned there on scroll — the
   body padding-top above already supplies all the clearance a flex-item
   sibling like .sidebar needs var(--topbar-h) here for; a plain block
   child needs zero on top of that). .sidebar's own identical-looking
   override (being a flex item) does NOT have this problem — verified
   separately, left exactly as is. */
body.has-app-topbar .mobile-topbar {
    top: 0;
}

/* Sidebar overlay (mobile, hidden by default) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 190;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.sidebar-overlay.is-open { display: block; }

/* ── Tablet: tighten KPI values ─────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .kpi-big-value { font-size: 1.8rem; }
    .kpi-stat-value { font-size: 1rem; }
}

/* ── Narrow desktop/laptop: side-by-side cards (col-lg-6) get plenty tight
   here, even though there's technically room above 991.98px — wrap the FTD
   card's 5 stat items into a 2-column grid instead of squeezing them (and
   overflowing) into one row. ─────────────────────────────────────────────── */
@media (min-width: 992px) and (max-width: 1399.98px) {
    .kpi-stat-row { flex-wrap: wrap; }
    .kpi-stat-item, .kpi-stat-item--wide {
        flex: 1 1 calc(50% - 1px);
        min-width: 0;
        padding: 0.5rem 0.6rem;
        border-bottom: 1px solid rgba(255,255,255,0.06);
    }
    .kpi-stat-item:nth-child(odd)  { padding-left: 0; }
    .kpi-stat-item:nth-child(even) { border-right: none; }
    .kpi-stat-item:last-child                       { border-bottom: none; }
    .kpi-stat-item:nth-last-child(2):nth-child(odd) { border-bottom: none; }
}

/* ── Sidebar collapses to a burger/drawer starting at tablet width, not
   just true mobile (2026-10-06, user report: an in-between window size —
   narrower laptop, tablet, a split-screen browser — kept the full 220px
   fixed sidebar with no way to collapse it, so wide content, e.g. the
   Links page's long tracking URLs, had nowhere left to shrink into and
   stopped fitting correctly). 991.98px matches Bootstrap's own lg
   breakpoint, same one the KPI-card rules just above already treat as
   "narrow desktop" — the sidebar now collapses at the same point those
   already do, rather than nearly 200px later. Only the drawer mechanics
   move here; everything genuinely phone-specific (dialogs full-screen
   panes, stacked analytics layout, etc.) stays at 767.98px below, since
   there's still plenty of room for those at tablet width. ───────────────── */
@media (max-width: 991.98px) {

    /* Show mobile topbar */
    .mobile-topbar { display: flex; }

    /* Sidebar becomes a slide-in drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 200;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
    }
    .sidebar.is-open {
        transform: translateX(0);
        box-shadow: 6px 0 40px rgba(0,0,0,0.6);
    }
    /* Admin pages only — drawer starts below .app-topbar, not under it. */
    body.has-app-topbar .sidebar {
        top: var(--topbar-h);
        height: calc(100% - var(--topbar-h));
    }

    /* Full-width main content */
    .main-wrapper { min-width: 0; }

    /* Reduce page padding */
    .main-wrapper > .p-4 { padding: 0.75rem !important; }
}

/* ── Mobile only (< 768px) ───────────────────────────────────────────────── */
@media (max-width: 767.98px) {

    /* Workspace switcher: icons only (2026-10-06, user report) — at true
       phone width the bar was just overflowing with .app-topbar's own
       overflow-x:auto, cutting tab labels off mid-word ("Task Ma…") with
       no visual hint there was more to scroll to. Four icon-only tabs fit
       one phone-width row with room to spare, so there's nothing left to
       scroll at all. Tablet/narrow-laptop widths (768-991.98px) keep the
       text labels — there's enough room there. */
    .app-topbar-tab span { display: none; }
    .app-topbar-tab { padding: 0.4rem 0.6rem; }

    /* Card body padding */
    .card-body.p-4 { padding: 1.1rem !important; }

    /* KPI big value */
    .kpi-big-value { font-size: 1.55rem; }
    .kpi-stat-value { font-size: 1rem; }

    /* KPI stat row: 2-column wrap */
    .kpi-stat-row { flex-wrap: wrap; padding-top: 0.9rem; margin-top: 0.9rem; }
    .kpi-stat-item {
        flex: 1 1 calc(50% - 1px);
        min-width: 0;
        padding: 0.5rem 0.6rem;
        border-right: 1px solid rgba(255,255,255,0.06);
        border-bottom: 1px solid rgba(255,255,255,0.06);
    }
    .kpi-stat-item:first-child { padding-left: 0; }
    .kpi-stat-item:nth-child(even)  { border-right: none; }
    .kpi-stat-item:last-child       { border-bottom: none; }
    .kpi-stat-item:nth-last-child(2):nth-child(odd) { border-bottom: none; }

    /* KPI footer row */
    .kpi-footer-row { flex-wrap: wrap; gap: 0.5rem 1rem; }

    /* Tables: horizontal scroll */
    .card-body > .table,
    .card-body > table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-responsive { -webkit-overflow-scrolling: touch; }

    /* Dialogs: full-screen panels */
    .dialogs-layout {
        flex-direction: column;
        height: auto;
        min-height: auto;
        gap: 0;
    }
    .dialog-list-pane {
        width: 100%;
        height: calc(100svh - 195px);
        border-radius: 12px;
    }
    .dialog-list-pane.mobile-hidden { display: none; }

    /* Thread pane: fixed fullscreen on mobile */
    .thread-pane {
        position: fixed;
        inset: 0;
        z-index: 150;
        border-radius: 0;
        height: 100%;
        display: none;
    }
    .thread-pane.mobile-visible { display: flex; }
    /* Admin pages only — fullscreen thread view starts below .app-topbar
       instead of underneath it. */
    body.has-app-topbar .thread-pane {
        top: var(--topbar-h);
        height: calc(100% - var(--topbar-h));
    }
    .thread-messages { background: #0f172a; }

    /* Analytics: stack sidebar above content.
       align-items-start (set on this element for the desktop row layout,
       where it only affects vertical alignment) becomes load-bearing once
       flex-direction flips to column here — the cross axis is now
       horizontal, so "start" stops children from stretching to the
       container's width and each one shrinks to its own widest unbreakable
       content instead. That silently overflowed every KPI card off the
       right edge of the viewport (big value included) with no visible
       scrollbar, because an ancestor clips overflow-x. Stretch restores the
       intended "full width, stacked" mobile layout. */
    .analytics-layout { flex-direction: column !important; align-items: stretch !important; }
    .analytics-sidebar-card {
        width: 100% !important;
        position: static !important;
        max-height: 260px !important;
        overflow-y: auto;
    }

    /* Dialogs page header: stack on small screens */
    .dialogs-header { flex-direction: column; align-items: stretch !important; }
    .dialogs-header > * { width: 100%; }
    .dialogs-header form { justify-content: stretch; }
    .dialogs-header .ms-auto { margin-left: 0 !important; }

    /* Hide less important table columns */
    .table-mobile-hide { display: none; }

    /* Accounts page: collapse action buttons to icon-only on small screens */
    .btn-settings-label { display: none; }

    /* Analytics page filters: stack on mobile */
    #filterForm { flex-direction: column !important; align-items: stretch !important; }
    #filterForm .btn, #filterForm input[type="date"] { width: 100%; }

    /* FTD filters: stack on mobile */
    .ftd-filters .row > div { margin-bottom: 0.4rem; }

    /* Settings modal: full-screen on mobile */
    #settingsModal .modal-dialog { margin: 0; max-width: 100%; }
    #settingsModal .modal-content { border-radius: 0; min-height: 100vh; }
}

/* ── Respect reduced-motion preference ────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Переключатель рабочих пространств в рейке (2026-10-22) ───────────────
   Пришёл на смену фиксированной .app-topbar. Её правила ниже по файлу
   намеренно оставлены нетронутыми и просто перестали с чем-либо
   совпадать: если шапку когда-нибудь захотят вернуть, это правка одного
   шаблона, а не раскопки в CSS.
   Зелёный у активной кнопки — тот же --brand-grad, что у активного пункта
   меню под ней, чтобы «где я сейчас» читалось одним цветом по всей рейке. */
.ws-switch {
    display: flex;
    gap: 3px;
    padding: 3px;
    margin: 0 0 12px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--line, rgba(255, 255, 255, 0.08));
    border-radius: 9px;
}
.ws-item {
    /* flex-basis: 0 — чтобы обе кнопки были равной ширины независимо от
       длины слова, иначе «Tasks» оказался бы шире «CRM». */
    flex: 1 1 0;
    min-width: 0;
    padding: 7px 4px;
    border-radius: 6px;
    text-align: center;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.55);
    transition: background .15s ease, color .15s ease;
}
.ws-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.85);
}
.ws-item--on,
.ws-item--on:hover {
    background: var(--brand-grad);
    color: #04150d;
    font-weight: 700;
    box-shadow: 0 4px 14px -6px var(--brand-glow);
}

/* ── Users modal: per-section scope list (2026-10-29) ──────────────────────
   A plain indented list under its pages — no panel, no border, no fill —
   the same nesting prod's modal uses for its Bot & Channel / Tracking
   children (user request: "не нужно делать как отдельные блоки"). It was a
   recessed panel for a day; the user found it heavier than the thing it
   held. */
.scope-wrap .form-check-label { font-size: inherit; }

/* The read/write pair on a page row. Deliberately quiet until it matters:
   grey while 'read', emerald once someone is actually given write. */
.access-mode .btn {
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--bs-secondary-color);
    font-weight: 500;
    letter-spacing: .02em;
}
.access-mode .btn-check:checked + .btn {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.16);
    color: var(--bs-body-color);
}
.access-mode .btn-check[value="write"]:checked + .btn {
    background: var(--brand-glow-soft);
    border-color: var(--brand-glow);
    color: #6ee7b7;
}

/* ── Links page (2026-10-29, redesign after the user's mockup) ───────────
   Scoped under lk-* so nothing else in the app picks it up. One card holds
   tabs + table; rows are tall enough to carry a type tile and an avatar but
   no taller, and every secondary control (pencil, gear) appears on hover so
   eighty rows do not read as a wall of buttons. ─────────────────────────── */
.lk-head {
    display: flex; justify-content: space-between; align-items: flex-start;
    flex-wrap: wrap; gap: 1rem; margin-bottom: 1.25rem;
}
.lk-title {
    font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em;
    margin: 0; display: flex; align-items: center; gap: .6rem;
}
.lk-count {
    font-size: .8rem; font-weight: 600; color: #cbd5e1;
    background: rgba(255,255,255,.07); border-radius: 999px; padding: .15rem .6rem;
}
.lk-sub { margin: .3rem 0 0; color: #94a3b8; font-size: .9rem; }
.lk-head-right { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.lk-synced { display: inline-flex; align-items: center; gap: .45rem; color: #94a3b8; font-size: .78rem; margin-right: .4rem; }

.lk-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #64748b; flex-shrink: 0; }
.lk-dot.is-ok   { background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,.18); }
.lk-dot.is-warn { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,.18); }
.lk-dot.is-off  { background: #64748b; }

.lk-btn {
    display: inline-flex; align-items: center; gap: .4rem;
    height: 38px; padding: 0 .9rem; border-radius: 10px;
    background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.1);
    color: #e2e8f0; font-size: .82rem; font-weight: 500; text-decoration: none;
    transition: background .12s ease, border-color .12s ease;
}
.lk-btn:hover { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.18); color: #fff; }
.lk-btn.is-primary { background: var(--brand-grad); border-color: transparent; color: #fff; font-weight: 600; box-shadow: 0 4px 14px var(--brand-glow-soft); }
.lk-btn.is-primary:hover { background: var(--brand-grad-hover); }
.lk-btn.is-sm { height: 28px; padding: 0 .65rem; font-size: .74rem; border-radius: 8px; }

.lk-search {
    position: relative; max-width: 640px; margin-bottom: .9rem;
}
.lk-search > .bi-search { position: absolute; left: .95rem; top: 50%; transform: translateY(-50%); color: #64748b; }
.lk-search input {
    width: 100%; height: 44px; padding: 0 3.4rem 0 2.6rem; border-radius: 12px;
    background: rgba(2,6,23,.45); border: 1px solid rgba(255,255,255,.1); color: #e2e8f0; font-size: .9rem;
}
.lk-search input::placeholder { color: #64748b; }
.lk-search input:focus { outline: none; border-color: var(--brand-glow); box-shadow: 0 0 0 3px var(--brand-glow-soft); }
.lk-kbd {
    position: absolute; right: .8rem; top: 50%; transform: translateY(-50%);
    font-size: .68rem; color: #64748b; background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.08); border-radius: 6px; padding: .1rem .4rem;
}

.lk-filters { display: flex; align-items: flex-end; flex-wrap: wrap; gap: .6rem; margin-bottom: 1.25rem; }
.lk-field { display: flex; flex-direction: column; gap: .3rem; margin: 0; }
.lk-field > span { font-size: .72rem; color: #94a3b8; }
.lk-field .form-select, .lk-field .form-control { height: 38px; border-radius: 10px; min-width: 170px; }

/* The card: tabs on top, then the table. */
.lk-card {
    background: #131c2e; border: 1px solid rgba(255,255,255,.07);
    border-radius: 16px; overflow: hidden;
}
.lk-tabs {
    display: flex; align-items: stretch; gap: .25rem; padding: 0 1rem;
    border-bottom: 1px solid rgba(255,255,255,.07);
}
.lk-tab {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .95rem .8rem; background: none; border: 0; border-bottom: 2px solid transparent;
    color: #94a3b8; font-size: .9rem; font-weight: 500; text-decoration: none; margin-bottom: -1px;
}
.lk-tab:hover { color: #e2e8f0; }
.lk-tab.is-active { color: #34d399; border-bottom-color: #10b981; font-weight: 600; }
.lk-tab-n {
    font-size: .7rem; font-weight: 600; color: #cbd5e1;
    background: rgba(255,255,255,.07); border-radius: 999px; padding: .05rem .45rem;
}

#linksTable { border-collapse: separate; border-spacing: 0; }
#linksTable > thead th {
    background: rgba(2,6,23,.35); border-bottom: 1px solid rgba(255,255,255,.07);
    text-transform: uppercase; letter-spacing: .06em; font-size: .68rem; font-weight: 600;
    color: #94a3b8; padding: .75rem 1rem; white-space: nowrap;
}
#linksTable tr.links-row > td {
    border-top: 1px solid rgba(255,255,255,.05);
    padding: .75rem 1rem; vertical-align: middle; background: transparent;
}
#linksTable tbody tr.links-row:first-child > td { border-top: 0; }
#linksTable tr.links-row:hover > td { background: rgba(255,255,255,.025); }

/* Domain / link */
.lk-link { display: flex; align-items: center; gap: .85rem; }
.lk-tile {
    width: 52px; height: 52px; flex-shrink: 0; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 1.35rem; color: #fff;
    background:
        radial-gradient(circle at 30% 25%, hsla(var(--h), 85%, 62%, .55), transparent 60%),
        linear-gradient(135deg, hsl(var(--h), 55%, 26%), hsl(calc(var(--h) + 40), 60%, 14%));
    border: 1px solid rgba(255,255,255,.1);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}
.lk-link-text { min-width: 0; }
.lk-path { font-size: .95rem; font-weight: 600; line-height: 1.3; display: flex; align-items: center; flex-wrap: wrap; gap: .35rem; }
.lk-host { color: #f1f5f9; }
.lk-folder { color: #34d399; margin-left: -.35rem; }
.lk-pill {
    font-size: .66rem; font-weight: 600; color: #cbd5e1;
    background: rgba(255,255,255,.08); border-radius: 999px; padding: 0 .4rem; line-height: 1.5;
}
.lk-chip-btn {
    display: inline-flex; align-items: center; gap: .25rem; margin-top: .35rem;
    font-size: .68rem; font-weight: 600; color: #34d399;
    background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.25);
    border-radius: 999px; padding: .1rem .55rem;
}
.lk-chip-btn:hover { background: rgba(16,185,129,.2); }
.lk-url-full code {
    display: block; margin-top: .4rem; padding: .45rem .55rem; border-radius: 8px;
    background: rgba(2,6,23,.6); color: #7dabf8; font-size: .68rem; line-height: 1.45; max-width: 420px;
}

/* Manager */
.lk-mgr { display: flex; align-items: center; gap: .6rem; }
.lk-ava {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; object-fit: cover;
    border: 1px solid rgba(255,255,255,.1);
}
.lk-ava.is-letter {
    display: inline-flex; align-items: center; justify-content: center;
    background: #1e293b; color: #e2e8f0; font-weight: 700; font-size: .85rem;
}
.lk-mgr-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.lk-mgr-name { font-weight: 500; color: #f1f5f9; }
.lk-muted { color: #64748b; font-size: .74rem; }
.lk-pin { color: #34d399; font-size: .8rem; text-decoration: none; }
.lk-pin:hover { color: #6ee7b7; }

/* Pixels */
.lk-pixels { display: flex; align-items: flex-start; gap: .4rem; }
.lk-pixel {
    display: inline-block; margin-bottom: .2rem; padding: .1rem .5rem; border-radius: 7px;
    background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08);
    color: #e2e8f0; font-family: var(--bs-font-monospace); font-size: .74rem; letter-spacing: .02em;
}
.lk-pixel-src { font-size: .7rem; color: #94a3b8; }
.lk-pixel-src.is-own { color: #38bdf8; }

/* Buyer */
.lk-buyer { display: flex; align-items: center; gap: .45rem; color: #e2e8f0; white-space: nowrap; }

/* Status */
.lk-status { display: inline-flex; align-items: center; gap: .45rem; font-size: .85rem; font-weight: 500; }
.lk-status.is-active   { color: #34d399; } .lk-status.is-active   .lk-dot { background: #10b981; }
.lk-status.is-nopixel  { color: #fbbf24; } .lk-status.is-nopixel  .lk-dot { background: #f59e0b; }
.lk-status.is-unbound  { color: #f87171; } .lk-status.is-unbound  .lk-dot { background: #ef4444; }
.lk-status.is-archived { color: #94a3b8; } .lk-status.is-archived .lk-dot { background: #64748b; }
.lk-status.is-down     { color: #f87171; } .lk-status.is-down     .lk-dot { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.2); }
.lk-status.is-broken   { color: #fb923c; } .lk-status.is-broken   .lk-dot { background: #f97316; }
.lk-status.is-deaddest { color: #f87171; } .lk-status.is-deaddest .lk-dot { background: #ef4444; }
.lk-status.is-unchecked{ color: #94a3b8; } .lk-status.is-unchecked .lk-dot { background: transparent; border: 1px solid #64748b; }
.lk-status-note { font-size: .68rem; color: #64748b; margin-top: .15rem; white-space: nowrap; }

/* Row actions: always visible, as in the mockup — they are the three
   things people come here to do. The pencils and the gear stay quiet. */
.lk-act {
    width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 9px; border: 1px solid rgba(255,255,255,.1); background: rgba(255,255,255,.03);
    color: #cbd5e1; font-size: .9rem; margin-left: .3rem;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.lk-act:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.2); color: #fff; }
.lk-act.link-copy-btn:hover { color: #6ee7b7; border-color: var(--brand-glow); background: var(--brand-glow-soft); }

.lk-icon {
    width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 6px; border: 1px solid transparent; background: transparent; color: #94a3b8; font-size: .78rem;
}
.lk-icon:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.14); color: #e2e8f0; }

.links-ghost { opacity: 0; transition: opacity .12s ease; }
#linksTable tr.links-row:hover .links-ghost,
#linksTable tr.links-row:focus-within .links-ghost { opacity: 1; }
@media (hover: none) { .links-ghost { opacity: 1; } }

.lk-empty { padding: 2rem; text-align: center; color: #64748b; }

/* TG Bots: the row a deep link (?page=tgbots&bot=<id>) landed on. */
tr.bot-row-target > td {
    background: var(--brand-glow-soft) !important;
    transition: background 1.2s ease;
}

/* Active Dialogs: Link / Reg / FTD headers double as filters (2026-10-29) */
#active-table th.attr-filter { cursor: pointer; user-select: none; white-space: nowrap; transition: color .15s; }
#active-table th.attr-filter:hover { color: #198754; }
#active-table th.attr-filter:focus-visible { outline: 2px solid #198754; outline-offset: -2px; }
#active-table th.attr-filter.is-active { color: #198754; }
#active-table th.attr-filter.is-active::before {
    content: ''; display: inline-block; width: .45rem; height: .45rem; border-radius: 50%;
    background: #198754; margin-right: .3rem; vertical-align: middle;
}

/* Dialogs: search phrase response rate (2026-10-29) */
.phrase-stats { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: .25rem .6rem; font-size: .85rem; margin: -.35rem 0 .75rem; }
.phrase-stats .ps-sep { color: var(--bs-secondary-color, #6c757d); }
.phrase-stats .ps-rate b { font-variant-numeric: tabular-nums; }
.phrase-stats .ps-rate.is-good { color: #198754; }
.phrase-stats .ps-rate.is-mid  { color: #d39e00; }
.phrase-stats .ps-rate.is-low  { color: #dc3545; }
.phrase-stats .ps-detail { color: var(--bs-secondary-color, #6c757d); font-size: .8rem; }
.phrase-stats .ps-detail b, .phrase-stats .ps-found b { font-variant-numeric: tabular-nums; }
