@layer reset, tokens, base, shell, components, modules, utilities, responsive;

@layer reset {
    *, *::before, *::after { box-sizing: border-box; }
    html { scroll-behavior: smooth; text-size-adjust: 100%; }
    body, h1, h2, h3, p { margin: 0; }
    img { display: block; max-width: 100%; }
    button, input, select, textarea { font: inherit; }
    button, select { cursor: pointer; }
    a { color: inherit; text-decoration: none; }
}

@layer tokens {
    :root {
        color-scheme: light;
        --canvas: #f5f6f8;
        --canvas-deep: #eceff2;
        --surface: #ffffff;
        --surface-subtle: #f8f9fa;
        --surface-raised: #ffffff;
        --ink: #171a1f;
        --ink-soft: #404650;
        --muted: #707782;
        --line: #e2e5e9;
        --line-strong: #d3d7dd;
        --brand: #60337a;
        --brand-strong: #48235e;
        --brand-soft: #f2ebf6;
        --accent: #c9ff3d;
        --success: #18765b;
        --success-soft: #e8f6f1;
        --warning: #9a6115;
        --warning-soft: #fff5e4;
        --danger: #b43f50;
        --danger-soft: #fcecef;
        --info: #345f9f;
        --info-soft: #edf4ff;
        --radius-xs: 7px;
        --radius-sm: 10px;
        --radius: 14px;
        --radius-lg: 20px;
        --shadow-sm: 0 1px 2px rgba(23, 26, 31, .05), 0 6px 16px rgba(23, 26, 31, .035);
        --shadow-md: 0 16px 40px rgba(23, 26, 31, .08);
        --sidebar: 258px;
        --content: 1560px;
        --focus: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
    }
}

