/**
 * Product Design System — white-label ERP suite
 * =============================================
 * Written for a product that gets resold under someone else's name, so
 * NOTHING here hardcodes a brand colour. Every accent resolves through
 * --tbf-primary / --tbf-accent / --tbf-sidebar, which includes/header.php
 * fills from agency_settings. Change those two hex values in Corporate
 * Branding and the entire suite re-themes — buttons, tabs, chips, focus
 * rings, avatars, charts — with no CSS edit and no per-client build.
 *
 * The neutrals (ink, surface, line) are deliberately NOT themable: they
 * carry the professional, enterprise feel that has to survive whatever
 * colour a reseller picks. A client choosing a loud primary still gets a
 * calm product around it.
 *
 * Scoped under .tbf-suite so it can be adopted screen by screen without
 * disturbing pages still on the old Bootstrap look.
 */

:root {
    /* Themable (set per install from agency_settings, see header.php) */
    --tbf-primary: #1d4ed8;
    --tbf-primary-dark: #1e3a8a;
    --tbf-accent: #0ea5e9;
    --tbf-sidebar: #0f172a;

    /* Fixed product neutrals */
    --tbf-ink: #0f172a;
    --tbf-ink-2: #334155;
    --tbf-muted: #64748b;
    --tbf-faint: #94a3b8;
    --tbf-line: #e2e8f0;
    --tbf-line-soft: #eef2f7;
    --tbf-surface: #ffffff;
    --tbf-canvas: #f5f7fa;
    --tbf-raised: #f8fafc;

    /* Status — semantic, never themable (green must stay "good") */
    --tbf-success: #15803d;
    --tbf-success-bg: #dcfce7;
    --tbf-warning: #b45309;
    --tbf-warning-bg: #fef3c7;
    --tbf-danger: #b91c1c;
    --tbf-danger-bg: #fee2e2;
    --tbf-info-bg: #e0f2fe;

    --tbf-radius: 12px;
    --tbf-radius-sm: 8px;
    --tbf-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .06);
    --tbf-shadow-lg: 0 8px 30px rgba(15, 23, 42, .10);
}

/* ---------------------------------------------------------------- shell */
.tbf-suite {
    color: var(--tbf-ink);
    font-size: .875rem;
}
.tbf-suite h1, .tbf-suite h2, .tbf-suite h3,
.tbf-suite h4, .tbf-suite h5, .tbf-suite h6 { letter-spacing: -.01em; }

.tbf-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.tbf-page-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}
.tbf-page-sub {
    color: var(--tbf-muted);
    font-size: .82rem;
    margin: .25rem 0 0;
    max-width: 68ch;
}

/* Brand mark — initial block that picks up the install's own colour */
.tbf-brandmark {
    width: 42px; height: 42px;
    border-radius: 11px;
    display: grid; place-items: center;
    color: var(--tbf-on-primary, #fff); font-weight: 700; font-size: 1.05rem;
    background: linear-gradient(135deg, var(--tbf-primary), var(--tbf-accent));
    box-shadow: var(--tbf-shadow);
    flex: 0 0 auto;
}

/* ----------------------------------------------------------------- card */
.tbf-card {
    background: var(--tbf-surface);
    border: 1px solid var(--tbf-line);
    border-radius: var(--tbf-radius);
    box-shadow: var(--tbf-shadow);
}
.tbf-card-head {
    padding: .9rem 1.1rem;
    border-bottom: 1px solid var(--tbf-line-soft);
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
}
.tbf-card-title { font-size: .9rem; font-weight: 700; margin: 0; }
.tbf-card-sub { font-size: .76rem; color: var(--tbf-muted); margin: .15rem 0 0; }
.tbf-card-body { padding: 1.1rem; }
.tbf-card-body.tight { padding: .75rem 1.1rem; }

/* ------------------------------------------------------------ stat tile */
.tbf-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.tbf-stat {
    background: var(--tbf-surface);
    border: 1px solid var(--tbf-line);
    border-radius: var(--tbf-radius);
    padding: .85rem .95rem;
    position: relative;
    overflow: hidden;
}
.tbf-stat::after {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
    background: var(--tbf-primary); opacity: .85;
}
.tbf-stat.is-warning::after { background: var(--tbf-warning); }
.tbf-stat.is-success::after { background: var(--tbf-success); }
.tbf-stat.is-danger::after  { background: var(--tbf-danger); }
.tbf-stat-label {
    font-size: .67rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--tbf-muted); font-weight: 600; margin-bottom: .3rem;
}
.tbf-stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.tbf-stat-foot { font-size: .72rem; color: var(--tbf-faint); margin-top: .3rem; }

