:root {
  --ink: #18211b;
  --muted: #667269;
  --paper: #f4f6f1;
  --surface: #ffffff;
  --line: #dfe5dc;
  --brand: #1f6f50;
  --brand-dark: #15533b;
  --within: #2f7d4c;
  --warning: #b77513;
  --overdue: #b4472f;
  --critical: #8f2635;
  --shadow: 0 14px 36px rgba(31, 47, 36, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 90% 0, #e4eee6 0, transparent 32rem), var(--paper); }
button, input, select, textarea { font: inherit; }
.topbar { min-height: 62px; padding: 10px clamp(16px, 3vw, 42px); display: flex; align-items: center; justify-content: space-between; background: #172820; color: white; }
.topbar h1 { margin: 1px 0 0; font-size: clamp(21px, 2.5vw, 27px); letter-spacing: -.04em; }
.eyebrow { margin: 0; font-size: 9px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; color: #80af95; }
.live { display: flex; align-items: center; gap: 7px; font-size: 11px; color: #d9e9df; }
.live span { width: 7px; height: 7px; border-radius: 50%; background: #55cf83; box-shadow: 0 0 0 4px rgba(85,207,131,.12); }
.topbar-actions, .session-summary { display: flex; align-items: center; gap: 10px; }
.session-summary { padding-left: 10px; border-left: 1px solid rgba(255,255,255,.18); }
.session-summary strong { font-size: 12px; }
.session-summary > span { color: #b8d2c2; font-size: 10px; }
.session-summary .button.secondary { color: white; background: rgba(255,255,255,.12); }
.tabs { display: flex; gap: 6px; padding: 7px clamp(16px, 3vw, 42px) 0; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.72); backdrop-filter: blur(10px); }
.tab { border: 0; background: transparent; padding: 8px 12px 9px; color: var(--muted); font-size: 12px; font-weight: 750; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand-dark); border-color: var(--brand); }
main { max-width: 1480px; margin: 0 auto; padding: 18px clamp(14px, 3vw, 38px) 40px; }
.view { display: none; }
.view.active { display: block; }
.section-heading { display: flex; justify-content: space-between; gap: 16px; align-items: end; margin-bottom: 13px; }
h2 { margin: 3px 0 0; font-size: clamp(23px, 3vw, 31px); letter-spacing: -.04em; }
h3 { margin: 0 0 5px; font-size: 15px; }
.muted { color: var(--muted); font-size: 11px; }
.metrics { display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)); gap: 7px; margin-bottom: 11px; }
.metrics article { background: var(--surface); border: 1px solid var(--line); border-top: 3px solid #79837c; border-radius: 10px; padding: 8px 11px; box-shadow: 0 5px 16px rgba(31, 47, 36, .05); }
.metrics span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; }
.metrics strong { display: block; margin-top: 2px; font-size: 22px; line-height: 1.08; letter-spacing: -.035em; }
.metrics .within { border-top-color: var(--within); }
.metrics .warning { border-top-color: var(--warning); }
.metrics .overdue { border-top-color: var(--overdue); }
.metrics .critical { border-top-color: var(--critical); }
.filters { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 7px; background: #eaf0e8; padding: 8px; border: 1px solid #d8e2d7; border-radius: 10px 10px 0 0; }
.report-filters { grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); border-radius: 10px; margin-bottom: 11px; }
.report-filters .button { align-self: end; white-space: nowrap; }
label { display: grid; gap: 4px; color: #4d5b51; font-size: 10px; font-weight: 750; }
input, select, textarea { width: 100%; border: 1px solid #cbd5cc; border-radius: 7px; background: white; min-height: 33px; padding: 5px 8px; color: var(--ink); font-size: 12px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid rgba(31,111,80,.2); border-color: var(--brand); }
.table-shell { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 10px 10px; box-shadow: 0 7px 20px rgba(31, 47, 36, .06); }
table { width: 100%; border-collapse: collapse; }
.waiting-table { table-layout: fixed; }
.waiting-table th { position: relative; }
.waiting-table td { overflow-wrap: anywhere; }
.waiting-table .identity-copy { max-width: 100%; }
.column-resizer { position: absolute; z-index: 2; top: 0; right: -6px; width: 13px; height: 100%; cursor: col-resize; touch-action: none; }
.column-resizer::after { content: ""; position: absolute; top: 18%; bottom: 18%; left: 6px; width: 1px; background: #ccd5ce; }
.column-resizer:hover::after, .column-resizer.active::after { width: 2px; background: var(--brand); }
body.resizing-columns { cursor: col-resize; user-select: none; }
th { text-align: left; padding: 8px 10px; font-size: 9px; letter-spacing: .05em; text-transform: uppercase; color: #6b756e; background: #f7f9f6; white-space: nowrap; }
td { padding: 8px 10px; border-top: 1px solid #edf0ec; font-size: 11px; vertical-align: middle; }
.identity strong, .identity span { display: block; }
.identity span { margin-top: 2px; color: var(--muted); font-size: 9px; }
.identity-copy { border: 0; padding: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: copy; }
.identity-copy:hover strong { color: var(--brand-dark); text-decoration: underline; text-underline-offset: 2px; }
.identity-copy:focus-visible { border-radius: 4px; outline: 3px solid rgba(31,111,80,.2); }
.context-policy-button { cursor: pointer; }
.context-policy-button:hover strong { color: var(--brand-dark); text-decoration: underline; text-underline-offset: 2px; }
.context-preview-trigger { cursor: pointer; }
.context-preview {
  position: fixed;
  z-index: 40;
  width: min(390px, calc(100vw - 16px));
  max-height: min(470px, calc(100vh - 16px));
  overflow: auto;
  padding: 11px;
  border: 1px solid #cbd7cd;
  border-radius: 11px;
  color: var(--ink);
  background: white;
  box-shadow: 0 18px 45px rgba(24, 42, 31, .24);
}
.context-preview-header { display: grid; gap: 2px; margin-bottom: 9px; padding: 0 2px; }
.context-preview-header strong { font-size: 13px; line-height: 1.3; }
.context-preview-header span { color: var(--muted); font-size: 10px; }
.context-telegram-link { color: var(--brand-dark); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; overflow-wrap: anywhere; }
.context-telegram-link:hover { color: var(--brand); }
.context-telegram-web { justify-self: start; color: var(--muted); font-size: 11px; text-underline-offset: 2px; }
.context-link-note { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.context-telegram-link:focus-visible, .context-telegram-web:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 2px; }
.context-preview-list { display: grid; gap: 6px; }
.context-preview-message {
  padding: 7px 9px;
  border: 1px solid #e3e9e2;
  border-radius: 8px;
  background: #f7f9f6;
}
.context-preview-message.employee { border-color: #cfe1d3; background: #edf6ef; }
.context-preview-message.client { border-color: #dce2ec; background: #f2f5fa; }
.context-preview-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.context-preview-meta strong { overflow: hidden; color: #526057; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.context-preview-message.employee .context-preview-meta strong { color: var(--brand-dark); }
.context-preview-meta time { flex: 0 0 auto; color: #7a857d; font-size: 9px; font-variant-numeric: tabular-nums; }
.context-preview-message p { margin: 3px 0 0; font-size: 11px; line-height: 1.38; white-space: pre-wrap; overflow-wrap: anywhere; }
.context-preview-state { margin: 0; padding: 16px 8px; color: var(--muted); font-size: 11px; text-align: center; }
.clipboard-helper { position: fixed; left: -9999px; top: 0; opacity: 0; }
.timer { font-variant-numeric: tabular-nums; font-size: 16px; font-weight: 800; letter-spacing: .015em; }
.badge { display: inline-flex; border-radius: 999px; padding: 3px 7px; font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .035em; background: #edf0ed; color: #4f5c53; }
.badge.within { background: #e4f3e7; color: var(--within); }
.badge.warning { background: #fff1cf; color: #96600c; }
.badge.overdue { background: #fbe4df; color: var(--overdue); }
.badge.critical { background: #f7dce2; color: var(--critical); }
.badge.scheduled { background: #e8ecf5; color: #4e6088; }
.badge.manual { background: #e7e5f4; color: #584a8a; }
.badge.undone { background: #edf0ed; color: #68736b; }
.case-status { position: relative; display: inline-block; }
.case-status-toggle { border: 0; padding: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.case-status-toggle:hover { filter: brightness(.94); }
.case-action-menu .button.no-response-action { min-height: 44px; width: 100%; white-space: normal; font-size: 13px; line-height: 1.35; color: #8a2633; background: #f7dce2; }
.no-response-action:hover { color: white; background: var(--critical); }
.empty { min-height: 145px; display: grid; place-content: center; text-align: center; gap: 5px; color: var(--muted); }
.empty[hidden] { display: none; }
.empty strong { color: var(--ink); font-size: 15px; }
.report-metrics { margin-top: 0; }
.report-metrics strong { font-size: clamp(18px, 2vw, 22px); }
.insight { margin: 0 0 11px; padding: 9px 12px; border: 1px solid #cfe0d2; border-left: 3px solid var(--brand); border-radius: 8px; background: #eef5ef; color: #3d5345; font-size: 11px; }
.insight:empty { display: none; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.panel-heading h3, .panel-heading p { margin-top: 0; }
.panel-heading > strong { color: var(--brand-dark); font-size: 11px; white-space: nowrap; }
.report-comparisons td:nth-child(n+2), .report-comparisons th:nth-child(n+2) { text-align: right; }
.history-panel .timer { font-size: 15px; }
.metric-detail { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 600; }
.manual-comment { min-width: 220px; max-width: 420px; white-space: pre-wrap; overflow-wrap: anywhere; }
@keyframes spin { to { transform: rotate(360deg); } }
.history-pagination { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); font-size: 11px; }
.history-pagination span { min-width: 170px; text-align: center; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; margin-bottom: 11px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 13px; box-shadow: 0 7px 20px rgba(31, 47, 36, .06); }
.system-status-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.system-status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 11px; margin-bottom: 14px; }
.system-status-card { min-height: 112px; padding: 15px; border: 1px solid var(--line); border-left: 4px solid #88958a; border-radius: 10px; background: var(--surface); box-shadow: 0 7px 20px rgba(31, 47, 36, .06); }
.system-status-card.ok { border-left-color: var(--within); }
.system-status-card.down { border-left-color: var(--critical); }
.system-status-card.paused { border-left-color: var(--warning); }
.system-status-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.system-status-card h3 { margin: 0; font-size: 14px; }
.system-status-card p { margin: 12px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.system-status-pill { display: inline-flex; flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; color: #526057; background: #edf0ed; font-size: 10px; font-weight: 800; }
.system-status-card.ok .system-status-pill { color: var(--within); background: #e4f3e7; }
.system-status-card.down .system-status-pill { color: var(--critical); background: #f7dce2; }
.system-status-card.paused .system-status-pill { color: #96600c; background: #fff1cf; }
.panel.full { margin-bottom: 11px; }
.form-grid { display: grid; gap: 8px; margin-top: 10px; }
.telegram-account-form { display: grid; grid-template-columns: minmax(220px, 360px) auto; align-items: end; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.telegram-account-form[hidden] { display: none; }
.telegram-code-intro { display: grid; align-self: center; }
.telegram-code-intro strong { font-size: 12px; }
.telegram-account-status { display: grid; gap: 3px; }
.telegram-account-status .muted { max-width: 300px; }
.button { border: 0; border-radius: 7px; min-height: 33px; padding: 6px 10px; background: var(--brand); color: white; font-size: 11px; font-weight: 800; cursor: pointer; }
.button:hover { background: var(--brand-dark); }
.button.secondary { color: var(--brand-dark); background: #e4eee7; }
.button.danger { color: #8a2633; background: #f7dce2; }
.button.danger:hover { color: white; background: var(--critical); }
.button.small { min-height: 29px; padding: 4px 8px; font-size: 10px; }
.form-actions, .row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.auth-shell { min-height: calc(100vh - 62px); display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(100%, 390px); }
.auth-card h2 { margin-bottom: 7px; }
.auth-card .form-grid { margin-top: 16px; }
.settings-session { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 7px; }
.switch-row { display: flex; align-items: center; gap: 7px; margin-top: 9px; }
.switch-row input { width: 16px; min-height: 16px; accent-color: var(--brand); }
.compact-table { overflow-x: auto; margin: 8px -13px -13px; border-radius: 0 0 10px 10px; }
.compact-table select { min-width: 155px; }
.compact-table .topic-title { min-width: 190px; }
.group-tree { display: grid; gap: 8px; margin-top: 10px; }
.group-browser-controls { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px) auto; gap: 8px; align-items: end; margin-top: 10px; }
.group-card { overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: #fbfcfa; }
.group-summary { display: grid; grid-template-columns: minmax(250px, 1.6fr) minmax(180px, .8fr) minmax(170px, .8fr) auto; gap: 8px; align-items: end; padding: 9px; }
.group-toggle { display: flex; align-items: center; gap: 11px; align-self: stretch; border: 0; border-radius: 9px; padding: 7px 9px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.group-toggle:hover { background: #edf3ed; }
.chevron { display: inline-grid; place-content: center; width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%; background: #e4eee7; color: var(--brand-dark); font-size: 24px; line-height: 1; transition: transform .16s ease; }
.group-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.group-identity strong, .group-identity small { display: block; }
.group-identity strong { font-size: 15px; }
.group-identity small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.group-topics { overflow-x: auto; border-top: 1px solid var(--line); background: white; }
.group-topics[hidden] { display: none; }
.group-topics table { min-width: 760px; }
.group-topics .topic-title { min-width: 200px; }
.group-topics .topic-status { min-width: 210px; }
.inherit-note { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; font-weight: 600; }
.stack-list { display: grid; gap: 6px; margin-top: 9px; }
.stack-item { display: flex; justify-content: space-between; align-items: center; gap: 9px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; }
.schedule-form { display: grid; gap: 10px; margin-top: 10px; }
.schedule-controls { display: grid; grid-template-columns: repeat(3, minmax(150px, 220px)); gap: 8px; }
.schedule-form > .button { justify-self: start; min-width: 160px; }
.client-action-menu { position: fixed; z-index: 30; display: grid; width: min(240px, calc(100vw - 16px)); padding: 7px; border: 1px solid #cbd7cd; border-radius: 9px; background: white; box-shadow: 0 14px 34px rgba(24, 42, 31, .2); }
.client-action-menu > strong, .client-action-menu > span { padding: 3px 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-action-item { border: 0; border-radius: 6px; padding: 8px 9px; color: var(--ink); background: transparent; font-size: 11px; font-weight: 700; text-align: left; cursor: pointer; }
.client-action-item:hover, .client-action-item:focus-visible { background: #eaf2eb; color: var(--brand-dark); }
.client-action-item.selected { color: var(--brand-dark); background: #e4eee7; }
.modal-dialog { width: min(430px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 11px; padding: 16px; color: var(--ink); background: white; box-shadow: 0 20px 55px rgba(20, 38, 27, .28); }
.modal-dialog::backdrop { background: rgba(16, 28, 21, .42); backdrop-filter: blur(2px); }
.modal-dialog h3 { margin-top: 5px; }
.modal-dialog .form-grid { margin-top: 0; }
.chat-context-button { display: none; margin-top: 8px; min-height: 44px; min-width: 64px; }
.chat-context-dialog { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow: hidden; }
.chat-context-dialog[open] { display: flex; flex-direction: column; gap: 12px; }
.chat-context-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; }
.chat-context-toolbar h3 { margin: 0; }
.chat-context-toolbar .button { min-height: 44px; }
.chat-context-content { min-height: 0; overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
.chat-context-content .context-preview-header strong { font-size: 15px; }
.chat-context-content .context-preview-header span { font-size: 12px; }
.chat-context-content .context-preview-message p { font-size: 14px; line-height: 1.5; }
.chat-context-content .context-preview-meta { flex-wrap: wrap; gap: 4px 10px; }
.chat-context-content .context-preview-meta strong { font-size: 12px; white-space: normal; overflow-wrap: anywhere; }
.chat-context-content .context-preview-meta time { font-size: 11px; }
.chat-context-content .context-preview-state { font-size: 14px; }
.undo-action { position: fixed; z-index: 20; right: 18px; bottom: 18px; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; color: white; background: #172820; font-size: 11px; box-shadow: var(--shadow); }
.undo-action > strong { min-width: 18px; text-align: center; font-size: 14px; }
.undo-action .button.secondary { color: var(--brand-dark); background: #e4eee7; }
.toast { position: fixed; z-index: 21; right: 18px; bottom: 72px; max-width: 340px; padding: 9px 12px; border-radius: 8px; color: white; background: #172820; font-size: 11px; box-shadow: var(--shadow); transform: translateY(120px); opacity: 0; transition: .2s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--critical); }
@media (max-width: 850px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .filters, .settings-grid, .report-filters, .group-browser-controls { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  .group-summary { grid-template-columns: 1fr; }
  th, td { padding: 8px; }
}
@media (max-width: 520px) {
  .telegram-account-form { grid-template-columns: 1fr; }
  .live { display: none; }
  .session-summary { border-left: 0; padding-left: 0; }
  .session-summary > span { display: none; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics article:first-child { grid-column: 1 / -1; }
  .schedule-controls { grid-template-columns: 1fr; }
}

/* Mobile cards override desktop column widths, including saved inline widths. */
@media (max-width: 700px) {
  .topbar, .topbar-actions, .session-summary { flex-wrap: wrap; }
  .topbar-actions { justify-content: flex-end; }
  .tabs { overflow-x: auto; }
  .tab { flex-shrink: 0; }
  .section-heading, .panel-heading { flex-wrap: wrap; align-items: flex-start; }
  .panel-heading > strong { white-space: normal; }
  .group-toggle, .group-identity { min-width: 0; overflow-wrap: anywhere; }
  .history-pagination { flex-wrap: wrap; gap: 8px; padding: 10px 0; }
  .waiting-table { display: block; width: 100% !important; min-width: 0 !important; }
  .waiting-table colgroup, .waiting-table thead { display: none; }
  .waiting-table tbody { display: grid; gap: 8px; padding: 10px; background: var(--paper); }
  .waiting-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "client context" "employee started" "elapsed chat" "status chat";
    gap: 6px 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
  }
  .waiting-table td { display: block; min-width: 0; padding: 0; border: 0; font-size: 13px; }
  .waiting-table td::before, .waiting-table .case-context-cell > .context-preview-trigger::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0;
  }
  .waiting-table td:nth-child(1) { grid-area: client; }
  .waiting-table td:nth-child(2) { grid-area: employee; }
  .waiting-table td:nth-child(3) { grid-area: context; }
  .waiting-table td:nth-child(4) { grid-area: started; }
  .waiting-table td:nth-child(5) { grid-area: elapsed; }
  .waiting-table td:nth-child(6) { grid-area: status; }
  .waiting-table td:nth-child(6)::before { display: none; }
  .waiting-table .case-context-cell { display: contents; }
  .waiting-table .case-context-cell::before { display: none; }
  .waiting-table .case-context-cell > .context-preview-trigger { grid-area: context; align-self: start; min-width: 0; }
  .waiting-table .case-context-cell > .context-preview-trigger::before { content: "Контекст"; }
  .waiting-table .chat-context-button { display: inline-flex; align-items: center; justify-content: center; grid-area: chat; justify-self: start; align-self: start; width: 72px; max-width: 100%; height: 44px; min-width: 0; margin-top: 0; font-size: 13px; }
  .waiting-table .identity span { font-size: 10px; }
  .waiting-table .identity-copy { width: 100%; }
  .waiting-table .identity-copy strong, .waiting-table .identity-copy span, .waiting-table .cell-text { display: block; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .waiting-table .timer { font-size: clamp(16px, 4.6vw, 19px); white-space: nowrap; }
  .waiting-table .case-status { display: flex; min-height: 44px; align-items: center; }
  .waiting-table .case-status-toggle { display: inline-flex; align-items: center; min-height: 44px; max-width: 100%; }
  .waiting-table .badge { white-space: normal; overflow-wrap: anywhere; }
  .toast, .undo-action { max-width: calc(100vw - 32px); }
  .undo-action { flex-wrap: wrap; }
}
