:root {
  color-scheme: light;
  --bg: #f5f7fb; --card: #fff; --line: #e2e8f0; --line-strong: #cbd5e1;
  --text: #0f172a; --text-2: #334155; --muted: #64748b; --faint: #94a3b8;
  --accent: #2563eb; --accent-hover: #1d4ed8; --accent-soft: #eff4ff; --accent-text: #1e40af;
  --ok: #15803d; --ok-soft: #ecfdf3; --danger: #b42318; --danger-soft: #fef2f2;
  --warn: #b45309; --warn-soft: #fffbeb;
  /* Owner dots: a fixed muted palette; one person keeps one color (picked in app.js by id hash) */
  --owner-1: #2563eb; --owner-2: #0f766e; --owner-3: #7c3aed; --owner-4: #b45309;
  --owner-5: #be185d; --owner-6: #15803d; --owner-7: #b42318; --owner-8: #475569;
  --shadow: 0 1px 2px #0f17220a, 0 4px 16px #0f17220d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }  /* pages of every service line up whether they scroll or not */
body { margin: 0; min-width: 320px; }
h1, h2, h3, p { margin: 0; }
main { width: min(1160px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 48px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

/* Controls */
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.secondary { background: var(--card); color: var(--text-2); border-color: var(--line-strong); }
.btn.secondary:hover:not(:disabled) { background: #f8fafc; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #912018; }
.icon-btn { width: 32px; height: 32px; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--muted); font-size: 18px; line-height: 1; }
.icon-btn:hover { background: #f1f5f9; color: var(--text); }
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field > .hint { font-size: 12px; font-weight: 400; color: var(--muted); }
input:not([type=checkbox], [type=radio]) { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--card); color: var(--text); font: inherit; }
input::placeholder { color: var(--faint); }
input[readonly] { background: #f8fafc; color: var(--muted); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.check { display: inline-flex; gap: 10px; align-items: flex-start; color: var(--text-2); cursor: pointer; }
.check input { margin-top: 2px; flex-shrink: 0; }
.check small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
:is(button, input):focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.with-action { display: flex; gap: 8px; }
.with-action input { flex: 1; min-width: 0; }

/* Layout */
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 28px 0 20px; }
.top h1 { font-size: 22px; }
.lead { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* Contour bar (DESIGN.md Л2): static until contour.js from Users fills in the services */
.contour { background: var(--card); border-bottom: 1px solid var(--line); }
.contour-inner { width: min(1160px, calc(100% - 32px)); margin: 0 auto; height: 52px; display: flex; align-items: center; gap: 24px; }
.contour-brand { font-weight: 700; color: var(--text); text-decoration: none; }
.contour-links { display: flex; gap: 20px; flex: 0 1 auto; min-width: 0; overflow: hidden; }
.contour-links a { color: var(--muted); font-weight: 600; font-size: 13px; text-decoration: none; white-space: nowrap; padding: 16px 0 14px; border-bottom: 2px solid transparent; }
.contour-links a:hover { color: var(--text); }
.contour-links a[aria-current=page] { color: var(--accent); border-bottom-color: var(--accent); }
.contour-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.contour-user .btn { height: 32px; padding: 0 12px; }
.contour-user span { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.contour-user span a { color: inherit; text-decoration: none; }  /* email → profile in Users, set by contour.js */
.contour-user span a:hover { color: var(--text); text-decoration: underline; }
.contour-more { height: 32px; padding: 0 12px; flex-shrink: 0; }  /* «Ещё ▾» / «Сервисы ▾»: contour.js adds and shows it */
.contour-menu a { text-decoration: none; }
.contour-menu a[aria-current=page] { color: var(--accent); font-weight: 600; }

/* «Реакции»: requests from CRM above the tasks; «Подключения»: sections in the order of DESIGN.md Л5 */
.section-title, .proxies > h2 { font-size: 16px; }

/* «Реакции»: a switch between its views, compact queue tables, a sticky bar for what is picked */
.segmented { justify-self: start; display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.segmented button { padding: 6px 14px; border: 0; border-radius: 7px; background: none; color: var(--muted); font-weight: 600; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed=true] { background: var(--accent-soft); color: var(--accent-text); }
.seg-count { margin-left: 4px; font-variant-numeric: tabular-nums; }
.reaction-view { display: grid; gap: 12px; }
.reaction-view > .toolbar { margin-bottom: 0; }
.bulk-bar { position: sticky; top: 8px; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; padding: 8px 8px 8px 16px; border: 1px solid var(--accent); border-radius: 10px; background: var(--card); box-shadow: var(--shadow); }
#request-picked { margin-right: auto; font-weight: 600; }
.queue-row { cursor: pointer; }
.queue-row:hover td { background: #f8fafc; }
.queue-table td { padding-top: 10px; padding-bottom: 10px; }
td.queue-main { max-width: 0; width: 55%; }  /* the long link truncates instead of widening the table */
.queue-main > a, .queue-note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-main > a { display: inline-block; max-width: 100%; vertical-align: top; }  /* only the text is a link: the rest of the row opens it */
.queue-note { display: block; }
.queue-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-label { color: var(--muted); margin-right: 6px; }
.queue-label::after { content: ":"; }
.queue-wish { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }  /* the copywriter's wish: «на пост» often comes last */
.queue-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
td.progress-cell { min-width: 150px; }
td.action-cell { width: 1%; text-align: right; white-space: nowrap; }
.btn.compact { height: 32px; padding: 0 12px; }
.idle-toggle td { padding: 8px 16px; }
.reason-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { padding: 4px 10px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--card); color: var(--text-2); font-size: 13px; }
.chip-btn:hover { background: #f1f5f9; }
@media (max-width: 720px) {
  .segmented { display: flex; }
  .queue-table .hide-mobile { display: none !important; }
  .segmented button { flex: 1; padding: 6px 8px; }
  .queue-table, .queue-table tbody { display: block; }
  .queue-table thead { display: none; }
  /* Row one: check, what it is, its menu; the other cells stack below it, under the text */
  .queue-table tbody tr { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; border-bottom: 1px solid var(--line); }
  .queue-table tbody td { border: 0; padding: 4px 12px; width: auto; max-width: none; }
  .queue-table td.check-cell { grid-area: 1 / 1; padding: 12px 0 0 12px; }
  .queue-table td.queue-main { grid-area: 1 / 2; padding-top: 10px; }
  .queue-table tr:not(:has(> .check-cell)) td.queue-main { grid-column: 1 / 3; }
  .queue-table td.menu-cell { grid-area: 1 / 3; padding-top: 8px; }
  .queue-table td:not(.queue-main, .check-cell, .menu-cell) { grid-column: 2 / -1; }
  .queue-table tr:not(:has(> .check-cell)) td:not(.queue-main, .menu-cell) { grid-column: 1 / -1; }
  .queue-table tbody tr > td:last-child { padding-bottom: 12px; }
  .queue-table td.action-cell .btn { width: 100%; }
  .queue-table td.empty, .idle-toggle td { grid-column: 1 / -1; padding: 12px; }
  .bulk-bar .btn { flex: 1; }
  .queue-table td.progress-cell { flex-basis: 100%; }
  .queue-table td.empty, .idle-toggle td { flex: 1 1 100%; }
}
.section-title { margin-top: 24px; }
.section-title:first-child { margin-top: 0; }
.section-lead { margin: 4px 0 12px; }
.proxies { margin-top: 24px; }
.table-dialog { width: min(820px, calc(100% - 32px)); }
.work-idle { opacity: .65; }  /* «Работа»: a task this person has no account left for */
.tabs { display: flex; flex-wrap: wrap; gap: 0 24px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.tab { padding: 10px 0 12px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.panel { display: grid; gap: 16px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar .search { width: min(320px, 100%); }
.form { display: grid; gap: 18px; padding: 24px; max-width: 760px; }
.form-section { display: grid; gap: 16px; }
.form-section + .form-section { padding-top: 22px; border-top: 1px solid var(--line); }
.form-section h2 { font-size: 16px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { display: flex; gap: 8px; align-items: center; }
.message { padding: 9px 12px; border-radius: 8px; color: var(--ok); background: var(--ok-soft); font-size: 13px; }
.message:empty { display: none; }
.message.error { color: var(--danger); background: var(--danger-soft); }

/* Login */
#login { width: min(400px, calc(100vw - 32px)); margin: 12vh auto; padding: 28px; }
#login h1 { font-size: 22px; margin-bottom: 20px; }
#login-form { display: grid; gap: 14px; }
#login .btn { width: 100%; margin-top: 4px; }

/* Tables */
.table-wrap { position: relative; overflow-x: auto; }
.list-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.list-foot > span { color: var(--muted); font-size: 13px; }
table { width: 100%; border-collapse: collapse; }
#agents-table { min-width: 900px; }
#agents-table thead th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
#agents-table thead th[data-sort]:hover { color: var(--text-2); }
.activity-cell { white-space: nowrap; }
#journal-table { min-width: 900px; }
#journal-table td { vertical-align: top; }
#journal-table td:not(.details) { white-space: nowrap; overflow-wrap: normal; }
#journal-table td.details { min-width: 320px; width: 40%; }
#journal-table td.agent-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
td.when { color: var(--muted); font-size: 13px; }
.action-danger { color: var(--danger); font-weight: 600; }
.details { font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.load-more { justify-self: center; }
th { padding: 10px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }
th.narrow, td.narrow { width: 1%; white-space: nowrap; }
td.menu-cell { width: 1%; text-align: right; padding-right: 10px; }
.person { font-weight: 600; overflow-wrap: anywhere; }
.person + .muted { font-size: 13px; margin-top: 2px; }
.you { margin-left: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
tr.inactive .person, tr.inactive .person + .muted, tr.inactive .chip { opacity: .55; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--ok); background: var(--ok-soft); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.off { color: var(--danger); background: var(--danger-soft); }
.badge.none { color: var(--muted); background: #f1f5f9; }
.badge.busy { color: var(--accent-text); background: var(--accent-soft); }
.service-name { font-weight: 600; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }

/* Multiselect and row menu: popovers render in the top layer, so the table's scroll box never clips them */
.ms-trigger { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; width: 100%; min-width: 220px; min-height: 36px; padding: 4px 32px 4px 8px;
  position: relative; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--text); text-align: left; }
td .ms-trigger { max-width: 420px; }
.ms-trigger:hover:not(:disabled) { border-color: var(--faint); }
.ms-trigger::after { content: ""; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px; margin-top: -6px;
  border: solid var(--muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
.ms-trigger:disabled { opacity: 1; cursor: default; background: #f8fafc; }
.ms-trigger:disabled::after { display: none; }
.ms-placeholder { padding: 0 4px; color: var(--faint); }
.ms-value { padding: 0 4px; }
.chip { padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 600; }
[popover] { position: fixed; inset: auto; margin: 0; padding: 6px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); box-shadow: 0 10px 30px #0f172226; }
.ms-panel { width: max-content; max-width: min(320px, calc(100vw - 16px)); }
.ms-search { margin-bottom: 6px; }
.ms-list { display: grid; max-height: 260px; overflow-y: auto; }
.ms-option { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.ms-option:hover { background: #f1f5f9; }
select { height: 32px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; }
.role-option { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 6px 6px 6px 10px; border-radius: 6px; }
.role-option:hover { background: #f8fafc; }
.role-option > span { font-weight: 600; }
.role-option:not(.on) > span { color: var(--muted); font-weight: 400; }
.ms-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 4px 2px; margin-top: 6px; border-top: 1px solid var(--line); }
.ms-foot .btn { height: 32px; padding: 0 12px; }
.menu-panel { min-width: 200px; }
.menu-item { display: block; width: 100%; padding: 8px 12px; border: 0; border-radius: 6px; background: none; color: var(--text); text-align: left; }
.menu-item:hover { background: #f1f5f9; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-sep { height: 1px; margin: 4px 0; background: var(--line); }

/* Dialogs and toast */
dialog { width: min(460px, calc(100% - 32px)); padding: 24px; border: 1px solid var(--line); border-radius: 14px; color: var(--text); box-shadow: 0 24px 70px #0f172240; }
dialog::backdrop { background: #0f172259; }
dialog form, .dialog-body { display: grid; gap: 14px; }
dialog h2 { font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 16px;
  border-radius: 10px; background: #0f172a; color: #fff; font-size: 13px; box-shadow: 0 10px 30px #0f172240; z-index: 10; }
#toast.error { background: var(--danger); }
#toast:empty { display: none; }

@media (max-width: 720px) {
  main, .contour-inner { width: calc(100% - 24px); }
  .contour-links, .contour-user span { display: none; }  /* links move into the «Сервисы ▾» popover */
  .top { padding-top: 18px; }
  .cols { grid-template-columns: 1fr; }
  .form { padding: 18px; }
  .tabs { gap: 0 18px; }
  .inline-form > .btn { margin-top: 0; }
}

/* Agents */
textarea { width: 100%; min-height: 76px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--card); color: var(--text); font: inherit; resize: vertical; }
.mono, textarea.mono, input.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
:is(textarea, select):focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.form-field-full { grid-column: 1 / -1; }
.toolbar-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar select { height: 38px; }
/* Agent form: secrets with their show / copy buttons right at the field */
.secret-editor { display: grid; gap: 22px; }
.secret-group { display: grid; gap: 12px; }
.secret-group h3 { font-size: 14px; }
/* Show / copy sit inside the field, so every field keeps the same width */
.with-icons { position: relative; }
.with-icons > :is(input, textarea) { padding-right: calc(var(--icons, 1) * 32px + 8px); }
.field-icons { position: absolute; top: 3px; right: 4px; display: flex; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.totp-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.totp-line:empty { display: none; }
.totp-code { font: 600 18px ui-monospace, "Cascadia Code", Consolas, monospace; letter-spacing: .08em; color: var(--accent-text); }
.link-button { padding: 0; border: 0; background: none; color: var(--text); text-align: left; }
.link-button:hover { color: var(--accent); text-decoration: underline; }
#agent-form select:disabled, #reaction-form input:not([type=radio]):disabled, #reaction-form select:disabled { background: #f8fafc; color: var(--muted); opacity: 1; }
a { color: var(--accent); }
.agent-row { cursor: pointer; }
.quick-copy { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.quick { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 10px 0 8px; border: 1px solid var(--line-strong);
  border-radius: 8px; background: var(--card); color: var(--text-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.quick:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.quick svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#agent-form select, #import-form select { width: 100%; height: 38px; }
#import-form select { min-width: 0; }
#agent-form select:disabled { background: #f8fafc; color: var(--muted); opacity: 1; }
#agent-title:focus { outline: none; }
.badge.warm { color: var(--accent-text); background: var(--accent-soft); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip.muted-chip { background: #f1f5f9; color: var(--muted); }
.chip.gone { background: var(--danger-soft); color: var(--danger); }
td.check-cell, th.check-cell { width: 1%; padding-right: 0; }
.wide-dialog { width: min(640px, calc(100% - 32px)); }
/* History filter: one kind at a time, with how many there are */
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 1px solid var(--line-strong);
  border-radius: 999px; background: var(--card); color: var(--text-2); font-size: 13px; font-weight: 600; }
.filter-chip:hover { background: #f8fafc; }
.filter-chip[aria-pressed=true] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.filter-count { color: var(--muted); font-weight: 500; }
.filter-chip[aria-pressed=true] .filter-count { color: var(--accent-text); }
.history { display: grid; gap: 12px; max-height: 50vh; overflow-y: auto; padding-right: 4px; }
.history-item { display: grid; gap: 2px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: 0; }
/* A CRM reply: our text in a quiet box, long text clamped (full text in the title) */
.crm-reply { display: grid; gap: 4px; min-width: 0; }
.crm-reply:empty, #reaction-crm:empty { display: none; }
.crm-text { padding: 6px 10px; border-left: 3px solid var(--line-strong); background: #f8fafc; border-radius: 4px; color: var(--text); white-space: pre-line; }
.crm-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
/* Clamped text clips at the padding edge: bottom space as a border, so the 4th line never peeks through it. */
.crm-text.crm-clamp { padding-bottom: 0; border-bottom: 6px solid transparent; }
/* CRM publication picker: what the post is on the left, «Выбрать» on the right */
.publication-row { grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; align-items: center; }
.publication-row > div { display: grid; gap: 2px; min-width: 0; }
.publication-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.publication-filters input { flex: 1 1 220px; min-width: 0; }
.publication-filters select { height: 38px; flex: 1 1 140px; min-width: 0; }
.with-action .btn { flex: none; }
/* Reaction task: one field per row (what is boosted, then who places it); counts stay narrow */
.reaction-cols { grid-template-columns: 1fr; }
/* Exchange services: one dialog, a list of assigned services or the exchange's catalog; only the list scrolls */
.services-dialog { width: min(980px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 0; }
.services-dialog.picking { height: min(760px, calc(100dvh - 32px)); }  /* the catalog gets the room; a short list does not */
.services-body { display: flex; flex-direction: column; gap: 12px; height: 100%; padding: 24px; }
.services-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.services-view { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.services-scroll { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.compact-table th { position: sticky; top: 0; z-index: 1; background: var(--card); padding: 8px 12px; }
.compact-table td { padding: 8px 12px; }
.compact-table td.clip { max-width: 0; width: 100%; }
.compact-table td.nowrap { white-space: nowrap; }
.compact-table td.label-cell { white-space: nowrap; }
@media (max-width: 720px) { .compact-table td.label-cell { white-space: normal; width: 100%; } }
#services-assigned .services-scroll { flex: 0 1 auto; }  /* hugs a short list instead of an empty frame */
.compact-table .clip > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compact-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.catalog-table tbody tr { cursor: pointer; }
.catalog-table tbody tr:hover { background: #f8fafc; }
.catalog-table tbody tr[aria-selected="true"] { background: var(--accent-soft); }
.catalog-table tbody tr:focus-visible { outline: 3px solid #93c5fd; outline-offset: -3px; }
.catalog-count { padding: 8px 12px; }
.catalog-filters { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 8px; }
.catalog-filters > * { min-width: 0; height: 38px; }
.catalog-pick { display: grid; gap: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.catalog-pick-fields { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: end; }
.catalog-pick-fields.with-platform { grid-template-columns: 2fr 1fr 1fr 1fr auto; }
.catalog-pick select { width: 100%; height: 38px; }
.badge.assigned { margin-left: 8px; color: var(--accent-text); background: var(--accent-soft); }
.badge.assigned::before { display: none; }
@media (max-width: 720px) {
  .services-dialog, .services-dialog.picking { width: 100%; height: 100dvh; max-width: none; max-height: none; border-radius: 0; }
  .services-body { padding: 16px; }
  .services-head { flex-wrap: wrap; }
  .catalog-filters { grid-template-columns: 1fr 1fr; }
  .catalog-filters #catalog-search { grid-column: 1 / -1; order: 5; }
  .catalog-pick-fields { grid-template-columns: 1fr 1fr; }
  .catalog-pick-fields .field:first-child, .catalog-pick-fields .btn { grid-column: 1 / -1; }
  .hide-mobile { display: none; }
}
/* «Биржи накрутки»: the primary action in the card's head, like a toolbar */
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
@media (max-width: 720px) { .card-head { flex-wrap: wrap; } }
.exchange-services { display: grid; gap: 2px; }
#exchanges-table .person { overflow-wrap: normal; word-break: keep-all; }
/* showModal focuses the dialog itself when nothing has autofocus: no ring around the whole window */
dialog:focus-visible { outline: none; }
/* a long form keeps its buttons in reach */
#agent-form > .dialog-actions, #import-form > .dialog-actions, #reaction-dialog > .sticky-actions { position: sticky; bottom: -24px; margin: 0 -24px -24px; padding: 12px 24px 24px; background: var(--card); border-top: 1px solid var(--line); }
.history-item .what { font-weight: 600; }
.history-item .what.action-danger { color: var(--danger); }
a.btn { text-decoration: none; }
/* Integrations, as on CRM: a card per direction, a one-line form above its table */
.wide-form { max-width: none; }
.wide-form h2 { font-size: 16px; }
.wide-form h2 + p { margin-top: 4px; }
.inline-form { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.inline-form .grow { flex: 1 1 220px; }
.inline-form select { width: 100%; height: 38px; }
.inline-form > .btn { margin-top: 25px; }
#connections-table, #keys-table { min-width: 560px; }
.only-mobile { display: none; }
@media (max-width: 720px) {
  #connections-table, #keys-table { min-width: 0; }
  #connections-table td:nth-child(2), #connections-table th:nth-child(2),
  #keys-table td:nth-child(2), #keys-table th:nth-child(2),
  #exchanges-table td:nth-child(2), #exchanges-table th:nth-child(2) { display: none; }
  .only-mobile { display: block; }
}
#connection-form { display: grid; gap: 16px; }
.toolbar > .toolbar-group:first-child { flex: 1; }
/* Agents toolbar: actions above filters, each its own row; rows wrap independently */
#agents-panel .toolbar { align-items: flex-start; }
#agents-panel .actions-row, #agents-panel .actions-row .toolbar-group { justify-content: flex-end; }
@media (max-width: 720px) { .toolbar select { flex: 1; } }

/* Reaction tasks use wrapping cards rather than a wide table. */
.panel, .toolbar-group, .reaction-list, .reaction-heading > * { min-width: 0; }
.reaction-list, .checkbox-list { display: grid; gap: 8px; }
.reaction-card { display: grid; gap: 8px; padding: 16px; overflow-wrap: anywhere; }
.reaction-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.reaction-count { flex-shrink: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
:is(.reaction-card, .progress-cell) progress { width: 100%; height: 6px; appearance: none; border: 0; border-radius: 3px; background: var(--line); overflow: hidden; }
:is(.reaction-card, .progress-cell) progress::-webkit-progress-bar { background: var(--line); }
:is(.reaction-card, .progress-cell) progress::-webkit-progress-value { background: var(--accent); }
:is(.reaction-card, .progress-cell) progress::-moz-progress-bar { background: var(--accent); }
.reaction-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.reaction-footer .actions { margin-left: auto; }
#report-dialog { width: min(520px, calc(100% - 32px)); }
#report-dialog h3 { font-size: 14px; }
#report-agents { max-height: 320px; overflow-y: auto; }
.report-mark { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.report-mark > .btn, .report-mark > .actions { margin-left: auto; }
#order-block summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 4px 0; }
#order-block[open] summary { margin-bottom: 12px; }
#reaction-work { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
#reaction-dialog select { width: 100%; height: 38px; }
#reaction-dialog .ms-trigger { min-width: 0; }
#reaction-dialog .dialog-actions, .report-mark .actions { flex-wrap: wrap; }
#reaction-order-form { gap: 12px; }
#publication-list .btn { justify-self: start; }
@media (max-width: 720px) {
  .toolbar > .toolbar-group { flex: 1 1 100%; }
  .toolbar .search { width: 100%; }
  #add-reaction { order: -1; width: 100%; }
  #reactions-panel .toolbar select { min-width: 0; max-width: 100%; flex: 1 1 calc(50% - 4px); }
  .reaction-heading { flex-wrap: wrap; }
  dialog { max-height: calc(100dvh - 32px); overflow-y: auto; }
}

/* exchange orders: how many a person says were placed; selects next to an input share the row */
.actions .count-input { width: 96px; height: 34px; flex: none; }
.with-action select { flex: 1; min-width: 0; }
.service-row { padding: 12px 0; }
.service-row > .btn { justify-self: start; }

/* --- review of the tabs: phones, footers, rows --------------------------------------------------- */
.danger-text, .btn.secondary.danger-text { color: var(--danger); }
#reaction-dialog > .sticky-actions #delete-reaction { margin-right: auto; }
#reaction-order-form > .btn { justify-self: end; }
.actions .count-input { height: 38px; }
.ms-placeholder { color: var(--muted); }  /* «Любой сотрудник» is a state, not a hint */
.file-pick { align-items: center; position: relative; }
.file-pick input.sr-only { left: 0; top: 0; width: 1px; height: 1px; }  /* field rules must not widen the hidden input */
.publication-row { cursor: pointer; }
.publication-row:hover { background: #f8fafc; }
.publication-row:focus-visible { outline: 3px solid #93c5fd; outline-offset: -3px; }
.publication-row a.details { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-bar { width: 100%; }
@media (max-width: 720px) {
  /* Agents: checkbox, the agent (status under it), quick copy, «⋯» — the columns a phone needs */
  /* Agents: a card per agent — checkbox, the agent (status under it), «⋯»; quick copy in a row below */
  #agents-table, #agents-table tbody { display: block; min-width: 0; }
  #agents-table thead { display: none; }
  #agents-table tbody tr { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; border-bottom: 1px solid var(--line); }
  #agents-table tbody td { border: 0; padding: 10px 12px 4px; }
  /* One agent card: check, agent (status and activity under it), quick copy, «⋯» — the rest is hidden */
  #agents-table :is(th, td):is(:nth-child(3), :nth-child(5), :nth-child(6), :nth-child(7)) { display: none; }
  #agents-table tbody td:nth-child(4) { grid-column: 2 / 4; grid-row: 2; padding: 0 12px 12px; }
  #agents-table tbody td.check-cell { grid-row: 1 / 3; }
  #agents-table .person { overflow-wrap: anywhere; }
  /* Journal: each event a block, no table to scroll sideways */
  #journal-table { min-width: 0; }
  #journal-table thead { display: none; }
  #journal-table, #journal-table tbody, #journal-table tr, #journal-table td { display: block; }
  #journal-table tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  #journal-table td { padding: 2px 0; border: 0; white-space: normal; min-width: 0; width: auto; max-width: none; }
  #journal-table td.when { font-size: 12px; }
  #journal-table td:nth-child(1), #journal-table td:nth-child(2) { display: inline; font-size: 12px; color: var(--muted); }
  #journal-table td:nth-child(2)::before { content: " · "; }
  #journal-table td.agent-cell.none { display: none; }
}

/* Task cards: who does it, what, how many; agents' cards also say what matters and who sees the task */
.task-cards { display: grid; gap: 8px; }
.task-card { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.task-card-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 110px 32px; gap: 8px; align-items: center; }
.task-card :is(.card-kind, .card-action, .card-count, .card-note) { width: 100%; height: 38px; }
.task-card-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.task-card .card-hint:empty { display: none; }
.task-card .card-remove[hidden] { display: none; }
.add-card { justify-self: start; color: var(--accent); }
.task-cards.editing .task-card-row { grid-template-columns: minmax(0, 1fr) 110px; }  /* one card: no kind, no ✕ */
@media (max-width: 720px) {
  .task-card-row { grid-template-columns: minmax(0, 1fr) 96px 32px; }
  .task-cards:not(.editing) .task-card-row .card-action { grid-column: 1 / -1; order: 4; }
  .task-card-extra { grid-template-columns: 1fr; }
}
dialog { overflow-x: hidden; }  /* sticky footers reach the edges with negative margins: never a sideways scroll */

/* Mailbox link: the account's mailbox in its card, the mailbox's accounts in its card, a line in the list */
.mail-line { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-status { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; overflow-wrap: anywhere; }
.mail-address { font-weight: 600; }
.mail-open { color: var(--accent-text); font-weight: 600; }
.mail-field .ms-trigger { max-width: 360px; }
.linked-list { display: grid; gap: 6px; }
.linked-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); text-align: left; }
.linked-row:hover { border-color: var(--line-strong); background: #fafbfd; }
.linked-row .person { flex: 1; min-width: 0; }

/* «Кто пользуется»: a person keeps one dot color; the dot carries the full name in its title */
.owner-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.owner-line > span:last-child { font-weight: 600; overflow-wrap: anywhere; }
.owner-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.owner-1 { background: var(--owner-1); } .owner-2 { background: var(--owner-2); }
.owner-3 { background: var(--owner-3); } .owner-4 { background: var(--owner-4); }
.owner-5 { background: var(--owner-5); } .owner-6 { background: var(--owner-6); }
.owner-7 { background: var(--owner-7); } .owner-8 { background: var(--owner-8); }
tr.inactive .owner-dot { opacity: .55; }

/* «Мои агенты» in the filters row; the badge in a picker option hugs the far edge */
.toolbar .mine-filter { align-items: center; height: 38px; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.toolbar .mine-filter input { margin-top: 0; }
.ms-option .ms-badge { margin-left: auto; }