/* ----------------------------------------------------------------- tabs */
.tbf-tabs {
    display: flex; gap: .25rem; flex-wrap: wrap;
    border-bottom: 1px solid var(--tbf-line);
    margin-bottom: 1.1rem;
}
.tbf-tab {
    appearance: none; background: none; border: 0;
    border-bottom: 2px solid transparent;
    padding: .6rem .9rem;
    font-size: .82rem; font-weight: 600; color: var(--tbf-muted);
    border-radius: var(--tbf-radius-sm) var(--tbf-radius-sm) 0 0;
    transition: color .15s, background .15s, border-color .15s;
    white-space: nowrap;
}
.tbf-tab:hover { color: var(--tbf-ink); background: var(--tbf-raised); }
.tbf-tab.active { color: var(--tbf-primary); border-bottom-color: var(--tbf-primary); }
.tbf-tab .tbf-tab-count {
    display: inline-block; margin-left: .35rem; padding: 0 .38rem;
    font-size: .68rem; border-radius: 999px;
    background: var(--tbf-line-soft); color: var(--tbf-ink-2);
}
.tbf-tab.active .tbf-tab-count { background: var(--tbf-primary); color: var(--tbf-on-primary, #fff); }

/* ---------------------------------------------------------------- chips */
.tbf-chip {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .16rem .5rem; border-radius: 999px;
    font-size: .7rem; font-weight: 600; line-height: 1.5;
    background: var(--tbf-line-soft); color: var(--tbf-ink-2);
    border: 1px solid transparent; white-space: nowrap;
}
.tbf-chip-success { background: var(--tbf-success-bg); color: var(--tbf-success); }
.tbf-chip-warning { background: var(--tbf-warning-bg); color: var(--tbf-warning); }
.tbf-chip-danger  { background: var(--tbf-danger-bg);  color: var(--tbf-danger); }
.tbf-chip-info    { background: var(--tbf-info-bg);    color: var(--tbf-primary-dark); }
.tbf-chip-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* -------------------------------------------------------------- buttons */
.tbf-btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .45rem .85rem; border-radius: var(--tbf-radius-sm);
    font-size: .8rem; font-weight: 600; line-height: 1.2;
    border: 1px solid var(--tbf-line); background: var(--tbf-surface); color: var(--tbf-ink);
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
    text-decoration: none; cursor: pointer;
}
.tbf-btn:hover { background: var(--tbf-raised); color: var(--tbf-ink); }
.tbf-btn-primary {
    background: var(--tbf-primary); border-color: var(--tbf-primary); color: var(--tbf-on-primary, #fff);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
}
.tbf-btn-primary:hover { background: var(--tbf-primary-dark); border-color: var(--tbf-primary-dark); color: var(--tbf-on-primary, #fff); }
.tbf-btn-ghost { background: transparent; border-color: transparent; color: var(--tbf-muted); }
.tbf-btn-ghost:hover { background: var(--tbf-raised); color: var(--tbf-ink); }
.tbf-btn-sm { padding: .28rem .55rem; font-size: .74rem; }
.tbf-suite .form-control:focus, .tbf-suite .form-select:focus, .tbf-btn:focus-visible {
    border-color: var(--tbf-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--tbf-primary) 18%, transparent);
    outline: none;
}

/* ------------------------------------------------------- inbox workspace */
.tbf-workspace {
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr) 290px;
    gap: 0;
    height: 640px;
    background: var(--tbf-surface);
    border: 1px solid var(--tbf-line);
    border-radius: var(--tbf-radius);
    box-shadow: var(--tbf-shadow);
    overflow: hidden;
}
.tbf-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tbf-pane + .tbf-pane { border-left: 1px solid var(--tbf-line); }
.tbf-pane-head {
    padding: .7rem .85rem;
    border-bottom: 1px solid var(--tbf-line-soft);
    background: var(--tbf-surface);
    flex: 0 0 auto;
}
.tbf-pane-body { overflow-y: auto; flex: 1 1 auto; }
.tbf-pane-foot {
    padding: .7rem .85rem; border-top: 1px solid var(--tbf-line-soft);
    background: var(--tbf-surface); flex: 0 0 auto;
}

/* conversation list */
.tbf-conv {
    display: flex; gap: .65rem; align-items: flex-start;
    padding: .7rem .85rem;
    border-bottom: 1px solid var(--tbf-line-soft);
    cursor: pointer; transition: background .12s;
}
.tbf-conv:hover { background: var(--tbf-raised); }
.tbf-conv.active { background: color-mix(in srgb, var(--tbf-primary) 7%, #fff); box-shadow: inset 3px 0 0 var(--tbf-primary); }
.tbf-conv-main { min-width: 0; flex: 1 1 auto; }
.tbf-conv-name { font-weight: 600; font-size: .82rem; }
.tbf-conv-preview {
    font-size: .75rem; color: var(--tbf-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tbf-conv-meta { text-align: right; font-size: .68rem; color: var(--tbf-faint); flex: 0 0 auto; }

.tbf-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center; flex: 0 0 auto;
    font-size: .78rem; font-weight: 700; color: var(--tbf-on-primary, #fff);
    background: linear-gradient(135deg, var(--tbf-primary), var(--tbf-accent));
}
.tbf-avatar-lg { width: 56px; height: 56px; font-size: 1.1rem; }

.tbf-unread {
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 999px; background: var(--tbf-success); color: #fff;
    font-size: .66rem; font-weight: 700; display: inline-grid; place-items: center;
}

/* message thread */
.tbf-thread { padding: 1.1rem; background: var(--tbf-canvas); }
.tbf-bubble {
    max-width: 74%; padding: .55rem .75rem; border-radius: 12px;
    font-size: .81rem; line-height: 1.45; margin-bottom: .6rem;
    box-shadow: 0 1px 1px rgba(15, 23, 42, .05); position: relative;
}
.tbf-bubble-in  { background: #fff; border: 1px solid var(--tbf-line); border-bottom-left-radius: 3px; }
.tbf-bubble-out {
    background: color-mix(in srgb, var(--tbf-primary) 10%, #fff);
    border: 1px solid color-mix(in srgb, var(--tbf-primary) 22%, #fff);
    border-bottom-right-radius: 3px; margin-left: auto;
}
.tbf-bubble-time { font-size: .66rem; color: var(--tbf-faint); margin-top: .25rem; display: block; }
.tbf-day-divider {
    text-align: center; font-size: .68rem; color: var(--tbf-muted);
    margin: .5rem 0 .9rem;
}
.tbf-day-divider span {
    background: #fff; border: 1px solid var(--tbf-line);
    padding: .15rem .6rem; border-radius: 999px;
}

/* composer */
.tbf-composer { display: flex; gap: .5rem; align-items: center; }
.tbf-composer .form-control { border-radius: 999px; font-size: .82rem; }

/* ------------------------------------------------------------- data list */
.tbf-list-row {
    display: flex; align-items: center; gap: .85rem;
    padding: .8rem 1.1rem; border-bottom: 1px solid var(--tbf-line-soft);
    transition: background .12s;
}
.tbf-list-row:last-child { border-bottom: 0; }
.tbf-list-row:hover { background: var(--tbf-raised); }
.tbf-list-title { font-weight: 600; font-size: .84rem; }
.tbf-list-sub { font-size: .74rem; color: var(--tbf-muted); }

.tbf-meter { height: 6px; border-radius: 999px; background: var(--tbf-line-soft); overflow: hidden; }
.tbf-meter > span { display: block; height: 100%; background: var(--tbf-primary); border-radius: 999px; }

/* template preview — a phone-ish frame so an admin sees what lands */
.tbf-preview {
    background: var(--tbf-canvas); border: 1px solid var(--tbf-line);
    border-radius: 10px; padding: .7rem .8rem;
    font-size: .78rem; line-height: 1.5; white-space: pre-wrap;
    color: var(--tbf-ink-2);
}
.tbf-preview-var { color: var(--tbf-primary); font-weight: 600; }

/* --------------------------------------------------------- empty states */
.tbf-empty { text-align: center; padding: 2.5rem 1rem; color: var(--tbf-muted); }
.tbf-empty i { font-size: 1.6rem; color: var(--tbf-faint); margin-bottom: .5rem; display: block; }
.tbf-empty-title { font-weight: 600; color: var(--tbf-ink-2); font-size: .85rem; }
.tbf-empty-text { font-size: .78rem; max-width: 44ch; margin: .25rem auto 0; }

/* --------------------------------------------------------------- mobile */
@media (max-width: 1199.98px) {
    .tbf-workspace { grid-template-columns: 280px minmax(0, 1fr); }
    .tbf-pane-contact { display: none; }
}
@media (max-width: 767.98px) {
    .tbf-workspace { grid-template-columns: 1fr; height: auto; }
    .tbf-pane-list { max-height: 320px; }
    .tbf-pane + .tbf-pane { border-left: 0; border-top: 1px solid var(--tbf-line); }
    .tbf-thread { min-height: 320px; }
    .tbf-tabs { flex-wrap: nowrap; overflow-x: auto; }
}
