/* =========================================================================
   Zapkam Messaging · design system
   Neutral, quiet surfaces; one accent used for selection and the primary
   action; type and spacing on a fixed scale; motion only for feedback.
   ========================================================================= */

:root {
    /* Type */
    --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
    --font-display: "Segoe UI Variable Display", "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
    --fs-11: 0.6875rem;
    --fs-12: 0.75rem;
    --fs-13: 0.8125rem;
    --fs-14: 0.875rem;
    --fs-15: 0.9375rem;
    --fs-18: 1.125rem;
    --fs-22: 1.375rem;

    /* Neutrals */
    --bg: #f6f6f4;
    --surface: #ffffff;
    --surface-2: #fafaf9;
    --surface-hover: #f0f0ee;
    --surface-pressed: #e8e8e5;
    --surface-selected: #e9efec;
    --line: #e5e5e2;
    --line-strong: #d4d4d0;
    --text: #1a1b1c;
    --text-2: #575b60;
    --text-3: #8a8e93;
    --text-inverse: #ffffff;

    /* Accent and states */
    --accent: #0f7a5a;
    --accent-hover: #0c6b4e;
    --accent-pressed: #0a5c43;
    --accent-soft: #e6f2ed;
    --accent-text: #0b6649;
    --out-bubble: #e4f1eb;
    --danger: #c2412d;
    --danger-hover: #a9382a;
    --danger-soft: #fbece8;
    --warn: #9a5a00;
    --warn-dot: #d98a12;
    --warn-soft: #fdf3e2;
    --info: #2463b8;
    --info-soft: #e9f1fb;

    /* Shape and depth */
    --r-4: 4px;
    --r-6: 6px;
    --r-8: 8px;
    --r-12: 12px;
    --shadow-1: 0 1px 2px rgba(17, 20, 24, 0.06);
    --shadow-pop: 0 1px 2px rgba(17, 20, 24, 0.08), 0 8px 28px rgba(17, 20, 24, 0.14);
    --shadow-dialog: 0 2px 6px rgba(17, 20, 24, 0.08), 0 24px 64px rgba(17, 20, 24, 0.22);
    --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px rgba(15, 122, 90, 0.45);

    /* Motion */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in: cubic-bezier(0.5, 0, 0.75, 0);
    --ease: cubic-bezier(0.2, 0, 0, 1);
    --t-fast: 110ms;
    --t: 170ms;
    --t-slow: 240ms;

    /* Layout */
    --appbar-h: 3rem;
    --list-w: 22.5rem;

    /* Channel dots on conversation rows */
    --ch-whatsapp: #1fa855;
    --ch-messenger: #1877f2;
    --ch-instagram: #c13584;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--fs-14);
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body.is-app { height: 100dvh; overflow: hidden; }

h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.i {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.i-sm { width: 0.875rem; height: 0.875rem; }
.i-lg { width: 1.25rem; height: 1.25rem; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

kbd {
    font-family: var(--font);
    font-size: var(--fs-11);
    padding: 1px 0.3125rem;
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-4);
    background: var(--surface);
    color: var(--text-2);
}

/* ---------- App bar ---------- */
.appbar {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    height: var(--appbar-h);
    padding: 0 0.75rem 0 0.875rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5625rem;
    margin-right: 0.875rem;
    color: var(--text);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--fs-14);
    letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 1.375rem;
    height: 1.375rem;
    border-radius: 6px;
    background: var(--text);
    color: var(--surface);
    font-size: var(--fs-12);
    font-weight: 700;
}

.appbar-link {
    display: inline-flex;
    align-items: center;
    height: 1.875rem;
    padding: 0 0.625rem;
    border-radius: var(--r-6);
    color: var(--text-2);
    font-size: var(--fs-13);
    font-weight: 500;
    transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.appbar-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.appbar-link[aria-current="page"] { color: var(--text); background: var(--surface-hover); }

.appbar-spacer { flex: 1; }

.inbox-switcher {
    display: inline-flex;
    align-items: center;
    gap: 0.5625rem;
    max-width: 20rem;
    height: 2.125rem;
    padding: 0 0.5rem 0 0.25rem;
    border: 1px solid var(--line);
    border-radius: var(--r-8);
    color: var(--text);
    transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.inbox-switcher:hover { background: var(--surface-hover); text-decoration: none; }
.inbox-switcher-avatar {
    display: grid;
    place-items: center;
    width: 1.625rem;
    height: 1.625rem;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent-text);
    font-size: var(--fs-11);
    font-weight: 700;
}
.inbox-switcher-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.inbox-switcher-name { font-size: var(--fs-13); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-switcher-sub { font-size: var(--fs-11); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-switcher .i { color: var(--text-3); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    height: 2rem;
    padding: 0 0.75rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-6);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-13);
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
                color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:active { background: var(--surface-pressed); transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--text-inverse); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-pressed); border-color: var(--accent-pressed); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--text-inverse); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-link {
    height: auto;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent-text);
    font-weight: 500;
}
.btn-link:hover { background: none; text-decoration: underline; }

.btn-sm { height: 1.75rem; padding: 0 0.625rem; font-size: var(--fs-12); }
.btn-lg { height: 2.25rem; padding: 0 1rem; font-size: var(--fs-14); }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 1.875rem;
    height: 1.875rem;
    border: 0;
    border-radius: var(--r-6);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:active { background: var(--surface-pressed); }
.icon-btn[aria-expanded="true"] { background: var(--surface-pressed); color: var(--text); }

/* Spinner inside buttons and status lines */
.spinner {
    width: 0.875rem;
    height: 0.875rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 0.375rem; }
.field + .field { margin-top: 0.875rem; }
.field-label { font-size: var(--fs-12); font-weight: 600; color: var(--text-2); }
.field-hint { font-size: var(--fs-12); color: var(--text-3); }

.input, .select, .textarea {
    width: 100%;
    height: 2.125rem;
    padding: 0 0.625rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-6);
    background: var(--surface);
    font-size: var(--fs-13);
    transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.textarea { height: auto; min-height: 4rem; padding: 0.5rem 0.625rem; resize: vertical; line-height: 1.45; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: #c4c4bf; }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 122, 90, 0.14);
}

.search {
    position: relative;
    display: flex;
    align-items: center;
}
.search .i { position: absolute; left: 0.5625rem; color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 1.875rem; padding-right: 1.875rem; height: 2rem; background: var(--surface); }
.search kbd { position: absolute; right: 0.5rem; pointer-events: none; transition: opacity var(--t-fast) var(--ease); }
.search .input:focus ~ kbd, .search .input:not(:placeholder-shown) ~ kbd { opacity: 0; }

/* Radio choices used in dialogs */
.choice { display: flex; gap: 0.875rem; flex-wrap: wrap; }
.choice label { display: inline-flex; align-items: center; gap: 0.375rem; font-size: var(--fs-13); cursor: pointer; }

