/* ============================================================
   THE BOT CONSOLE — FOUNDATION (P10A)
   ------------------------------------------------------------
   C2.5D-DASHBOARD-FOUNDATION-P2: the token dictionary that used to live
   here (39 colors + both themes) moved to /shared-ui/tokens.css, the
   platform's canonical Design Tokens v1 -- see
   docs/architecture/DASHBOARD-ARCHITECTURE-P1.md §T. dashboard.html
   <link>s that file before this one, so every declaration below still
   resolves to the exact same values as before -- this file now only
   ever CONSUMES tokens, never defines them.
   ============================================================ */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: sans-serif;
  background: var(--bg);
}

.hidden { display: none !important; }

/* Login page */
.login-box {
  max-width: 320px;
  margin: 120px auto;
  padding: 24px;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 4px 16px var(--shadow-color);
  text-align: center;
}

@media (max-width: 480px) {
  .login-box {
    max-width: none;
    margin: 60px 16px;
  }
}

.login-box form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-box input {
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 14px;
}

.login-box button {
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 14px;
  cursor: pointer;
}

.error { color: var(--danger); font-size: 13px; }

/* Dashboard */
.dashboard {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  font-weight: bold;
}

.organization-name {
  font-weight: normal;
  font-size: 12px;
  color: var(--ink-muted);
}

.widget-snippet-toggle {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.widget-snippet-toggle button {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}

.widget-snippet-box {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
}

.widget-snippet-box code {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-size: 11px;
  word-break: break-all;
  white-space: pre-wrap;
}

.sidebar-header button {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
}

.conversation-list-toggle {
  display: flex;
  border-bottom: 1px solid var(--border);
}
/* TGMAX-IMPL-1: channel filter (admin dashboard outside the console shell) */
.list-channel-filter { flex: 0 1 auto; max-width: 140px; margin-left: 4px; font-size: 12px; }
.conversation-list-empty { padding: 16px; color: #666; font-size: 13px; }

.list-view-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px;
  font-size: 13px;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.list-view-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface-alt);
  cursor: pointer;
}

.conversation-item:hover { background: var(--bg); }
.conversation-item.active {
  background: var(--accent-wash);
  box-shadow: inset 3px 0 0 var(--accent);
}
.conversation-item.active:hover { background: var(--accent-wash); }

.conversation-header-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 2px;
}

.conversation-visitor { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }

.conversation-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}

.conversation-online-dot.online { background: var(--success); }

.conversation-repeat-tag {
  font-size: 10px;
  font-weight: 600;
  color: var(--info-ink);
  background: var(--info-wash);
  padding: 1px 5px;
  border-radius: 4px;
}

.channel-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  text-transform: uppercase;
}

.channel-tag-avito {
  color: var(--accent-soft);
  background: var(--accent-wash);
}

.channel-tag-widget {
  color: var(--success);
  background: var(--success-wash);
}

.channel-tag-telegram {
  color: var(--accent-soft);
  background: var(--accent-wash);
}

.bulk-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  background: var(--danger-wash);
  border-bottom: 1px solid var(--danger-edge);
  font-size: 13px;
  color: var(--danger-ink);
}

.bulk-actions button {
  border: 1px solid var(--danger-edge);
  background: var(--surface);
  color: var(--danger);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}

.bulk-actions button:hover {
  background: var(--danger-wash);
}

.conversation-select-checkbox {
  margin-right: 6px;
}

.conversation-timestamp {
  font-size: 11px;
  color: var(--ink-faint);
  flex-shrink: 0;
}

.conversation-id-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface-alt);
  border-radius: 4px;
  padding: 1px 6px;
}

.ai-suggestion-compare {
  margin-top: 6px;
}

.ai-suggestion-tag {
  display: inline-block;
  font-size: 11px;
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  cursor: default;
}

.ai-suggestion-unedited {
  background: var(--success-wash);
  color: var(--success-ink);
}

.ai-suggestion-edited {
  background: var(--warning-wash);
  color: var(--warning-ink);
  cursor: pointer;
  font-family: inherit;
}

.ai-suggestion-original {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  font-size: 13px;
  color: var(--ink-muted);
  white-space: pre-line;
}

.ai-suggestion-original.hidden {
  display: none;
}

.org-chat-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--surface-alt);
}

.org-chat-group-header:hover {
  background: var(--surface-alt);
}

.org-chat-group-toggle {
  color: var(--ink-muted);
  font-size: 11px;
  width: 10px;
  flex-shrink: 0;
}

.org-chat-group-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-chat-group-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-wash);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.org-chat-group-autosend-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--warning-ink);
  background: var(--warning-wash);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.org-chat-group-draft-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--info-ink);
  background: var(--info-wash);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.org-chat-group-overdue-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--danger-ink);
  background: var(--danger-wash);
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.conversation-item-overdue {
  border-left: 3px solid var(--danger);
  background: var(--danger-wash);
}