@layer base {
    body {
        min-width: 320px;
        min-height: 100vh;
        min-height: 100dvh;
        overflow-x: hidden;
        color: var(--ink);
        background: var(--canvas);
        font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
        font-size: 15px;
        line-height: 1.55;
        -webkit-font-smoothing: antialiased;
    }

    :where(a, button, input, select, textarea, summary):focus-visible {
        outline: 2px solid var(--brand);
        outline-offset: 2px;
    }

    ::selection { color: #fff; background: var(--brand); }
    h1, h2, h3, strong { text-wrap: balance; }
    p { text-wrap: pretty; }
    small, .muted, .panel-hint { color: var(--muted); }
    code {
        padding: 3px 7px;
        border: 1px solid var(--line);
        border-radius: 6px;
        color: var(--brand-strong);
        background: var(--brand-soft);
        font: .86em ui-monospace, SFMono-Regular, Consolas, monospace;
    }
}

@layer shell {
    .skip-link {
        position: fixed;
        inset: 8px auto auto 8px;
        z-index: 200;
        translate: 0 -150%;
        padding: 9px 13px;
        border-radius: var(--radius-sm);
        color: #fff;
        background: var(--ink);
        transition: translate .15s ease;
    }
    .skip-link:focus { translate: 0; }

    .workspace-shell { min-height: 100dvh; }
    .workspace-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 80;
        display: flex;
        width: var(--sidebar);
        padding: 20px 16px;
        flex-direction: column;
        border-inline-end: 1px solid var(--line);
        background: color-mix(in srgb, var(--surface) 94%, transparent);
        backdrop-filter: blur(18px) saturate(130%);
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .workspace-brand-block { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 28px; }
    .workspace-brand, .login-brand { display: inline-flex; align-items: center; gap: 11px; min-width: 0; }
    .workspace-brand > span:last-child, .login-brand > span:last-child { display: grid; line-height: 1.1; }
    .workspace-brand strong, .login-brand strong { font-size: 1rem; letter-spacing: -.025em; }
    .workspace-brand small, .login-brand small { margin-top: 4px; font-size: .68rem; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
    .workspace-brand-mark {
        display: grid;
        width: 38px;
        height: 38px;
        flex: 0 0 38px;
        place-items: center;
        border-radius: 11px;
        color: #fff;
        background: linear-gradient(145deg, #73448d, var(--brand-strong));
        box-shadow: 0 7px 18px rgba(72, 35, 94, .2);
        font-size: .75rem;
        font-weight: 850;
        letter-spacing: -.03em;
    }

    .workspace-nav { display: grid; gap: 24px; }
    .nav-group { display: grid; gap: 4px; }
    .nav-group-label { padding: 0 11px 7px; color: #949aa4; font-size: .67rem; font-weight: 750; letter-spacing: .115em; text-transform: uppercase; }
    .workspace-nav a {
        position: relative;
        display: flex;
        min-height: 42px;
        padding: 9px 11px;
        align-items: center;
        gap: 11px;
        border: 1px solid transparent;
        border-radius: var(--radius-sm);
        color: #565e69;
        font-size: .89rem;
        font-weight: 620;
        transition: color .16s ease, background .16s ease, border-color .16s ease, transform .16s ease;
    }
    .workspace-nav a:hover { color: var(--ink); background: var(--surface-subtle); transform: translateX(2px); }
    .workspace-nav a.is-active { color: var(--brand-strong); border-color: #e8dcec; background: var(--brand-soft); }
    .workspace-nav a.is-active::after { content: ""; position: absolute; inset: 10px 7px 10px auto; width: 3px; border-radius: 4px; background: var(--brand); }
    .nav-icon { position: relative; display: grid; width: 20px; height: 20px; flex: 0 0 20px; place-items: center; }
    .nav-icon::before, .nav-icon::after { content: ""; position: absolute; border: 1.7px solid currentColor; }
    .nav-icon-overview::before { inset: 2px; border-radius: 5px; box-shadow: inset 7px 0 0 transparent; }
    .nav-icon-overview::after { width: 5px; height: 5px; inset: 5px auto auto 5px; border-radius: 2px; background: currentColor; }
    .nav-icon-chat::before { inset: 3px 2px 5px; border-radius: 6px; }
    .nav-icon-chat::after { width: 5px; height: 5px; inset: auto auto 2px 5px; border-width: 0 0 1.7px 1.7px; rotate: -30deg; }
    .nav-icon-send::before { width: 15px; height: 15px; border-radius: 3px 10px 3px 3px; rotate: 45deg; }
    .nav-icon-send::after { width: 8px; border-width: 1.7px 0 0; rotate: -45deg; }
    .nav-icon-campaign::before { width: 15px; height: 11px; border-radius: 3px; clip-path: polygon(0 18%, 100% 0, 100% 100%, 0 82%); }
    .nav-icon-campaign::after { width: 4px; height: 7px; inset: 12px auto auto 5px; border-width: 0 0 0 1.7px; rotate: -10deg; }
    .nav-icon-contacts::before, .nav-icon-users::before { width: 7px; height: 7px; inset: 1px auto auto 6px; border-radius: 50%; }
    .nav-icon-contacts::after, .nav-icon-users::after { width: 15px; height: 8px; inset: auto auto 1px 2px; border-radius: 9px 9px 3px 3px; }
    .nav-icon-groups::before { width: 6px; height: 6px; inset: 2px auto auto 7px; border-radius: 50%; box-shadow: -6px 4px 0 -1px var(--surface), -6px 4px 0 1px currentColor, 6px 4px 0 -1px var(--surface), 6px 4px 0 1px currentColor; }
    .nav-icon-groups::after { width: 16px; height: 7px; inset: auto auto 1px 2px; border-radius: 9px 9px 3px 3px; }
    .nav-icon-templates::before { inset: 2px 3px; border-radius: 3px; }
    .nav-icon-templates::after { width: 8px; height: 5px; border-width: 1.7px 0; }
    .nav-icon-logs::before { inset: 2px; border-radius: 50%; }
    .nav-icon-logs::after { width: 6px; height: 6px; inset: 5px auto auto 9px; border-width: 0 0 1.7px 1.7px; }
    .nav-icon-settings::before { inset: 3px; border-radius: 50%; box-shadow: 0 0 0 3px transparent; }
    .nav-icon-settings::after { inset: 7px; border-radius: 50%; background: currentColor; }

    .workspace-sidebar-footer { display: grid; gap: 12px; margin-top: auto; padding-top: 28px; }
    .workspace-user { display: flex; min-width: 0; padding: 9px; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-subtle); }
    .user-avatar { display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; border-radius: 10px; color: var(--brand-strong); background: var(--brand-soft); font-size: .75rem; font-weight: 800; }
    .user-copy { display: grid; min-width: 0; line-height: 1.25; }
    .user-copy strong, .user-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .user-copy strong { font-size: .82rem; }
    .user-copy small { margin-top: 3px; font-size: .7rem; }

    .workspace-stage { min-width: 0; margin-inline-start: var(--sidebar); }
    .workspace-header {
        position: sticky;
        inset-block-start: 0;
        z-index: 50;
        display: flex;
        min-height: 68px;
        padding: 11px clamp(18px, 2.5vw, 38px);
        align-items: center;
        justify-content: space-between;
        gap: 18px;
        border-block-end: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
        background: color-mix(in srgb, var(--canvas) 86%, transparent);
        backdrop-filter: blur(18px) saturate(130%);
    }
    .workspace-header-title { display: grid; line-height: 1.15; }
    .workspace-header-title strong { font-size: .95rem; letter-spacing: -.015em; }
    .workspace-context { margin-bottom: 3px; color: var(--muted); font-size: .68rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
    .workspace-main { width: min(100%, var(--content)); margin-inline: auto; padding: 30px clamp(18px, 2.5vw, 38px) 56px; container: workspace / inline-size; }
    .topbar { display: flex; margin-bottom: 22px; align-items: end; justify-content: space-between; gap: 16px; }
    .topbar h1 { margin-top: 8px; font-size: clamp(1.65rem, 3vw, 2.35rem); line-height: 1.08; letter-spacing: -.045em; }
    .mobile-nav-toggle, .sidebar-close { display: none; }
    .workspace-scrim { display: none; }
}

@layer components {
    .glass, .glass-soft { border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm); }
    .glass-soft { background: var(--surface-subtle); box-shadow: none; }
    .panel, .stat-card, .login-card { padding: clamp(17px, 2vw, 24px); border-radius: var(--radius-lg); }
    .grid { display: grid; gap: 18px; }
    .cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .two-col-layout { grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr); align-items: start; }
    .dashboard-grid, .conversation-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
    .catalog-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
    .section-head { display: flex; margin-bottom: 18px; align-items: center; justify-content: space-between; gap: 14px; }
    .section-head h2, .empty-state h2 { font-size: clamp(1.14rem, 2vw, 1.45rem); line-height: 1.2; letter-spacing: -.035em; }
    .section-head .pill + h2 { margin-top: 7px; }
    .pill { display: inline-flex; width: fit-content; min-height: 25px; padding: 4px 9px; align-items: center; gap: 6px; border: 1px solid #e4d9e9; border-radius: 99px; color: var(--brand-strong); background: var(--brand-soft); font-size: .66rem; font-weight: 780; letter-spacing: .075em; text-transform: uppercase; }

    .button, button.button {
        display: inline-flex;
        min-height: 40px;
        padding: 9px 15px;
        align-items: center;
        justify-content: center;
        gap: 8px;
        border: 1px solid var(--ink);
        border-radius: var(--radius-sm);
        color: #fff;
        background: var(--ink);
        box-shadow: 0 4px 12px rgba(23, 26, 31, .1);
        font-size: .88rem;
        font-weight: 720;
        line-height: 1.1;
        transition: translate .15s ease, box-shadow .15s ease, background .15s ease;
    }
    .button:hover { translate: 0 -1px; box-shadow: 0 7px 18px rgba(23, 26, 31, .14); }
    .button:active { translate: 0; }
    .button.secondary { border-color: var(--brand); background: var(--brand); }
    .button.ghost { color: var(--ink); border-color: var(--line-strong); background: var(--surface); box-shadow: none; }
    .button.ghost:hover { border-color: #bfc4cb; background: var(--surface-subtle); }
    .button.tiny { min-height: 32px; padding: 6px 10px; border-radius: 8px; font-size: .76rem; }
    .button.full, .full { width: 100%; }
    .icon-button { display: grid; width: 40px; height: 40px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--ink); background: var(--surface); }

    .stack-form, .stack-panels, .card-list, .activity-feed, .message-list, .thread-list, .dashboard-reply-stack, .dashboard-diagnostics-list, .dashboard-campaign-list, .dashboard-activity-list { display: grid; gap: 13px; }
    .toolbar, .upload-bar, .quick-actions, .quick-actions form, .inline-form, .checkbox-row, .field-grid, .compact-form { display: flex; gap: 11px; flex-wrap: wrap; }
    .toolbar > *, .upload-bar > *, .inline-form > * { flex: 1 1 170px; }
    .toolbar.compact > * { flex: 0 1 auto; }
    .field-grid.two > * { flex: 1 1 calc(50% - 8px); }
    .field-group { display: grid; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-subtle); }
    .field-group h3 { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; }
    label { display: grid; gap: 6px; min-width: 0; }
    label > span { color: var(--ink-soft); font-size: .76rem; font-weight: 720; letter-spacing: .025em; }
    input, select, textarea {
        width: 100%;
        min-height: 42px;
        padding: 10px 12px;
        border: 1px solid var(--line-strong);
        border-radius: var(--radius-sm);
        color: var(--ink);
        background: var(--surface);
        transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    }
    textarea { min-height: 112px; resize: vertical; line-height: 1.5; }
    input::placeholder, textarea::placeholder { color: #a0a6ae; }
    input:hover, select:hover, textarea:hover { border-color: #b9bec6; }
    input:focus, select:focus, textarea:focus { border-color: color-mix(in srgb, var(--brand) 55%, white); outline: 0; box-shadow: var(--focus); }
    input[type="checkbox"], input[type="radio"] { width: 17px; min-height: 17px; accent-color: var(--brand); }
    input[type="file"] { padding: 7px; }
    .checkbox-row { align-items: center; }
    .checkbox-row label { display: flex; align-items: center; gap: 7px; }

    .stat-card { display: grid; min-height: 122px; align-content: space-between; }
    .stat-card span { color: var(--muted); font-size: .77rem; font-weight: 650; }
    .stat-card strong { font-size: clamp(1.7rem, 3vw, 2.35rem); line-height: 1; letter-spacing: -.055em; }
    .card-item, .message-row, .thread-item, .activity-item, .preview-box, .empty-state, .compact-thread-item {
        padding: 14px;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: var(--surface-subtle);
    }
    .card-item, .activity-item, .thread-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
    .card-item h3, .card-item strong { font-size: .96rem; }
    .card-meta { display: grid; min-width: 100px; justify-items: end; gap: 6px; }
    .tag-cloud { display: flex; gap: 6px; flex-wrap: wrap; }
    .tag { display: inline-flex; padding: 4px 8px; border: 1px solid var(--line); border-radius: 99px; color: var(--ink-soft); background: var(--surface); font-size: .7rem; font-weight: 650; }
    .empty-state { display: grid; min-height: 150px; place-content: center; gap: 7px; text-align: center; color: var(--muted); }
    .empty-state h2 { color: var(--ink); }
    .compact-empty { min-height: 100px; }

    .data-table, .responsive-table { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); scrollbar-width: thin; }
    table { width: 100%; border-collapse: collapse; font-size: .86rem; }
    th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
    tr:last-child td { border-bottom: 0; }
    th { color: var(--muted); background: var(--surface-subtle); font-size: .68rem; font-weight: 760; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
    tbody tr { transition: background .12s ease; }
    tbody tr:hover { background: #fafafb; }

    .status { display: inline-flex; width: fit-content; padding: 4px 8px; align-items: center; border-radius: 99px; color: var(--ink-soft); background: #edf0f2; font-size: .68rem; font-weight: 760; line-height: 1.25; text-transform: lowercase; }
    .status.success, .status.sent, .status.delivered, .status.completed, .status.confirmed { color: var(--success); background: var(--success-soft); }
    .status.warning, .status.running, .status.sending, .status.pending, .status.planned, .status.open, .status.processed { color: var(--warning); background: var(--warning-soft); }
    .status.danger, .status.error, .status.failed, .status.cancelled, .status.opt_out, .status.declined { color: var(--danger); background: var(--danger-soft); }
    .status.info { color: var(--info); background: var(--info-soft); }

    .flash-stack { display: grid; gap: 9px; margin-bottom: 18px; }
    .flash { display: grid; grid-template-columns: auto 1fr auto; padding: 12px 14px; align-items: center; gap: 11px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
    .flash > div { display: grid; }
    .flash strong { font-size: .68rem; letter-spacing: .07em; }
    .flash span { font-size: .85rem; }
    .flash-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--info); }
    .flash.success .flash-dot { background: var(--success); }
    .flash.warning .flash-dot { background: var(--warning); }
    .flash.error .flash-dot { background: var(--danger); }
    .flash-close { width: 30px; height: 30px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: 1.25rem; }
    .flash-close:hover { color: var(--ink); background: var(--surface-subtle); }
    .list-metric { display: grid; }
    .list-metric > div { display: flex; padding: 10px 0; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
}

@layer modules {
    .dashboard-lead { display: grid; grid-template-columns: minmax(0, 1fr) auto; margin-bottom: 14px; gap: 24px; background: linear-gradient(135deg, #fff 0%, #faf7fc 100%); }
    .dashboard-lead-copy { min-width: 0; }
    .dashboard-lead h2 { margin-top: 10px; font-size: clamp(1.35rem, 2.5vw, 1.85rem); letter-spacing: -.04em; }
    .dashboard-lead-text { margin-top: 8px; color: var(--muted); }
    .dashboard-kpi-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 20px; gap: 8px; }
    .dashboard-kpi, .dashboard-system-card { display: grid; padding: 12px; gap: 5px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: rgba(255,255,255,.8); }
    .dashboard-kpi span, .dashboard-system-card span, .dashboard-system-card small { color: var(--muted); font-size: .68rem; font-weight: 650; }
    .dashboard-kpi strong, .dashboard-system-card strong { font-size: 1.15rem; letter-spacing: -.035em; }
    .dashboard-action-stack, .dashboard-toolbox { display: grid; align-content: start; gap: 8px; min-width: 165px; }
    .dashboard-alert-strip { display: grid; margin-bottom: 14px; gap: 8px; }
    .dashboard-alert { display: flex; padding: 12px 14px; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
    .dashboard-alert strong { font-size: .83rem; white-space: nowrap; }
    .dashboard-alert span { color: var(--muted); font-size: .8rem; }
    .dashboard-alert-success { border-color: #cee9df; background: var(--success-soft); }
    .dashboard-smart-grid { grid-template-columns: minmax(0, 1.35fr) minmax(310px, .65fr); align-items: start; }
    .dashboard-subsection { display: grid; gap: 10px; }
    .dashboard-subsection + .dashboard-subsection { padding-top: 16px; border-top: 1px solid var(--line); }
    .dashboard-subsection-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
    .dashboard-subsection-head strong { font-size: .84rem; }
    .dashboard-subsection-head small { font-size: .72rem; }
    .dashboard-message-feed, .dashboard-thread-stack { display: grid; gap: 8px; }
    .dashboard-message-item, .dashboard-thread-item, .dashboard-campaign-row, .dashboard-activity-item, .dashboard-diagnostic-item { display: grid; padding: 12px; gap: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-subtle); transition: border-color .15s ease, background .15s ease; }
    a.dashboard-message-item:hover, a.dashboard-thread-item:hover { border-color: #d0c2d7; background: var(--brand-soft); }
    .dashboard-message-item { grid-template-columns: 1fr auto; }
    .dashboard-message-head, .dashboard-thread-head, .dashboard-campaign-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .dashboard-message-main, .dashboard-thread-body, .dashboard-campaign-main { min-width: 0; }
    .dashboard-message-item p, .dashboard-thread-body p, .dashboard-activity-item p, .dashboard-diagnostic-item p { color: var(--muted); font-size: .8rem; }
    .dashboard-thread-item { grid-template-columns: auto 1fr auto; }
    .thread-avatar, .chat-avatar { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border-radius: 11px; color: var(--brand-strong); background: var(--brand-soft); font-size: .77rem; font-weight: 800; }
    .dashboard-system-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .dashboard-campaign-row { grid-template-columns: 1fr auto; }
    .dashboard-campaign-bar { position: relative; height: 7px; margin-top: 8px; overflow: hidden; border-radius: 99px; background: #e7e9ec; }
    .dashboard-campaign-bar span { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: linear-gradient(90deg, var(--brand), #9c6bb5); }
    .dashboard-campaign-meta { display: grid; align-content: center; justify-items: end; }
    .dashboard-activity-item { grid-template-columns: 1fr auto; }
    .dashboard-activity-left { display: flex; min-width: 0; gap: 10px; }
    .dashboard-activity-left > div { min-width: 0; }

    .conversation-shell { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 16px; align-items: start; }
    .conversation-main-panel, .conversation-side-panel, .conversation-index-panel { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
    .conversation-main-panel, .conversation-index-panel { min-width: 0; overflow: hidden; }
    .conversation-side-panel { position: sticky; top: 86px; padding: 18px; }
    .conversation-header-bar, .conversation-index-header { display: flex; padding: 17px 19px; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
    .conversation-header-main { display: flex; min-width: 0; align-items: center; gap: 12px; }
    .conversation-header-copy { min-width: 0; }
    .conversation-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
    .conversation-title-row h2 { font-size: 1.1rem; letter-spacing: -.025em; }
    .conversation-search, .conversation-index-toolbar { display: flex; min-width: 0; gap: 8px; }
    .conversation-search input, .conversation-index-toolbar input { min-width: 220px; }
    .chat-thread, .compact-chat-thread { display: flex; min-height: 420px; max-height: calc(100dvh - 310px); padding: 20px; flex-direction: column; gap: 10px; overflow-y: auto; overscroll-behavior: contain; background: #f8f9fa; scrollbar-width: thin; }
    .chat-day-separator { display: flex; margin: 5px 0; align-items: center; justify-content: center; color: var(--muted); font-size: .68rem; font-weight: 700; }
    .chat-bubble, .bubble { width: fit-content; max-width: min(78%, 660px); padding: 10px 12px; border: 1px solid var(--line); border-radius: 15px 15px 15px 4px; background: var(--surface); box-shadow: 0 2px 5px rgba(23,26,31,.035); }
    .chat-bubble.outbound, .bubble.outbound { margin-inline-start: auto; border-color: #ded0e5; border-radius: 15px 15px 4px 15px; background: var(--brand-soft); }
    .chat-bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; }
    .chat-bubble-meta, .chat-bubble-tags { display: flex; margin-top: 6px; align-items: center; justify-content: flex-end; gap: 7px; color: var(--muted); font-size: .65rem; }
    .chat-composer { position: sticky; bottom: 0; padding: 14px; border-top: 1px solid var(--line); background: color-mix(in srgb, white 94%, transparent); backdrop-filter: blur(12px); }
    .chat-composer-row { display: flex; align-items: flex-end; gap: 9px; }
    .chat-composer-row textarea { min-height: 42px; max-height: 220px; resize: none; }
    .chat-send-actions { display: flex; gap: 7px; }
    .chat-advanced { margin-top: 10px; }
    .chat-advanced summary, .chat-toggle { color: var(--muted); font-size: .75rem; font-weight: 680; }
    .chat-advanced-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; gap: 10px; }
    .conversation-side-block { display: grid; gap: 8px; }
    .conversation-side-block + .conversation-side-block { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
    .conversation-facts { display: grid; gap: 8px; }
    .conversation-facts > div { display: grid; gap: 2px; }
    .conversation-facts span { color: var(--muted); font-size: .69rem; font-weight: 700; text-transform: uppercase; }
    .conversation-side-actions { display: grid; gap: 8px; }
    .compact-thread-list { display: grid; gap: 8px; }
    .compact-thread-item { display: grid; gap: 6px; }
    .compact-thread-topline, .compact-thread-subline { display: flex; justify-content: space-between; gap: 10px; }
    .compact-thread-subline, .compact-thread-body { color: var(--muted); font-size: .78rem; }
    .thread-direction-chip { display: inline-flex; padding: 3px 7px; border-radius: 99px; font-size: .64rem; font-weight: 720; }
    .thread-direction-chip.inbound { color: var(--success); background: var(--success-soft); }
    .thread-direction-chip.outbound { color: var(--brand-strong); background: var(--brand-soft); }

    .blank-body { background: #edf0f3; }
    .login-screen { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(390px, .85fr); }
    .login-intro { display: flex; min-height: 100%; padding: clamp(28px, 5vw, 72px); flex-direction: column; justify-content: space-between; color: #fff; background: radial-gradient(circle at 85% 15%, rgba(201,255,61,.19), transparent 25%), radial-gradient(circle at 12% 92%, rgba(161,108,190,.35), transparent 34%), linear-gradient(150deg, #17131a 0%, #392044 58%, #5c3272 100%); }
    .login-brand small { color: rgba(255,255,255,.62); }
    .login-brand .workspace-brand-mark { color: var(--ink); background: var(--accent); box-shadow: 0 8px 24px rgba(201,255,61,.16); }
    .login-message { max-width: 680px; padding: 60px 0; }
    .login-message .pill { border-color: rgba(255,255,255,.18); color: #fff; background: rgba(255,255,255,.1); }
    .login-message h1 { margin-top: 20px; font-size: clamp(3rem, 7vw, 6.5rem); line-height: .91; letter-spacing: -.075em; }
    .login-message p { max-width: 610px; margin-top: 24px; color: rgba(255,255,255,.74); font-size: clamp(1rem, 1.7vw, 1.25rem); }
    .login-trust { display: flex; gap: 18px; flex-wrap: wrap; color: rgba(255,255,255,.68); font-size: .75rem; }
    .login-trust span { display: flex; align-items: center; gap: 7px; }
    .login-trust i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(201,255,61,.13); }
    .login-card { width: min(470px, calc(100% - 40px)); margin: auto; padding: clamp(28px, 5vw, 48px); border: 0; box-shadow: var(--shadow-md); }
    .login-card h2 { margin-top: 20px; font-size: clamp(2rem, 4vw, 2.75rem); letter-spacing: -.055em; }
    .login-card > p { margin-top: 5px; color: var(--muted); }
    .login-card .stack-form { margin-top: 28px; gap: 16px; }
    .login-support { padding-top: 18px; border-top: 1px solid var(--line); font-size: .72rem; text-align: center; }
    .centered { width: min(640px, calc(100% - 32px)); margin-inline: auto; }
    .blank-body > .flash-stack { position: fixed; inset: 18px 18px auto auto; z-index: 100; }
}

@layer utilities {
    .small { font-size: .78rem; }
    .compact-details { font-size: .8rem; }
    .message-details { overflow-wrap: anywhere; }
    .gateway-test-form { margin-top: 14px; align-items: end; }
    .file-field { min-width: min(100%, 250px); }
    .compact-status-hint { display: block; margin-top: 8px; }
}

@layer responsive {
    @container workspace (max-width: 1050px) {
        .cards-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
        .dashboard-smart-grid, .conversation-shell { grid-template-columns: 1fr; }
        .conversation-side-panel { position: static; }
        .dashboard-kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    }

    @media (max-width: 1100px) {
        body.has-open-navigation { overflow: hidden; }
        .workspace-stage { margin-inline-start: 0; }
        .workspace-sidebar { width: min(86vw, 290px); translate: -105% 0; box-shadow: var(--shadow-md); transition: translate .22s ease; }
        .nav-is-open .workspace-sidebar { translate: 0; }
        .workspace-scrim { position: fixed; inset: 0; z-index: 70; display: block; border: 0; background: rgba(19, 17, 22, .38); opacity: 0; pointer-events: none; backdrop-filter: blur(2px); transition: opacity .2s ease; }
        .nav-is-open .workspace-scrim { opacity: 1; pointer-events: auto; }
        .mobile-nav-toggle, .sidebar-close { display: grid; }
        .mobile-nav-toggle span, .mobile-nav-toggle span::before, .mobile-nav-toggle span::after { width: 17px; height: 1.5px; border-radius: 2px; background: currentColor; }
        .mobile-nav-toggle span { position: relative; }
        .mobile-nav-toggle span::before, .mobile-nav-toggle span::after { content: ""; position: absolute; inset-inline-start: 0; }
        .mobile-nav-toggle span::before { inset-block-start: -5px; }
        .mobile-nav-toggle span::after { inset-block-start: 5px; }
        .workspace-header { justify-content: flex-start; }
        .header-compose { margin-inline-start: auto; }
    }

    @media (max-width: 800px) {
        .login-screen { grid-template-columns: 1fr; background: linear-gradient(160deg, #211726, #5c3272 42%, #edf0f3 42%); }
        .login-intro { min-height: auto; padding: 24px 22px 70px; background: transparent; }
        .login-message { padding: 55px 0 0; }
        .login-message h1 { font-size: clamp(2.7rem, 12vw, 4.8rem); }
        .login-message p { font-size: .94rem; }
        .login-trust { display: none; }
        .login-card { margin: -32px auto 30px; }
        .dashboard-lead { grid-template-columns: 1fr; }
        .dashboard-action-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
        .two-col-layout, .dashboard-grid, .conversation-layout { grid-template-columns: 1fr; }
        .chat-thread, .compact-chat-thread { max-height: none; }
    }

    @media (max-width: 620px) {
        .workspace-header { min-height: 62px; padding-inline: 14px; }
        .workspace-header-title { display: none; }
        .workspace-main { padding: 22px 14px calc(36px + env(safe-area-inset-bottom)); }
        .topbar { margin-bottom: 16px; }
        .topbar h1 { font-size: 1.65rem; }
        .header-compose { min-height: 38px; }
        .panel, .stat-card, .login-card { border-radius: var(--radius); }
        .cards-4, .dashboard-kpi-strip, .dashboard-system-cards { grid-template-columns: 1fr 1fr; }
        .stat-card { min-height: 102px; }
        .field-grid.two > * { flex-basis: 100%; }
        .section-head, .dashboard-subsection-head, .card-item, .activity-item, .conversation-header-bar, .conversation-index-header { align-items: stretch; flex-direction: column; }
        .section-head .button { width: 100%; }
        .toolbar > *, .upload-bar > *, .inline-form > * { flex-basis: 100%; }
        .toolbar .button, .upload-bar .button, .inline-form .button { width: 100%; }
        .dashboard-message-item, .dashboard-thread-item, .dashboard-campaign-row, .dashboard-activity-item { grid-template-columns: 1fr; }
        .dashboard-thread-item { grid-template-columns: auto 1fr; }
        .dashboard-thread-item > small { grid-column: 2; }
        .dashboard-campaign-meta, .card-meta { justify-items: start; }
        .dashboard-alert { align-items: flex-start; flex-direction: column; gap: 3px; }
        .conversation-header-main { align-items: flex-start; }
        .conversation-search, .conversation-index-toolbar, .chat-composer-row { align-items: stretch; flex-direction: column; }
        .conversation-search input, .conversation-index-toolbar input { min-width: 0; }
        .chat-thread, .compact-chat-thread { padding: 13px; }
        .chat-bubble, .bubble { max-width: 92%; }
        .chat-send-actions > * { flex: 1; }
        .chat-advanced-grid { grid-template-columns: 1fr; }
        .data-table, .responsive-table { margin-inline: -1px; }
        .blank-body > .flash-stack { inset: 10px 10px auto; }
    }

    @media (max-width: 420px) {
        .cards-4, .dashboard-kpi-strip, .dashboard-system-cards, .dashboard-action-stack { grid-template-columns: 1fr; }
        .header-compose { padding-inline: 11px; font-size: .8rem; }
        .login-card { width: calc(100% - 24px); padding: 24px 20px; }
    }

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