/* Switch */
.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    cursor: pointer;
    user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
    position: relative;
    flex-shrink: 0;
    width: 1.875rem;
    height: 1.125rem;
    border-radius: 9px;
    background: var(--line-strong);
    transition: background-color var(--t) var(--ease);
}
.switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 0.875rem;
    height: 0.875rem;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: transform var(--t) var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(12px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus-ring); }
.switch:active .switch-track::after { width: 1.0625rem; }
.switch input:checked:active + .switch-track::after { transform: translateX(9px); }

/* ---------- Segmented control (list views) ---------- */
.segmented {
    position: relative;
    display: flex;
    padding: 2px;
    border-radius: var(--r-8);
    background: var(--surface-pressed);
}
.segmented-thumb {
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: 0;
    width: 0;
    border-radius: 6px;
    background: var(--surface);
    box-shadow: var(--shadow-1), 0 0 0 0.5px rgba(17, 20, 24, 0.06);
    transition: transform var(--t-slow) var(--ease-out), width var(--t-slow) var(--ease-out);
    pointer-events: none;
}
.segment {
    position: relative;
    z-index: 1;
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3125rem;
    min-width: 0;
    height: 1.625rem;
    padding: 0 0.375rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-2);
    font-size: var(--fs-12);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--t-fast) var(--ease);
}
.segment:hover { color: var(--text); }
.segment[aria-selected="true"] { color: var(--text); font-weight: 600; }
.segment-count { color: var(--text-3); font-weight: 500; font-variant-numeric: tabular-nums; }
.segment[data-view="unread"] .segment-count.has-items { color: var(--accent-text); font-weight: 600; }