.conversation-item-overdue:hover {
  background: var(--danger-wash);
}

.conversation-unanswered-badge {
  margin-top: 4px;
  margin-right: 4px;
  font-size: 11px;
  font-weight: 600;
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
}

.unanswered-badge-waiting {
  background: var(--surface-alt);
  color: var(--ink-muted);
}

.unanswered-badge-overdue {
  background: var(--danger-wash);
  color: var(--danger-ink);
}

.org-chat-group-items.hidden {
  display: none;
}

.org-chat-group-items .conversation-item {
  padding-left: 30px;
}
.conversation-preview {
  font-size: 13px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-autoresponse-badge {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
}

.autoresponse-badge-countdown {
  background: var(--warning-wash);
  color: var(--warning-ink);
}

.autoresponse-badge-draft {
  background: var(--info-wash);
  color: var(--info-ink);
}

/* TB-CCR-RETRY-POLICY-1 */
.autoresponse-badge-retry {
  background: var(--warning-wash);
  color: var(--warning-ink);
}

.autoresponse-badge-stopped {
  background: var(--danger-wash);
  color: var(--danger-ink);
}

/* P3.1 — conversation ownership in the list: MONITORING (a vertical answers) / owner unknown (locked). */
.ownership-badge-monitor {
  background: var(--warning-wash);
  color: var(--warning-ink);
}

.ownership-badge-unresolved {
  background: var(--danger-wash);
  color: var(--danger-ink);
}

.autoresponse-retry-btn {
  margin-top: 4px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--danger-edge);
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  /* Without this, a flex child's default min-height is its content size, not
     0 — so a long conversation would refuse to shrink and push the reply
     form/controls below it clean out of the fixed-height frame instead of
     just scrolling. Same reasoning on .chat-view/.chat-messages below. */
  min-height: 0;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
}

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
}

.chat-message {
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 60%;
  font-size: 14px;
  white-space: pre-line;
}

.chat-message a {
  color: inherit;
  text-decoration: underline;
}

.chat-message-author {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.7;
  margin-bottom: 2px;
}

.chat-message-visitor {
  background: var(--surface-alt);
  color: var(--ink);
  margin-right: auto;
}

.chat-message-operator {
  background: var(--accent);
  color: var(--on-accent);
  margin-left: auto;
}

.chat-message-deleted {
  opacity: 0.6;
  font-style: italic;
}

.chat-message-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.chat-message-actions button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  color: inherit;
  opacity: 0.75;
  text-decoration: underline;
}

.canned-picker {
  display: flex;
  gap: 8px;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}

.canned-picker select {
  flex: 1;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

.canned-manager {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.canned-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  max-height: 140px;
  overflow-y: auto;
}

.canned-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}

.canned-list-item-actions button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--accent);
  margin-left: 6px;
}

.canned-form {
  display: flex;
  gap: 6px;
}

.canned-form input {
  flex: 1;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13px;
}

.canned-form button {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  font-size: 13px;
}

.autoresponse-control {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 8px 20px 0;
  font-size: 13px;
  color: var(--ink-muted);
}

.autoresponse-control label {
  display: flex;
  align-items: center;
  gap: 4px;
}

.autoresponse-control select,
.autoresponse-control input[type="number"] {
  padding: 5px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13px;
  width: 56px;
}

.autosend-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 20px 0;
  padding: 8px 12px;
  background: var(--warning-wash);
  border: 1px solid var(--warning-edge);
  border-radius: 8px;
  font-size: 13px;
  color: var(--warning-ink);
}

.autosend-banner button {
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink);
}

.reply-form {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  gap: 8px;
}

.reply-form textarea {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 40px;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.4;
}

.reply-form button {
  padding: 10px 18px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.visitor-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
  color: var(--ink-muted);
}

.visitor-online-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}

.visitor-online-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
}

.visitor-online-badge.online { color: var(--success); }
.visitor-online-badge.online .dot { background: var(--success); }

.visitor-repeat-badge {
  color: var(--info-ink);
  background: var(--info-wash);
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 600;
}

.visitor-device { color: var(--ink-muted); }

.visitor-page-link {
  color: var(--accent);
  text-decoration: none;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.visitor-page-link:hover { text-decoration: underline; }

.visitor-info-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.visitor-info-actions button {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink);
}

.visitor-info-actions button:hover { background: var(--surface-alt); }

.visitor-info-actions .delete-btn {
  color: var(--danger);
  border-color: var(--danger-edge);
}
.visitor-info-actions .delete-btn:hover { background: var(--danger-wash); }

.chat-mobile-header {
  display: none;
}

.chat-back-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
}