/* ---------- Channel tabs (All / WhatsApp / Facebook / Instagram) ---------- */
.channel-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0 0.75rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0.5rem;
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.channel-tabs::-webkit-scrollbar { display: none; }
.channel-tab {
    flex: 1 1 auto;
    justify-content: center;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.625rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: var(--text-3);
    font: inherit;
    font-size: var(--fs-13);
    font-weight: 500;
    cursor: pointer;
}
.channel-tab .i { width: 1rem; height: 1rem; }
.channel-tab:hover { color: var(--text-2); }
.channel-tab:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.channel-tab .ct-label { display: none; }
.channel-tab[data-channel="all"] .ct-label,
.channel-tab.is-active .ct-label { display: inline; }
.channel-tab.is-active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.ct-count {
    min-width: 1.125rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    font-size: var(--fs-11);
    font-variant-numeric: tabular-nums;
    background: var(--surface-pressed);
    color: var(--text-2);
    text-align: center;
    line-height: 1.125rem;
}
.ct-count:empty { display: none; }
.ct-count.has-items { background: var(--accent); color: #fff; }

/* ---------- Notices (inline, not floating) ---------- */
.notice {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5625rem 0.75rem;
    font-size: var(--fs-12);
    line-height: 1.4;
    color: var(--text-2);
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
}
.notice .i { margin-top: 1px; }
.notice-body { flex: 1; min-width: 0; }
.notice strong { color: var(--text); font-weight: 600; }
.notice-warn { background: var(--warn-soft); color: #6f4a12; border-bottom-color: #f2e3c6; }
.notice-warn .i { color: var(--warn-dot); }
.notice-info { background: var(--info-soft); color: #23466f; border-bottom-color: #d8e5f6; }
.notice-info .i { color: var(--info); }
.notice a, .notice .btn-link { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* =========================================================================
   Inbox
   ========================================================================= */
.inbox {
    display: flex;
    height: calc(100dvh - var(--appbar-h));
    background: var(--surface);
}

/* ---------- Conversation list ---------- */
.inbox-list {
    position: relative;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: var(--list-w);
    min-width: 0;
    background: var(--surface-2);
    border-right: 1px solid var(--line);
    overflow: hidden;
    transition: width var(--t-slow) var(--ease-out), border-color var(--t-slow) var(--ease);
}
.inbox.list-collapsed .inbox-list { width: 0; border-right-color: transparent; }
body.is-resizing .inbox-list { transition: none; }
body.is-resizing { cursor: col-resize; user-select: none; }

.list-inner { display: flex; flex-direction: column; width: var(--list-w); min-width: 16.25rem; height: 100%; }

.list-head {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 0.625rem 0.25rem 1rem;
}
.list-title { font-size: var(--fs-18); }
.list-head .spacer { flex: 1; }

.list-summary {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin: 0 1rem 0.5rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-2);
    font-size: var(--fs-12);
    cursor: pointer;
    align-self: flex-start;
}
.list-summary .dot { width: 0.4375rem; height: 0.4375rem; border-radius: 50%; background: var(--accent); }
.list-summary strong { color: var(--accent-text); font-weight: 600; }
.list-summary:hover strong { text-decoration: underline; text-underline-offset: 2px; }
.list-summary.is-quiet { cursor: default; color: var(--text-3); }
.list-summary.is-quiet:hover strong { text-decoration: none; }

.list-controls { display: flex; flex-direction: column; gap: 0.5rem; padding: 0 0.75rem 0.625rem; }

.list-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 2px 0.375rem 0.75rem;
    scrollbar-gutter: stable;
}
.list-scroll::-webkit-scrollbar { width: 0.625rem; }
.list-scroll::-webkit-scrollbar-thumb { background: transparent; border: 3px solid transparent; border-radius: 6px; background-clip: padding-box; }
.list-scroll:hover::-webkit-scrollbar-thumb { background-color: rgba(17, 20, 24, 0.18); }

.inbox-list[data-view="completed"] .list-scroll[data-list="open"],
.inbox-list:not([data-view="completed"]) .list-scroll[data-list="completed"] { display: none; }

/* Conversation row */
.conv {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.6875rem;
    padding: 0.5625rem 0.625rem;
    border-radius: var(--r-8);
    color: var(--text);
    cursor: default;
    transition: background-color var(--t-fast) var(--ease);
}
.conv:hover { background: var(--surface-hover); text-decoration: none; }
.conv:active { background: var(--surface-pressed); }
.conv.is-selected { background: var(--surface-selected); }
.conv.is-selected::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.625rem;
    bottom: 0.625rem;
    width: 3px;
    border-radius: 2px;
    background: var(--accent);
    animation: bar-in var(--t) var(--ease-out);
}
@keyframes bar-in { from { transform: scaleY(0.3); opacity: 0; } }
.conv + .conv { margin-top: 1px; }
.conv.is-filtered { display: none; }

.avatar {
    position: relative;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    font-size: var(--fs-12);
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #3d4a44;
    background: #e3e9e5;
}
.avatar .i { width: 1.125rem; height: 1.125rem; color: currentColor; opacity: 0.8; }
.avatar-lg { width: 2.25rem; height: 2.25rem; }
.avatar.t1 { background: #e3ece7; color: #2e5444; }
.avatar.t2 { background: #e5e9f2; color: #3a4a6b; }
.avatar.t3 { background: #f1e8e1; color: #6b4a33; }
.avatar.t4 { background: #ece5f0; color: #563f69; }
.avatar.t5 { background: #e2edef; color: #2f5a60; }
.avatar.t6 { background: #efe9dc; color: #5f5232; }

/* Channel logo badge on an avatar */
.avatar-ch {
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 0.9375rem;
    height: 0.9375rem;
    border-radius: 50%;
    background: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 0 0 1.5px var(--surface);
}
.avatar .avatar-ch .i { width: 100%; height: 100%; opacity: 1; }

.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.conv-line { display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; }
.conv-name {
    flex: 1;
    min-width: 0;
    font-size: var(--fs-13);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-time { flex-shrink: 0; font-size: var(--fs-11); color: var(--text-3); font-variant-numeric: tabular-nums; }
.conv-preview {
    flex: 1;
    min-width: 0;
    font-size: var(--fs-12);
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-tag {
    flex-shrink: 0;
    max-width: 40%;
    font-size: var(--fs-11);
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-count {
    flex-shrink: 0;
    min-width: 1.125rem;
    height: 1.125rem;
    padding: 0 0.3125rem;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: var(--fs-11);
    font-weight: 700;
    line-height: 1.125rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
    animation: count-in var(--t) var(--ease-out);
}
@keyframes count-in { from { transform: scale(0.6); opacity: 0; } }
.conv.is-unread .conv-name { font-weight: 650; font-weight: 600; }
.conv.is-unread .conv-preview { color: var(--text); }
.conv.is-unread .conv-time { color: var(--accent-text); font-weight: 600; }
.conv.is-completed .conv-name { color: var(--text-2); }

.list-empty {
    padding: 2.5rem 1.25rem;
    text-align: center;
    color: var(--text-3);
    font-size: var(--fs-13);
}
.list-empty strong { display: block; margin-bottom: 0.25rem; color: var(--text-2); font-weight: 600; font-size: var(--fs-13); }

/* Resizer between list and thread */
.inbox-resizer {
    position: relative;
    flex-shrink: 0;
    width: 0;
    z-index: 5;
}
.inbox-resizer::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -3px;
    width: 0.375rem;
    cursor: col-resize;
    background: transparent;
    transition: background-color var(--t-fast) var(--ease);
}
.inbox-resizer:hover::after, body.is-resizing .inbox-resizer::after, .inbox-resizer:focus-visible::after { background: rgba(15, 122, 90, 0.35); }
.inbox-resizer:focus-visible { box-shadow: none; }
.inbox.list-collapsed .inbox-resizer { display: none; }

/* ---------- Thread ---------- */
.thread {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}
.thread-root { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.thread-root.is-entering { animation: thread-in var(--t-slow) var(--ease-out); }
@keyframes thread-in { from { opacity: 0; transform: translateY(4px); } }
.thread.is-loading .thread-root { opacity: 0.55; transition: opacity var(--t) var(--ease) 120ms; }

.thread-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 3.75rem;
    padding: 0.625rem 0.875rem 0.625rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.thread-head .avatar { width: 2.125rem; height: 2.125rem; }
.thread-title-wrap { flex: 1; min-width: 0; }
.thread-title {
    font-size: var(--fs-15);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.thread-sub {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 0.625rem;
    font-size: var(--fs-12);
    color: var(--text-3);
}
.thread-sub span { white-space: nowrap; }
.thread-state {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-2);
}
.thread-actions { display: flex; align-items: center; gap: 0.375rem; flex-shrink: 0; }
.only-collapsed, .only-mobile { display: none; }
.inbox.list-collapsed .only-collapsed { display: inline-grid; }

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.125rem max(1.25rem, calc((100% - 48.75rem) / 2)) 1.5rem;
    scroll-behavior: smooth;
}

.day-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.125rem 0 0.625rem;
    color: var(--text-3);
    font-size: var(--fs-11);
    font-weight: 600;
    letter-spacing: 0.02em;
}
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.messages > .day-divider:first-child { margin-top: 0; }

.new-divider {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin: 1rem 0 0.5rem;
    color: var(--accent-text);
    font-size: var(--fs-12);
    font-weight: 600;
    animation: fade-in var(--t-slow) var(--ease-out);
}
.new-divider::before { content: ""; flex: 1; height: 1px; background: rgba(15, 122, 90, 0.35); order: 1; }
.new-divider .btn-link { order: 2; font-size: var(--fs-12); }

.msg {
    position: relative;
    display: flex;
    flex-direction: column;
    width: fit-content;
    max-width: min(72%, 37.5rem);
    margin-top: 2px;
    padding: 0.4375rem 0.6875rem 0.375rem;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--line);
}
.msg.is-first { margin-top: 0.75rem; }
.msg.in { margin-right: auto; border-top-left-radius: 12px; }
.msg.out { margin-left: auto; background: var(--out-bubble); box-shadow: none; }
.msg.in.is-first { border-top-left-radius: 4px; }
.msg.out.is-first { border-top-right-radius: 4px; }
.msg.is-history { opacity: 0.86; }
.msg.is-new { animation: msg-in var(--t-slow) var(--ease-out); }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.msg.is-pending { opacity: 0.6; }
.msg.is-unread { box-shadow: 0 0 0 1px var(--line), inset 3px 0 0 var(--accent); }

.msg-sender { margin-bottom: 1px; font-size: var(--fs-12); font-weight: 600; color: var(--text-2); }
.msg.out .msg-sender { color: var(--accent-text); }
.msg-text {
    font-size: var(--fs-14);
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.msg-text a { color: var(--info); text-decoration: underline; text-underline-offset: 2px; }
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.375rem;
    margin-top: 2px;
    font-size: var(--fs-11);
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}
.msg-new-label { color: var(--accent-text); font-weight: 600; }
.msg-tag { display: inline-flex; align-items: center; gap: 3px; }
.msg-channel { font-size: var(--fs-11); font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }

/* Hover action on unread incoming bubbles */
.msg-action {
    position: absolute;
    top: 50%;
    right: -2.375rem;
    display: grid;
    place-items: center;
    width: 1.75rem;
    height: 1.75rem;
    margin-top: -0.875rem;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-2);
    box-shadow: var(--shadow-1);
    cursor: pointer;
    opacity: 0;
    transform: scale(0.9);
    transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.msg:hover .msg-action, .msg-action:focus-visible { opacity: 1; transform: none; }
.msg-action:hover { color: var(--accent-text); }

.msg-media { margin: 2px -0.25rem 0.25rem; }
.msg-media img {
    display: block;
    max-width: min(20rem, 100%);
    max-height: 20rem;
    border-radius: 8px;
    cursor: zoom-in;
}
.msg-media video { display: block; max-width: min(20rem, 100%); border-radius: 8px; }
.msg-media audio { width: 16.25rem; max-width: 100%; height: 2.25rem; }
.msg-file {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: var(--fs-13);
    font-weight: 500;
}
.msg-file:hover { background: var(--surface-hover); text-decoration: none; }
.msg-media-missing { font-size: var(--fs-12); color: var(--text-3); font-style: italic; padding: 2px 0.25rem; }

.thread-empty {
    margin: auto;
    padding: 2.5rem 1.5rem;
    max-width: 22.5rem;
    text-align: center;
    color: var(--text-3);
}
.thread-empty h2 { margin: 0.75rem 0 0.375rem; font-size: var(--fs-15); color: var(--text); }
.thread-empty p { font-size: var(--fs-13); line-height: 1.5; }
.thread-empty .actions { display: flex; justify-content: center; gap: 0.5rem; margin-top: 1rem; }
.thread-empty-icon {
    display: inline-grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--line);
    color: var(--text-3);
}
.thread-empty-icon .i { width: 1.375rem; height: 1.375rem; }

/* ---------- Composer ---------- */
.composer {
    padding: 0.5rem max(1rem, calc((100% - 50.75rem) / 2)) 0.875rem;
    background: var(--bg);
}
.composer-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 1.375rem;
    margin-bottom: 0.375rem;
    font-size: var(--fs-12);
    color: var(--text-3);
}
.composer-status .from { color: var(--text-2); }
.composer-status .spacer { flex: 1; }
.composer-status .hint kbd { font-size: 0.625rem; }
.composer-box {
    display: flex;
    align-items: flex-end;
    gap: 0.375rem;
    padding: 0.375rem 0.375rem 0.375rem 0.75rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-12);
    background: var(--surface);
    box-shadow: var(--shadow-1);
    transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 122, 90, 0.12); }
.composer-input {
    flex: 1;
    min-height: 1.5rem;
    max-height: 10rem;
    padding: 0.3125rem 0;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    font-size: var(--fs-14);
    line-height: 1.45;
}
.composer-input::placeholder { color: var(--text-3); }
.composer-input:focus { box-shadow: none; }
.send-btn {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: var(--r-8);
    background: var(--surface-pressed);
    color: var(--text-3);
    cursor: pointer;
    transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.composer-box.has-text .send-btn { background: var(--accent); color: #fff; }
.composer-box.has-text .send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { cursor: not-allowed; }
.composer.is-blocked .composer-box { background: var(--surface-2); box-shadow: none; border-style: dashed; }
.composer-blocked {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    margin-bottom: 0.5rem;
    padding: 0.5625rem 0.75rem;
    border-radius: var(--r-8);
    background: var(--warn-soft);
    color: #6f4a12;
    font-size: var(--fs-12);
    line-height: 1.45;
}
.composer-blocked .i { color: var(--warn-dot); margin-top: 1px; }
.composer-blocked strong { color: #5a3c0d; }

/* =========================================================================
   Overlays: dialogs, menus, toasts
   ========================================================================= */
dialog.dialog {
    width: min(28.75rem, calc(100vw - 2rem));
    max-height: calc(100dvh - 3rem);
    padding: 0;
    border: 0;
    border-radius: var(--r-12);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-dialog);
    overflow: visible;
}
dialog.dialog-wide { width: min(35rem, calc(100vw - 2rem)); }
dialog.dialog[open] { animation: dialog-in var(--t) var(--ease-out); }
dialog.dialog.is-closing { animation: dialog-out var(--t-fast) var(--ease-in) forwards; }
dialog.dialog::backdrop { background: rgba(17, 20, 24, 0.32); animation: fade-in var(--t) var(--ease-out); }
dialog.dialog.is-closing::backdrop { animation: fade-out var(--t-fast) var(--ease-in) forwards; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(4px) scale(0.99); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

.dialog-form { display: flex; flex-direction: column; max-height: inherit; }
.dialog-head { display: flex; align-items: flex-start; gap: 0.75rem; padding: 1.125rem 1.25rem 0.25rem; }
.dialog-title { flex: 1; font-size: var(--fs-15); }
.dialog-desc { margin-top: 0.25rem; font-size: var(--fs-13); color: var(--text-2); line-height: 1.5; white-space: pre-line; }
.dialog-body { padding: 0.875rem 1.25rem 0.375rem; overflow-y: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.875rem 1.25rem 1.125rem; }
.dialog-section + .dialog-section { margin-top: 1.125rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.dialog-section-title { margin-bottom: 0.5rem; font-size: var(--fs-12); font-weight: 600; color: var(--text-2); }
.inline-row { display: flex; gap: 0.5rem; }
.inline-row > .input, .inline-row > .select { flex: 1; min-width: 0; }
.kv-list { display: flex; flex-direction: column; font-size: var(--fs-13); }
.kv-list > div { display: flex; justify-content: space-between; gap: 0.625rem; padding: 0.3125rem 0; }
.kv-list > div + div { border-top: 1px solid var(--line); }
.kv-list .muted { color: var(--text-3); font-size: var(--fs-12); }
.dialog-skeleton { display: flex; flex-direction: column; gap: 0.625rem; }
.skeleton { height: 0.75rem; border-radius: 4px; background: linear-gradient(90deg, #efefec 25%, #f6f6f4 50%, #efefec 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.lightbox { background: transparent; box-shadow: none; width: auto; max-width: calc(100vw - 3rem); }
.lightbox img { display: block; max-width: calc(100vw - 3rem); max-height: calc(100dvh - 3rem); border-radius: var(--r-8); box-shadow: var(--shadow-dialog); }
.lightbox::backdrop { background: rgba(10, 12, 14, 0.78); }

/* Menu / popover */
.menu {
    position: fixed;
    z-index: 1000;
    min-width: 12.5rem;
    max-width: 17.5rem;
    padding: 0.25rem;
    border-radius: var(--r-8);
    background: var(--surface);
    box-shadow: var(--shadow-pop), 0 0 0 1px rgba(17, 20, 24, 0.06);
    transform-origin: var(--origin, top left);
    animation: menu-in var(--t-fast) var(--ease-out);
}
.menu.is-closing { animation: menu-out 90ms var(--ease-in) forwards; }
@keyframes menu-in { from { opacity: 0; transform: scale(0.97); } }
@keyframes menu-out { to { opacity: 0; transform: scale(0.98); } }
.menu-item {
    display: flex;
    align-items: center;
    gap: 0.5625rem;
    width: 100%;
    height: 1.875rem;
    padding: 0 0.5625rem;
    border: 0;
    border-radius: 5px;
    background: transparent;
    font-size: var(--fs-13);
    text-align: left;
    color: var(--text);
    cursor: default;
}
.menu-item .i { color: var(--text-2); }
.menu-item:hover, .menu-item:focus { outline: none; background: var(--surface-hover); box-shadow: none; }
.menu-item.is-danger { color: var(--danger); }
.menu-item.is-danger .i { color: var(--danger); }
.menu-sep { height: 1px; margin: 0.25rem 0.375rem; background: var(--line); }

/* Toasts */
.toasts {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    width: min(23.75rem, calc(100vw - 2rem));
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.625rem 0.625rem 0.625rem 0.875rem;
    border-radius: var(--r-8);
    background: #1f2224;
    color: #f2f3f3;
    font-size: var(--fs-13);
    line-height: 1.4;
    box-shadow: var(--shadow-pop);
    pointer-events: auto;
    animation: toast-in var(--t-slow) var(--ease-out);
}
.toast.is-leaving { animation: toast-out var(--t) var(--ease-in) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
.toast .i { color: #9aa1a6; }
.toast.success .i { color: #5ccfa6; }
.toast.danger .i { color: #ff8b7a; }
.toast.warning .i { color: #f0b250; }
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-action {
    flex-shrink: 0;
    height: 1.625rem;
    padding: 0 0.5rem;
    border: 0;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: var(--fs-12);
    font-weight: 600;
    cursor: pointer;
}
.toast-action:hover { background: rgba(255, 255, 255, 0.2); }
.toast-close {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #9aa1a6;
    cursor: pointer;
}
.toast-close:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }

/* =========================================================================
   Standalone pages: picker, connections, key form
   ========================================================================= */
.page {
    height: calc(100dvh - var(--appbar-h));
    overflow-y: auto;
}
.page-inner {
    max-width: 55rem;
    margin: 0 auto;
    padding: 2.25rem 1.5rem 4rem;
}
.page-header { margin-bottom: 1.75rem; }
.page-title { font-size: var(--fs-22); }
.page-lead { margin-top: 0.375rem; max-width: 38.75rem; color: var(--text-2); font-size: var(--fs-14); line-height: 1.55; }

.section + .section { margin-top: 2.25rem; }
.section-head { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.625rem; }
.section-title { font-size: var(--fs-14); }
.section-count { color: var(--text-3); font-size: var(--fs-13); font-variant-numeric: tabular-nums; }
.section-desc { margin: -0.25rem 0 0.75rem; color: var(--text-3); font-size: var(--fs-13); }

.panel {
    border: 1px solid var(--line);
    border-radius: var(--r-12);
    background: var(--surface);
    box-shadow: var(--shadow-1);
}

/* Connect form */
/* The button sits level with the input (not the hint line below it) */
.connect-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 0.625rem;
    align-items: center;
    padding: 1rem;
}
.connect-form .field { display: contents; }
.connect-form .field-label { grid-column: 1; grid-row: 1; margin-bottom: 0.375rem; }
.connect-form .input { grid-column: 1; grid-row: 2; }
.connect-form .field-hint { grid-column: 1; grid-row: 3; margin-top: 0.375rem; }
.connect-form > .btn { grid-column: 2; grid-row: 2; }
@media (max-width: 40rem) {
    .connect-form { grid-template-columns: minmax(0, 1fr); }
    .connect-form > .btn { grid-column: 1; grid-row: 4; margin-top: 0.75rem; }
}
.connect-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-top: 1px solid var(--line);
    font-size: var(--fs-13);
    color: var(--text-2);
    animation: fade-in var(--t) var(--ease-out);
}
.connect-status.is-success { color: var(--accent-text); }
.connect-status.is-error { color: var(--danger); }
.connect-status .i { flex-shrink: 0; }

/* Settings list (numbers) */
.settings-list { list-style: none; margin: 0; padding: 0; }
.setting-row { padding: 0.875rem 1rem; }
.setting-row + .setting-row { border-top: 1px solid var(--line); }
.setting-main { display: flex; align-items: center; gap: 0.875rem; }
.setting-who { flex: 1; min-width: 0; }
.owner-edit {
    display: block;
    width: 100%;
    max-width: 20rem;
    margin-left: -0.375rem;
    padding: 2px 0.375rem;
    border: 1px solid transparent;
    border-radius: var(--r-6);
    background: transparent;
    font-size: var(--fs-14);
    font-weight: 600;
    transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.owner-edit:hover { border-color: var(--line); }
.owner-edit:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px rgba(15, 122, 90, 0.14); }
.owner-edit::placeholder { color: var(--text-3); font-weight: 500; }
.owner-edit.is-saved { animation: saved-flash 900ms var(--ease); }
@keyframes saved-flash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
.setting-sub { display: flex; flex-wrap: wrap; gap: 2px 0.75rem; margin-top: 1px; font-size: var(--fs-12); color: var(--text-3); }
.status-dot { display: inline-flex; align-items: center; gap: 0.375rem; font-size: var(--fs-12); color: var(--text-2); white-space: nowrap; }
.status-dot::before { content: ""; width: 0.4375rem; height: 0.4375rem; border-radius: 50%; background: var(--text-3); }
.status-dot.ok::before { background: #22a06b; }
.status-dot.info::before { background: var(--info); }
.status-dot.warn::before { background: var(--warn-dot); }
.status-dot.off::before { background: var(--line-strong); }
.setting-side { display: flex; align-items: center; gap: 0.875rem; flex-shrink: 0; }
.switch-label { font-size: var(--fs-13); color: var(--text-2); }
.setting-problem {
    margin: 0.75rem 0 0 0;
    padding: 0.625rem 0.75rem;
    border-radius: var(--r-8);
    background: var(--warn-soft);
    color: #6f4a12;
    font-size: var(--fs-12);
    line-height: 1.5;
}
.setting-problem summary { margin-top: 0.25rem; cursor: pointer; font-weight: 600; color: #7d5a1e; width: fit-content; }
.setting-problem summary:hover { text-decoration: underline; text-underline-offset: 2px; }
.raw {
    margin: 0.5rem 0 0.375rem;
    max-height: 17.5rem;
    overflow: auto;
    padding: 0.625rem 0.75rem;
    border-radius: var(--r-6);
    background: #1f2224;
    color: #e8eaeb;
    font-family: var(--font-mono);
    font-size: var(--fs-11);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.setting-row.is-off .owner-static { color: var(--text-2); font-weight: 600; }
.empty-panel { padding: 1.75rem 1rem; text-align: center; color: var(--text-3); font-size: var(--fs-13); }

/* Picker */
.picker { max-width: 27.5rem; margin: 0 auto; padding: 4.5rem 1.5rem; }
.picker-title { font-size: var(--fs-22); }
.picker-lead { margin: 0.375rem 0 1.375rem; color: var(--text-2); }
.picker-list { list-style: none; margin: 0; padding: 0.25rem; }
.picker-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 0;
    border-radius: var(--r-8);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background-color var(--t-fast) var(--ease);
}
.picker-item:hover { background: var(--surface-hover); }
.picker-item:active { background: var(--surface-pressed); }
.picker-item .avatar { width: 2.125rem; height: 2.125rem; }
.picker-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.picker-item-name { font-weight: 600; font-size: var(--fs-14); }
.picker-item-sub { font-size: var(--fs-12); color: var(--text-3); }
.picker-item .i { color: var(--text-3); transition: transform var(--t-fast) var(--ease); }
.picker-item:hover .i { transform: translateX(2px); color: var(--text-2); }
.picker-current { font-size: var(--fs-11); font-weight: 600; color: var(--accent-text); background: var(--accent-soft); border-radius: 10px; padding: 2px 0.4375rem; }
.picker-foot { margin-top: 1.125rem; font-size: var(--fs-13); color: var(--text-3); }

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 860px) {
    :root { --list-w: 18.75rem; }
    .thread-actions .btn-label { display: none; }
}

@media (max-width: 720px) {
    .appbar { padding: 0 0.5rem 0 0.625rem; }
    .appbar-link { padding: 0 0.5rem; }
    .inbox-switcher-text { display: none; }
    .inbox-switcher { padding: 0 0.375rem 0 0.25rem; }

    .inbox { position: relative; overflow: hidden; }
    .inbox-list, .inbox.list-collapsed .inbox-list { width: 100%; border-right: 0; }
    .list-inner { width: 100%; }
    .inbox-resizer, [data-action="collapse-list"] { display: none !important; }
    .thread {
        position: absolute;
        inset: 0;
        transform: translateX(100%);
        transition: transform var(--t-slow) var(--ease-out);
        box-shadow: -8px 0 24px rgba(17, 20, 24, 0.06);
    }
    .inbox.has-selection .thread { transform: none; }
    .only-mobile { display: inline-grid; }
    .only-collapsed { display: none !important; }
    .messages { padding: 0.875rem 0.75rem 1.125rem; }
    .msg { max-width: 86%; }
    .msg-action { right: auto; left: calc(100% + 0.375rem); }
    .composer { padding: 0.375rem 0.625rem 0.625rem; }
    .composer-status .hint { display: none; }
    .page-inner { padding: 1.5rem 1rem 3rem; }
    .setting-main { flex-wrap: wrap; }
    .setting-side { width: 100%; justify-content: space-between; }
}

@media (hover: none) {
    .msg-action { opacity: 1; transform: none; }
}

/* =========================================================================
   Reduced motion: keep feedback, drop movement
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
        scroll-behavior: auto !important;
    }
    .spinner { animation-duration: 1.4s !important; animation-iteration-count: infinite !important; }
}


/* ---------- Refinements from review ---------- */
.notice-close {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 1.375rem;
    height: 1.375rem;
    margin: -2px -0.25rem -2px 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: inherit;
    opacity: 0.7;
    cursor: pointer;
}
.notice-close:hover { opacity: 1; background: rgba(0, 0, 0, 0.06); }
.notice.is-leaving { animation: notice-out var(--t) var(--ease-in) forwards; }
@keyframes notice-out { to { opacity: 0; transform: translateY(-4px); } }

/* Narrow list: the view names stay, the totals go (Unread keeps its count) */
.list-inner { container-type: inline-size; }
@container (max-width: 32rem) {
    .segment-count { display: none; }
    .segment[data-view="unread"] .segment-count.has-items { display: inline; }
    .segment { padding: 0 0.25rem; }
}

/* Dialog bodies without a footer still need room at the bottom */
.dialog-body:last-child { padding-bottom: 1.25rem; }

/* Toasts sit under the app bar, away from the composer and its Send button */
.toasts { top: calc(var(--appbar-h) + 0.75rem); bottom: auto; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-4px); } }
/* Final placement: bottom-left, clear of the composer and the header actions */
.toasts { top: auto; bottom: 1rem; left: 1rem; right: auto; align-items: flex-start; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px); } }
@media (max-width: 720px) {
    .toasts { left: 50%; transform: translateX(-50%); bottom: 5.25rem; align-items: stretch; }
}
/* Keep the list's internal layering (segmented thumb) inside the list */
.inbox-list { isolation: isolate; }
@media (max-width: 720px) { .thread { z-index: 2; } }
/* Keyboard hints mean nothing on touch screens */
@media (hover: none) { .search kbd, .composer-status .hint { display: none; } }
/* Narrow screens: one clear primary action; "mark read" stays in the divider and menus */
@media (max-width: 860px) {
    .thread-actions [data-action="mark-all-read"] { display: none; }
    .thread-actions .btn-label { display: inline; }
}
.inbox.list-collapsed .inbox-list { border-right-width: 0; }
/* Toasts stay within the list column so they never cover the composer */
.toasts { width: min(20.75rem, calc(100vw - 2rem)); }

/* =========================================================================
   Comfortable density + scaling across screen sizes
   Everything above is in rem, so the root size sets the scale: compact on
   small laptops, larger on big and very wide monitors, touch-sized on phones.
   ========================================================================= */
html { font-size: 15px; }
@media (min-width: 1280px) { html { font-size: 16px; } }
@media (min-width: 1680px) { html { font-size: 17px; } }
@media (min-width: 2200px) { html { font-size: 18.5px; } }
@media (max-width: 720px)  { html { font-size: 16px; } }

:root {
    --fs-16: 1rem;
    --fs-20: 1.25rem;
    --appbar-h: 3.25rem;
    /* The list grows with the screen; a width set by dragging wins */
    --list-w: clamp(19rem, 26vw, 30rem);
}

/* App bar */
.appbar { padding: 0 1rem; }
.brand { font-size: var(--fs-15); }
.brand-mark { width: 1.5rem; height: 1.5rem; font-size: var(--fs-13); }
.appbar-link { height: 2.125rem; padding: 0 0.75rem; font-size: var(--fs-14); }
.inbox-switcher { height: 2.375rem; }
.inbox-switcher-avatar { width: 1.75rem; height: 1.75rem; font-size: var(--fs-12); }
.inbox-switcher-name { font-size: var(--fs-14); }
.inbox-switcher-sub { font-size: var(--fs-12); }

/* Controls */
.btn { height: 2.25rem; padding: 0 0.875rem; font-size: var(--fs-14); }
.btn-sm { height: 2rem; padding: 0 0.75rem; font-size: var(--fs-13); }
.btn-lg { height: 2.5rem; padding: 0 1.125rem; font-size: var(--fs-15); }
.icon-btn { width: 2.125rem; height: 2.125rem; }
.i { width: 1.0625rem; height: 1.0625rem; }
.i-sm { width: 0.875rem; height: 0.875rem; }
.input, .select { height: 2.375rem; font-size: var(--fs-14); }
.textarea { font-size: var(--fs-14); }
.field-label { font-size: var(--fs-13); }
.field-hint { font-size: var(--fs-13); }

/* List */
.list-head { padding: 1rem 0.75rem 0.375rem 1.25rem; }
.list-title { font-size: var(--fs-20); }
.list-summary { margin: 0 1.25rem 0.75rem; font-size: var(--fs-13); }
.list-controls { gap: 0.625rem; padding: 0 1rem 0.875rem; }
.search .input { height: 2.375rem; }
.segment { height: 2rem; font-size: var(--fs-13); }
.list-scroll { padding: 0.25rem 0.5rem 1rem; }
.conv { gap: 0.875rem; padding: 0.75rem 0.75rem; }
.conv + .conv { margin-top: 2px; }
.avatar { width: 2.625rem; height: 2.625rem; font-size: var(--fs-13); }
.avatar .i { width: 1.25rem; height: 1.25rem; }
.conv-main { gap: 0.1875rem; }
.conv-name { font-size: var(--fs-15); }
.conv-time { font-size: var(--fs-12); }
.conv-preview { font-size: var(--fs-13); }
.conv-tag { font-size: var(--fs-12); }
.conv-count { min-width: 1.25rem; height: 1.25rem; line-height: 1.25rem; font-size: var(--fs-12); }
.conv.is-selected::before { top: 0.75rem; bottom: 0.75rem; }
.notice { padding: 0.75rem 1rem; font-size: var(--fs-13); }
.list-empty { font-size: var(--fs-14); }
.list-empty strong { font-size: var(--fs-14); }

/* Conversation */
.thread-head { min-height: 4.25rem; padding: 0.75rem 1.25rem; gap: 0.875rem; }
.thread-head .avatar { width: 2.5rem; height: 2.5rem; }
.thread-title { font-size: var(--fs-16); }
.thread-sub { font-size: var(--fs-13); gap: 0.125rem 0.75rem; }
.messages { padding: 1.5rem max(1.5rem, calc((100% - 54rem) / 2)) 1.75rem; }
.msg { max-width: min(70%, 42rem); padding: 0.5625rem 0.875rem 0.5rem; border-radius: 0.875rem; }
.msg.is-first { margin-top: 0.875rem; }
.msg + .msg { margin-top: 0.1875rem; }
.msg-sender { font-size: var(--fs-13); margin-bottom: 0.125rem; }
.msg-text { font-size: var(--fs-15); line-height: 1.5; }
.msg-meta { font-size: var(--fs-12); margin-top: 0.25rem; }
.msg-action { width: 2rem; height: 2rem; margin-top: -1rem; right: -2.625rem; }
.day-divider { font-size: var(--fs-12); margin: 1.5rem 0 0.875rem; }
.new-divider { font-size: var(--fs-13); margin: 1.25rem 0 0.625rem; }
.new-divider .btn-link { font-size: var(--fs-13); }
.msg-media img, .msg-media video { max-width: min(22rem, 100%); max-height: 22rem; }
.composer { padding: 0.625rem max(1.25rem, calc((100% - 56rem) / 2)) 1.125rem; }
.composer-status { font-size: var(--fs-13); margin-bottom: 0.5rem; }
.composer-box { padding: 0.5rem 0.5rem 0.5rem 0.875rem; border-radius: 0.875rem; }
.composer-input { font-size: var(--fs-15); min-height: 1.75rem; }
.send-btn { width: 2.25rem; height: 2.25rem; }
.composer-blocked { font-size: var(--fs-13); padding: 0.75rem 0.875rem; }
.thread-empty h2 { font-size: var(--fs-16); }
.thread-empty p { font-size: var(--fs-14); }

/* Overlays */
dialog.dialog { width: min(32rem, calc(100vw - 2rem)); }
dialog.dialog-wide { width: min(38rem, calc(100vw - 2rem)); }
.dialog-title { font-size: var(--fs-16); }
.dialog-desc { font-size: var(--fs-14); }
.menu-item { height: 2.125rem; font-size: var(--fs-14); }
.toast { font-size: var(--fs-14); }
.toasts { width: min(22rem, calc(100vw - 2rem)); }

/* Pages */
.page-inner { max-width: 62rem; padding: 2.75rem 2rem 4rem; }
.page-title { font-size: 1.625rem; }
.page-lead { font-size: var(--fs-15); max-width: 42rem; }
.section-title { font-size: var(--fs-16); }
.setting-row { padding: 1.125rem 1.25rem; }
.owner-edit { font-size: var(--fs-15); }
.setting-sub, .status-dot { font-size: var(--fs-13); }
.switch-label { font-size: var(--fs-14); }
.picker { max-width: 32rem; }
.picker-item-name { font-size: var(--fs-15); }
.picker-item-sub { font-size: var(--fs-13); }

/* Mid-size screens (tablets, small laptops): keep the list usable, drop button labels */
@media (min-width: 721px) and (max-width: 1100px) {
    :root { --list-w: clamp(18rem, 34vw, 22rem); }
    .messages { padding-left: 1.25rem; padding-right: 1.25rem; }
    .msg { max-width: 80%; }
}

/* Phones: full-width list, roomy touch targets */
@media (max-width: 720px) {
    .conv { padding: 0.75rem 0.625rem; }
    .msg { max-width: 86%; }
    .messages { padding: 1rem 0.875rem 1.25rem; }
    .composer { padding: 0.5rem 0.75rem 0.75rem; }
    .page-inner { padding: 1.75rem 1rem 3rem; }
}

/* The view names never squeeze into each other */
.segment { overflow: hidden; text-overflow: ellipsis; }

/* Tablets: a list wide enough for its controls */
@media (min-width: 721px) and (max-width: 1100px) {
    :root { --list-w: clamp(20rem, 36vw, 23rem); }
}

/* Short labels when the list is narrow */
.seg-short { display: none; }
@container (max-width: 22rem) {
    .seg-full { display: none; }
    .seg-short { display: inline; }
    .segment { font-size: var(--fs-12); }
}
/* Narrower conversation panes: keep the status line to what matters */
.composer-status { flex-wrap: wrap; row-gap: 2px; }
@media (max-width: 1100px) { .composer-status .hint { display: none; } }
/* Phones: the name gets the room; actions become icons, details are trimmed */
@media (max-width: 720px) {
    .thread-head { gap: 0.625rem; padding: 0.625rem 0.75rem; }
    .thread-actions .btn-label { display: none; }
    .thread-actions .btn { width: 2.25rem; padding: 0; }
    .thread-sub span:nth-child(n+3) { display: none; }
}

/* ---------- Team page ---------- */
.team-table { width: 100%; border-collapse: collapse; font-size: var(--fs-13); }
.team-table th { text-align: left; padding: 0.5rem 0.75rem; font-size: var(--fs-12); font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--line); }
.team-table td { padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.team-table tr:last-child td { border-bottom: none; }
.team-sub { font-size: var(--fs-12); color: var(--text-3); }
.team-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.team-actions form { margin: 0; }
.team-invite { display: grid; grid-template-columns: 1fr 1fr 10rem auto; gap: 0.75rem; align-items: end; }
.team-invite .field + .field { margin-top: 0; }
.team-owner { display: flex; gap: 0.5rem; align-items: center; margin: 0; }
@media (max-width: 720px) { .team-invite { grid-template-columns: 1fr; } }

/* ---------- Employee logins: owner views, notes, assignment ---------- */
.owner-views { display: flex; gap: 0.375rem; padding: 0.5rem 0.75rem 0; flex-wrap: wrap; }
.owner-view { display: inline-flex; align-items: center; gap: 0.375rem; height: 1.75rem; padding: 0 0.625rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text-2); font: inherit; font-size: var(--fs-12); font-weight: 500; cursor: pointer; }
.owner-view:hover { background: var(--surface-hover); }
.owner-view.is-active { background: var(--accent-soft, #e4f1ec); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.owner-view:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.conv-tag.is-warn { background: var(--warn-soft); color: #6f4a12; }
.thread-owner { font-weight: 600; color: var(--accent-text); }
.thread-owner.is-warn { color: #8a5a10; }
.assign-select { height: 1.75rem; font-size: var(--fs-12); width: auto; max-width: 11rem; }
.msg.note { background: #fdf0d5; border: 1px dashed #e0b95a; color: #4a3500; }
.msg.note .msg-sender { color: #7a5200; }
.note-form { display: flex; gap: 0.5rem; align-items: center; padding: 0.5rem 1rem 0.75rem; }
.note-form .input { flex: 1; height: 1.875rem; font-size: var(--fs-13); }
.overview-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.overview-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-8); padding: 0.875rem 1rem; display: flex; flex-direction: column; gap: 0.125rem; }
.overview-card strong { font-size: var(--fs-20, 1.25rem); font-weight: 700; }
.overview-card span { font-size: var(--fs-13); color: var(--text-2); }
.overview-card.is-warn { background: var(--warn-soft); border-color: #e0b95a; }
@media (max-width: 720px) { .overview-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Linked customers ---------- */
.avatar-dual { width: auto; min-width: 0.9375rem; padding: 0 1px; border-radius: 999px; display: flex; gap: 1px; align-items: center; }
.avatar .avatar-dual .i { width: 0.8125rem; height: 0.8125rem; opacity: 1; }
.thread-linked { font-weight: 600; color: var(--accent-text); }
.reply-picker { display: flex; flex-wrap: wrap; gap: 0.375rem; align-items: center; padding: 0.5rem 1rem 0; font-size: var(--fs-12); color: var(--text-2); }
.reply-pick { display: inline-flex; align-items: center; gap: 0.375rem; height: 1.75rem; padding: 0 0.625rem; border: 1px solid var(--line); border-radius: var(--r-8); background: var(--surface); color: var(--text); text-decoration: none; font-size: var(--fs-12); }
.reply-pick .i { width: 1rem; height: 1rem; }
.reply-pick:hover { background: var(--surface-hover); text-decoration: none; }
.reply-pick.is-active { border-color: var(--accent); background: var(--accent-soft, #e4f1ec); font-weight: 600; }
.reply-pick.is-off { color: var(--text-3); border-style: dashed; }
.reply-pick-note { color: var(--text-3); font-weight: 400; }
.msg-channel { display: inline-flex; align-items: center; gap: 0.25rem; }
.link-list { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: 0.75rem; }
.link-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.625rem 0.75rem; border: 1px solid var(--line); border-radius: var(--r-8); }
.link-item.is-suggested { border-color: var(--accent); background: var(--accent-soft, #e4f1ec); }
.link-item .i { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }
.link-item-main { flex: 1; min-width: 0; }
.link-item-title { font-weight: 600; font-size: var(--fs-14); }
.link-item-sub { font-size: var(--fs-12); color: var(--text-3); }
.link-empty { font-size: var(--fs-13); color: var(--text-3); padding: 0.25rem 0; }

/* ---------- Inbox picker: groups, unread counts, channel logos ---------- */
.picker-group { margin: 1.25rem 0 0.5rem; font-size: var(--fs-12); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }
.picker-unread { min-width: 1.375rem; height: 1.375rem; padding: 0 0.4rem; border-radius: 999px; background: var(--accent); color: #fff; font-size: var(--fs-12); font-weight: 600; display: grid; place-items: center; }
.picker-logos { display: flex; align-items: center; width: 2.125rem; flex-shrink: 0; }
.picker-logos .i { width: 1.125rem; height: 1.125rem; margin-left: -0.125rem; }
.picker-item:hover .picker-logos .i { transform: none; }
.appbar-user { display: flex; flex-direction: column; line-height: 1.15; margin-left: 0.75rem; font-size: var(--fs-13); font-weight: 600; text-align: right; }
.appbar-user small { font-size: var(--fs-11); font-weight: 400; color: var(--text-3); }

/* ---------- CRM customer panel ---------- */
.thread-root.has-crm { display: grid; grid-template-columns: minmax(0, 1fr) 18.5rem; grid-template-rows: auto minmax(0, 1fr) auto; }
.thread-root.has-crm > .thread-head { grid-column: 1 / -1; grid-row: 1; }
.thread-root.has-crm > .messages { grid-column: 1; grid-row: 2; }
.thread-root.has-crm > .composer { grid-column: 1; grid-row: 3; }
.crm-panel { grid-column: 2; grid-row: 2 / span 2; overflow-y: auto; border-left: 1px solid var(--line); background: var(--surface); }
.crm-section { padding: 0.875rem 1rem; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 0.5rem; }
.crm-heading { margin: 0; font-size: var(--fs-12); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); }
.crm-status { margin: 0; display: flex; align-items: center; gap: 0.375rem; font-size: var(--fs-13); color: var(--text-2); }
.crm-status.is-linked { color: var(--accent-text); font-weight: 600; }
.crm-status.is-blocked { color: var(--danger); }
.crm-muted { margin: 0; font-size: var(--fs-12); color: var(--text-3); }
.crm-card { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.625rem 0.75rem; border: 1px solid var(--line); border-radius: var(--r-8); background: var(--surface-2); }
.crm-org { font-weight: 600; font-size: var(--fs-14); color: var(--text); }
.crm-name { font-size: var(--fs-13); color: var(--text-2); }
.crm-row { display: flex; align-items: center; gap: 0.375rem; font-size: var(--fs-13); color: var(--text-2); min-width: 0; }
.crm-row a, .crm-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-ext { display: inline-flex; align-items: center; gap: 0.25rem; font-size: var(--fs-13); font-weight: 500; }
.crm-actions { display: flex; gap: 0.375rem; flex-wrap: wrap; }
.crm-tools { display: flex; flex-direction: column; gap: 0.375rem; }
.crm-tool, .crm-btn { justify-content: center; gap: 0.375rem; }
.crm-danger { color: var(--danger); }
.crm-block { border-bottom: 0; }
.thread-org { font-weight: 600; color: var(--text-2); }
.thread-state.is-blocked, .conv-tag.is-blocked { color: var(--danger); background: var(--danger-soft); }
.conv-org { font-size: var(--fs-12); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-toggle, .crm-close { display: none; }
@media (max-width: 75rem) {
  .thread-root.has-crm { grid-template-columns: minmax(0, 1fr); }
  .crm-toggle { display: inline-flex; }
  .crm-close { display: inline-flex; position: absolute; top: 0.5rem; right: 0.5rem; z-index: 1; }
  .crm-panel { position: relative; }
  .crm-panel { display: none; }
  .thread-root.crm-open > .crm-panel { display: block; position: absolute; top: 0; right: 0; bottom: 0; width: min(20rem, 100%); z-index: 30; box-shadow: var(--shadow-pop); }
}