/* Phones: the fixed sidebar+chat-panel side-by-side layout doesn't fit — stack
   them full-width instead and show only one at a time (classic master/detail
   pattern), toggled by adding/removing .mobile-chat-open on .dashboard from JS
   whenever a conversation is opened/closed. */
@media (max-width: 768px) {
  .dashboard {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
  }

  .chat-panel {
    display: none;
  }

  .dashboard.mobile-chat-open .sidebar {
    display: none;
  }

  .dashboard.mobile-chat-open .chat-panel {
    display: flex;
  }

  .chat-mobile-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
  }

  .chat-message {
    max-width: 85%;
  }

  .chat-messages {
    padding: 12px;
  }

  .canned-picker,
  .autoresponse-control,
  .visitor-info,
  .reply-form {
    padding-left: 12px;
    padding-right: 12px;
  }

  .visitor-page-link { max-width: 140px; }

  /* Bigger touch targets for buttons that are comfortably clickable with a
     mouse but too small to reliably tap. */
  .conversation-item {
    padding: 14px 16px;
  }

  .reply-form button,
  .canned-form button,
  .add-operator-form button {
    padding: 10px 16px;
  }

  /* Mobile text is ~20% larger than desktop across the board — small
     touch-screen text was hard to read, this mirrors every base font-size
     declaration above at 1.2x rather than a blanket html{font-size} scale
     (most selectors here use fixed px, which wouldn't inherit a root bump).*/
  .login-box input { font-size: 16.8px; }
  .login-box button { font-size: 16.8px; }
  .error { font-size: 15.6px; }
  .organization-name { font-size: 14.4px; }
  .widget-snippet-toggle button { font-size: 15.6px; }
  .widget-snippet-box { font-size: 14.4px; }
  .widget-snippet-box code { font-size: 13.2px; }
  .sidebar-header button { font-size: 15.6px; }
  .list-view-btn { font-size: 15.6px; }
  .conversation-visitor { font-size: 16.8px; }
  .conversation-repeat-tag { font-size: 12px; }
  .channel-tag { font-size: 12px; }
  .bulk-actions { font-size: 15.6px; }
  .bulk-actions button { font-size: 14.4px; }
  .conversation-timestamp { font-size: 13.2px; }
  .conversation-id-tag { font-size: 13.2px; }
  .ai-suggestion-tag { font-size: 13.2px; }
  .ai-suggestion-original { font-size: 15.6px; }
  .org-chat-group-header { font-size: 16.8px; }
  .org-chat-group-toggle { font-size: 13.2px; }
  .org-chat-group-count { font-size: 13.2px; }
  .org-chat-group-autosend-badge { font-size: 13.2px; }
  .org-chat-group-draft-badge { font-size: 13.2px; }
  .org-chat-group-overdue-badge { font-size: 13.2px; }
  .conversation-unanswered-badge { font-size: 13.2px; }
  .conversation-preview { font-size: 15.6px; }
  .conversation-autoresponse-badge { font-size: 13.2px; }
  .chat-message { font-size: 16.8px; }
  .chat-message-author { font-size: 13.2px; }
  .chat-message-actions button { font-size: 13.2px; }
  .canned-list-item { font-size: 15.6px; }
  .canned-list-item-actions button { font-size: 15.6px; }
  .canned-form input { font-size: 15.6px; }
  .canned-form button { font-size: 15.6px; }
  .autoresponse-control { font-size: 15.6px; }
  .autoresponse-control select,
.autoresponse-control input[type="number"] { font-size: 15.6px; }
  .autosend-banner { font-size: 15.6px; }
  .autosend-banner button { font-size: 14.4px; }
  .reply-form textarea { font-size: 16.8px; }
  .visitor-info { font-size: 14.4px; }
  .visitor-info-actions button { font-size: 14.4px; }
  .chat-back-btn { font-size: 16.8px; }
  .attach-btn { font-size: 19.2px; }
  .attachment-preview { font-size: 15.6px; }
  .attachment-preview button { font-size: 15.6px; }
}

.attach-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 0 12px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.attach-btn:hover {
  background: var(--bg);
}

.attach-btn.hidden {
  display: none;
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 20px;
  font-size: 13px;
  color: var(--ink-muted);
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.attachment-preview.hidden {
  display: none;
}

.attachment-preview button {
  border: none;
  background: none;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0 4px;
}

.chat-message-attachment {
  display: block;
  max-width: 260px;
  max-height: 260px;
  border-radius: 10px;
  margin-bottom: 6px;
  object-fit: cover;
}

/* Слой компонентов и состояний вынесен в console-foundation.css:
   admin.css подключается ПОСЛЕ этого файла, и при равной
   специфичности его правила перебивали бы состояния. Foundation
   должен грузиться последним на обеих страницах. */
