/* ============================================================
   CSS Custom Properties — Apple-inspired Light Theme
   ============================================================ */
:root {
  --bg-primary:    #f5f5f7;   /* Apple light gray */
  --bg-secondary:  #ffffff;
  --bg-tertiary:   #f0f0f2;
  --bg-hover:      #e8e8ed;
  --text-primary:  #1d1d1f;
  --text-secondary:#6e6e73;
  --text-muted:    #aeaeb2;
  --accent:        #007aff;   /* iOS blue */
  --accent-hover:  #0056cc;
  --accent-light:  #e8f0fe;
  --border:        #d2d2d7;
  --border-focus:  #007aff;
  --status-open:   #34c759;   /* iOS green */
  --status-replied:#007aff;   /* iOS blue */
  --status-closed: #8e8e93;
  --bubble-in:     #e9e9eb;   /* iMessage gray */
  --bubble-out:    #007aff;   /* iMessage blue */
  --bubble-out-text:#ffffff;
  --status-read:   #007aff;
  --shadow-sm:     0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg:     0 8px 24px rgba(0,0,0,0.12);
  --radius-sm:     10px;
  --radius-md:     14px;
  --radius-lg:     20px;
}

/* ============================================================
   Dark Theme Override
   ============================================================ */
[data-theme="dark"] {
  --bg-primary: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --bg-tertiary: #3a3a3c;
  --bg-hover: #48484a;
  --text-primary: #f5f5f7;
  --text-secondary: #aeaeb2;
  --text-muted: #636366;
  --border: #3a3a3c;
  --accent-light: #1a3a5c;
  --bubble-in: #3a3a3c;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

[data-theme="dark"] .conversation-header,
[data-theme="dark"] .monitor-status-bar {
  background: rgba(44,44,46,0.85);
}

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  line-height: 1;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.47;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  /* iOS safe areas — bottom handled by reply-area */
  padding-top: env(safe-area-inset-top, 0px);
}

/* ============================================================
   App Shell
   ============================================================ */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ============================================================
   Chat Sidebar
   ============================================================ */
.chat-sidebar {
  width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  min-height: 56px;
}

.sidebar-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.monitor-status {
  font-size: 16px;
  color: var(--text-muted);
  cursor: default;
  transition: color 0.3s;
}

/* ============================================================
   Search
   ============================================================ */
.search-wrapper {
  padding: 0 16px 10px;
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: box-shadow 0.2s;
}

.search-input::placeholder { color: var(--text-muted); }
.search-input:focus {
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

/* ============================================================
   Chat List
   ============================================================ */
.chat-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* ============================================================
   Chat List Item
   ============================================================ */
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 0.5px solid rgba(0,0,0,0.08);
  min-height: 64px;
  transition: background 0.1s;
  user-select: none;
}

.chat-item:active { background: var(--bg-hover); }
.chat-item:hover { background: rgba(0,0,0,0.02); }
.chat-item.active {
  background: var(--accent-light);
}

/* Avatar */
.chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  text-transform: uppercase;
  position: relative;
}
.chat-avatar--purple { background: #af52de; }
.chat-avatar--pink   { background: #ff2d55; }
.chat-avatar--blue   { background: #007aff; }
.chat-avatar--green  { background: #34c759; }
.chat-avatar--orange { background: #ff9500; }
.chat-avatar--teal   { background: #5ac8fa; }

.chat-avatar .avatar-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
}

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-name {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  color: var(--text-primary);
}

.chat-time {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.chat-preview {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.unread-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.chat-list-empty, .chat-list-loading {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
}

/* ============================================================
   Client Tags & Score
   ============================================================ */
.client-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 4px;
  flex-shrink: 0;
}
.client-tag--hot  { background: #ffe5e5; color: #ff3b30; }
.client-tag--warm { background: #fff4e5; color: #ff9500; }
.client-tag--cold { background: #e5f2ff; color: #007aff; }
.client-score { font-size: 11px; color: var(--text-muted); margin-left: 2px; flex-shrink: 0; }

/* ============================================================
   Client Notes
   ============================================================ */
.client-notes-wrapper {
  padding: 0 16px 8px;
  background: var(--bg-secondary);
  border-bottom: 0.5px solid var(--border);
}
.client-notes {
  width: 100%;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  padding: 8px 10px;
  resize: none;
  font-family: inherit;
  margin-top: 6px;
  line-height: 1.4;
  outline: none;
}
.client-notes:focus { box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2); }
.client-notes::placeholder { color: var(--text-muted); }

/* ============================================================
   Conversation Pane
   ============================================================ */
.conversation-pane {
  flex: 1;
  display: none;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

.conversation-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
}
.conversation-empty[hidden] { display: none; }

.conversation-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 10px);
  background: var(--bg-secondary);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
  z-index: 5;
}

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.back-btn:hover { background: var(--bg-tertiary); }

.conversation-client-info { flex: 1; min-width: 0; }

.client-name {
  display: block;
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-listing {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-status-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* ============================================================
   Messages — iMessage style
   ============================================================ */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-primary);
}

.msg-bubble {
  max-width: 70%;
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
}

.msg-in {
  background: var(--bubble-in);
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg-out {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.bubble-text { margin-bottom: 3px; }

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 11px;
  opacity: 0.7;
}

.msg-in .bubble-meta { color: var(--text-muted); }
.msg-out .bubble-meta { color: rgba(255,255,255,0.75); }

.status-sent { color: rgba(255,255,255,0.5); }
.status-delivered { color: rgba(255,255,255,0.5); }
.status-read { color: #34c759; }

/* Date separator between message groups */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0 8px;
  gap: 12px;
}
.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color, #e0e0e0);
}
.date-separator span {
  font-size: 12px;
  color: var(--text-muted, #86868b);
  white-space: nowrap;
  padding: 2px 10px;
  background: var(--bg-tertiary, #f0f0f2);
  border-radius: 10px;
}

.load-more-indicator {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 8px;
  cursor: pointer;
}

/* ============================================================
   Reply Area
   ============================================================ */
.reply-area {
  background: var(--bg-secondary);
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
}

.template-strip {
  display: flex;
  gap: 6px;
  padding: 8px 10px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.template-strip:empty { display: none; }
.template-strip::-webkit-scrollbar { display: none; }

.reply-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  align-items: flex-end;
}

.reply-textarea {
  flex: 1;
  border-radius: 16px;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: none;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
  min-height: 80px;
  max-height: 40vh;
  overflow-y: auto;
}
.reply-textarea:focus { box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15); }
.reply-textarea::placeholder { color: var(--text-muted); }
.reply-textarea:disabled { opacity: 0.5; }

.send-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn:hover:not(:disabled) { opacity: 0.85; }
.send-btn:active:not(:disabled) { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.35; cursor: default; }
.send-btn.sent { background: var(--status-open); }
.send-btn.error { background: #ff3b30; }

.reply-error {
  color: #ff3b30;
  font-size: 13px;
  padding: 0 12px 8px;
}

/* ============================================================
   Login Page
   ============================================================ */
.login-container {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 36px 28px;
  box-shadow: var(--shadow-lg);
}

.login-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 28px;
  text-align: center;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.login-error {
  background: #ffe5e5;
  border-radius: var(--radius-sm);
  color: #ff3b30;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
}

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

.login-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: block;
  font-weight: 500;
}

.login-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
}
.login-input:focus { box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2); }

.login-btn {
  margin-top: 4px;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  transition: opacity 0.15s;
}
.login-btn:hover { opacity: 0.85; }

/* ============================================================
   Sidebar header nav links
   ============================================================ */
.sidebar-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sidebar-nav-link {
  font-size: 16px;
  text-decoration: none;
  opacity: 0.5;
  transition: opacity 0.15s;
  padding: 4px;
}
.sidebar-nav-link:hover { opacity: 1; }
.push-bell { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; }

/* ============================================================
   Right Panel — Client Info
   ============================================================ */
.client-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-left: 0.5px solid var(--border);
  overflow-y: auto;
  display: none;
  flex-direction: column;
}

.client-panel-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 16px;
  border-bottom: 0.5px solid var(--border);
}

.client-panel-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  color: #fff;
  margin-bottom: 10px;
}

.client-panel-name {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 4px;
}

.client-panel-status {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}
.panel-status--open { color: var(--status-open); }
.panel-status--replied { color: var(--accent); }
.panel-status--closed { color: var(--text-muted); }

.client-panel-tag {
  margin-top: 4px;
}

.client-panel-section {
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--border);
}

.client-panel-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
}

.client-panel-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-stat-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.panel-stat-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.client-panel-actions {
  padding: 14px 16px;
}

.panel-action-btn {
  width: 100%;
  padding: 8px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.panel-action-btn:hover { background: var(--bg-hover); }

/* ============================================================
   Responsive
   ============================================================ */
@media (min-width: 768px) {
  .chat-sidebar { width: 300px; min-width: 260px; max-width: 320px; }
  .conversation-pane { display: flex; }
  .client-panel { display: flex; }
  .back-btn { display: none; }
  .hidden-mobile { display: flex !important; }
  .active-mobile { display: flex !important; }
}

/* Wide screens: wider sidebar */
@media (min-width: 1200px) {
  .chat-sidebar { width: 340px; max-width: 360px; }
  .client-panel { width: 300px; }
}

/* Hidden attribute override — flex elements need explicit none */
[hidden] { display: none !important; }

.chat-sidebar.hidden-mobile { display: none; }
.conversation-pane.active-mobile {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  overflow: hidden;
}

/* ============================================================
   Template Buttons
   ============================================================ */
.template-btn {
  background: var(--bg-tertiary);
  border: none;
  border-radius: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  padding: 5px 14px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}
.template-btn:hover { background: var(--bg-hover); }

/* ============================================================
   Settings Pages
   ============================================================ */
.settings-container { max-width: 800px; margin: 0 auto; padding: 24px 16px; }
.settings-header { margin-bottom: 24px; }
.settings-back-link { display: inline-block; color: var(--accent); text-decoration: none; font-size: 15px; margin-bottom: 12px; }
.settings-back-link:hover { text-decoration: underline; }
.settings-title { font-size: 28px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.5px; }
.settings-subtitle { font-size: 14px; color: var(--text-muted); }
.settings-subtitle code { background: var(--bg-tertiary); border-radius: 4px; padding: 1px 6px; font-size: 12px; color: var(--accent); }

.settings-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.settings-card-title { font-size: 17px; font-weight: 600; margin-bottom: 16px; }
.settings-loading, .settings-empty { color: var(--text-muted); font-size: 14px; padding: 16px 0; text-align: center; }

.settings-form { display: flex; flex-direction: column; gap: 12px; max-width: 600px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group-inline { flex-direction: row; align-items: center; gap: 12px; }
.form-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.form-input { padding: 8px 14px; background: var(--bg-tertiary); border: none; border-radius: var(--radius-sm); color: var(--text-primary); font-size: 15px; outline: none; font-family: inherit; }
.form-input:focus { box-shadow: 0 0 0 3px rgba(0,122,255,0.15); }
.form-input-sm { width: 80px; }
.form-textarea { padding: 8px 14px; background: var(--bg-tertiary); border: none; border-radius: var(--radius-sm); color: var(--text-primary); font-size: 15px; outline: none; font-family: inherit; resize: vertical; line-height: 1.4; }
.form-textarea:focus { box-shadow: 0 0 0 3px rgba(0,122,255,0.15); }
.form-textarea-sm { font-size: 13px; }
.form-error { color: #ff3b30; font-size: 13px; margin-top: 8px; }

.settings-btn { padding: 8px 18px; border: none; border-radius: var(--radius-sm); cursor: pointer; font-size: 15px; font-weight: 500; font-family: inherit; transition: opacity 0.15s; white-space: nowrap; }
.settings-btn-primary { background: var(--accent); color: #fff; }
.settings-btn-primary:hover { opacity: 0.85; }
.settings-btn-secondary { background: var(--bg-tertiary); color: var(--text-secondary); }
.settings-btn-secondary:hover { background: var(--bg-hover); }
.settings-btn-danger { background: #ffe5e5; color: #ff3b30; }
.settings-btn-danger:hover { background: #ffd5d5; }
.settings-btn-sm { padding: 5px 12px; font-size: 13px; }

.settings-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.settings-table th { text-align: left; padding: 8px; font-weight: 600; color: var(--text-secondary); border-bottom: 0.5px solid var(--border); font-size: 13px; }
.settings-table td { padding: 8px; border-bottom: 0.5px solid var(--border); vertical-align: top; }
.settings-table tr:last-child td { border-bottom: none; }
.td-position { width: 70px; color: var(--text-muted); }
.td-title { font-weight: 500; min-width: 120px; }
.td-body { color: var(--text-secondary); }
.td-actions { width: 170px; white-space: nowrap; }
.td-actions .settings-btn + .settings-btn { margin-left: 6px; }

/* ============================================================
   Monitor Log Page
   ============================================================ */
.monitor-page { max-width: 900px; margin: 0 auto; }
.monitor-header { padding: 20px 16px 0; }
.monitor-page-title { font-size: 28px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.5px; }

.monitor-status-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.monitor-status-bar .status-dot { margin-top: 0; }
.status-dot--running { background: #34c759 !important; }
.status-dot--stopped { background: #ff3b30 !important; }
#status-text { font-size: 15px; font-weight: 500; }
#last-scan-text { font-size: 14px; color: var(--text-secondary); }

.log-timeline { display: flex; flex-direction: column; }
.log-entry { display: flex; padding: 10px 16px; border-bottom: 0.5px solid rgba(0,0,0,0.06); gap: 12px; font-size: 14px; align-items: baseline; }
.log-entry--scan { color: var(--text-secondary); }
.log-entry--message_found { background: rgba(52,199,89,0.06); }
.log-entry--message_found .log-entry__type { color: #34c759; }
.log-entry--filter_skip { background: rgba(255,149,0,0.06); }
.log-entry--filter_skip .log-entry__type { color: #ff9500; }
.log-entry--error { background: rgba(255,59,48,0.06); }
.log-entry--error .log-entry__type { color: #ff3b30; }
.log-entry__time { min-width: 140px; color: var(--text-secondary); flex-shrink: 0; }
.log-entry__type { font-weight: 600; min-width: 100px; text-transform: uppercase; font-size: 12px; flex-shrink: 0; }
.log-entry__details { flex: 1; word-break: break-word; }

/* ============================================================
   AI Draft
   ============================================================ */
.ai-draft-trigger-btn {
  background: #ff3b30;
  color: #fff;
  border: none;
  border-radius: 18px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.ai-draft-trigger-btn:hover { opacity: 0.85; }

.ai-draft-card { margin: 8px 16px; padding: 12px; border-radius: var(--radius-md); background: var(--bg-secondary); box-shadow: var(--shadow-md); }
.ai-draft-loading { color: var(--text-muted); font-style: italic; text-align: center; padding: 16px; }
.ai-draft-confidence-high { border-left: 3px solid var(--status-open); }
.ai-draft-confidence-medium { border-left: 3px solid var(--text-muted); }
.ai-draft-confidence-low { border-left: 3px solid #ff9500; }
.ai-draft-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ai-draft-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.ai-draft-badge { background: var(--bg-tertiary); color: var(--text-primary); font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 8px; }
.ai-draft-confidence-high .ai-draft-badge { background: #e5f7e8; color: #34c759; }
.ai-draft-confidence-low .ai-draft-badge { background: #fff4e5; color: #ff9500; }
.ai-draft-text { font-size: 15px; line-height: 1.4; margin-bottom: 10px; white-space: pre-wrap; }
.ai-draft-actions { display: flex; gap: 8px; }
.ai-draft-btn { padding: 6px 16px; border: none; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; font-family: inherit; font-weight: 500; transition: opacity 0.15s; }
.ai-draft-btn:hover { opacity: 0.85; }
.ai-draft-send { background: var(--status-open); color: #fff; }
.ai-draft-edit { background: var(--accent); color: #fff; }
.ai-draft-reject { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ============================================================
   Autopilot Controls
   ============================================================ */
.autopilot-controls { display: flex; flex-direction: column; gap: 8px; padding: 8px 14px; border-bottom: 0.5px solid var(--border); }
.autopilot-segment { display: flex; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-tertiary); }
.autopilot-segment-btn { flex: 1; padding: 6px 12px; border: none; background: transparent; color: var(--text-muted); font-size: 13px; font-weight: 500; font-family: inherit; cursor: pointer; transition: all 0.2s; }
.autopilot-segment-btn.active { background: var(--accent); color: #fff; border-radius: 8px; }
.autopilot-segment-btn:hover:not(.active) { color: var(--text-primary); }
.autopilot-threshold { display: flex; align-items: center; gap: 8px; }
.autopilot-threshold-label { font-size: 13px; color: var(--text-secondary); white-space: nowrap; min-width: 72px; }
.autopilot-slider { flex: 1; accent-color: var(--accent); height: 4px; }
.autopilot-indicator { display: flex; align-items: center; gap: 6px; }
.autopilot-pulse { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--status-open); animation: pulse-green 1.5s infinite; }
.autopilot-indicator-text { font-size: 12px; font-weight: 600; color: var(--status-open); text-transform: uppercase; letter-spacing: 0.3px; }

@keyframes pulse-green { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Sidebar autopilot controls — always visible in chat list */
.sidebar-autopilot {
  padding: 10px 16px 12px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.sidebar-autopilot-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.sidebar-autopilot-pulse { flex-shrink: 0; }
.sidebar-autopilot .autopilot-segment { width: 100%; }
.sidebar-autopilot-threshold {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: center;
}
.sidebar-autopilot-threshold .autopilot-threshold-label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.sidebar-autopilot-threshold .autopilot-slider { flex: 1; max-width: 160px; }

/* Toast */
.autopilot-toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  color: var(--text-primary);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  animation: toast-in 0.3s ease-out;
}
.autopilot-toast-hide { animation: toast-out 0.3s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(16px); } }

.msg-autopilot-badge { display: inline-block; font-size: 10px; background: #e5f7e8; color: #34c759; border-radius: 4px; padding: 1px 5px; margin-left: 4px; font-weight: 500; }

/* ============================================================
   Autopilot Feed Page
   ============================================================ */
.autopilot-feed-page { max-width: 900px; margin: 0 auto; padding-bottom: 40px; }
.autopilot-timeline { padding: 0 16px; }
.autopilot-entry { background: var(--bg-secondary); border-radius: var(--radius-md); padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
.autopilot-entry--cancelled { opacity: 0.5; }
.autopilot-entry__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.autopilot-entry__client { font-weight: 600; color: var(--accent); text-decoration: none; font-size: 15px; }
.autopilot-entry__client:hover { text-decoration: underline; }
.autopilot-entry__time { font-size: 13px; color: var(--text-muted); }
.autopilot-entry__text { font-size: 15px; white-space: pre-wrap; line-height: 1.4; margin-bottom: 10px; max-height: 120px; overflow: hidden; }
.autopilot-text--cancelled { text-decoration: line-through; color: var(--text-secondary); }
.autopilot-expand-btn { background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; padding: 2px 0; }
.autopilot-entry__footer { display: flex; align-items: center; gap: 10px; }
.autopilot-confidence-badge { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 2px 8px; }
.autopilot-status { font-size: 13px; font-weight: 500; }
.autopilot-status--sent { color: var(--status-open); }
.autopilot-status--cancelled { color: var(--text-muted); }
.autopilot-cancel-btn { margin-left: auto; }
.autopilot-cancel-btn:disabled { opacity: 0.4; cursor: default; }
.status-dot--semi { background: #ff9500; }

/* ============================================================
   Analytics Page
   ============================================================ */
.analytics-page { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.analytics-header { padding: 0 0 12px; }
.period-toggle { display: flex; gap: 8px; margin-bottom: 20px; }
.period-btn { padding: 6px 18px; border: none; background: var(--bg-tertiary); color: var(--text-secondary); font-size: 14px; font-family: inherit; cursor: pointer; border-radius: var(--radius-sm); transition: all 0.15s; }
.period-btn.active { background: var(--accent); color: #fff; }
.period-btn:hover:not(.active) { background: var(--bg-hover); }
.stats-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stats-card { background: var(--bg-secondary); border-radius: var(--radius-md); padding: 16px; box-shadow: var(--shadow-sm); }
.stats-card__title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.stats-card__metrics { display: flex; gap: 16px; }
.stats-card__metric { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--text-secondary); }
.stats-card__metric span { color: var(--text-primary); font-weight: 600; }
.stats-unavailable { text-align: center; color: var(--text-muted); padding: 24px; font-size: 15px; }
.chart-container { background: var(--bg-secondary); border-radius: var(--radius-md); padding: 16px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.chart-title { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
.analytics-page canvas { max-height: 300px; }

/* ============================================================
   Typing Indicator
   ============================================================ */
.typing-indicator {
  padding: 4px 16px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}
.typing-dots {
  display: inline-block;
  margin-right: 4px;
}
.typing-dots span {
  display: inline-block;
  animation: typing-bounce 1.4s infinite;
  font-weight: 700;
  font-size: 16px;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* ============================================================
   Blocked client styles
   ============================================================ */
.chat-item--blocked { opacity: 0.5; }
.blocked-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  background: #ff3b30;
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 4px;
  vertical-align: middle;
  letter-spacing: 0.5px;
}
.panel-block-btn { color: var(--text-secondary); }
.panel-block-btn--active {
  color: #ff3b30;
  border-color: #ff3b30;
}

/* Refresh button spin animation */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spinning { animation: spin 0.6s ease-in-out; }


/* Вкладки по объявлениям — сразу видно, кто по какому объявлению пишет */
.listing-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 8px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.listing-tabs::-webkit-scrollbar { display: none; }
.listing-tab {
  flex: 0 0 auto;
  max-width: 150px;
  padding: 6px 10px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 2px solid transparent;
  transition: background .15s, color .15s;
}
.listing-tab:hover { background: rgba(127, 127, 127, .12); }
.listing-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent, #0af);
  font-weight: 600;
}
.listing-tab .tab-count { opacity: .6; margin-left: 4px; font-weight: 400; }
.listing-tab .tab-unread {
  display: inline-block;
  min-width: 16px;
  margin-left: 4px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent, #0af);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
}


/* Вкладка с новыми сообщениями: точка + подсветка названия */
.listing-tab.has-unread { color: var(--text-primary); font-weight: 600; }
.listing-tab .tab-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #f5222d;
  vertical-align: middle;
  animation: tab-dot-pulse 1.8s ease-in-out infinite;
}
@keyframes tab-dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .45; transform: scale(.8); }
}
@media (prefers-reduced-motion: reduce) {
  .listing-tab .tab-dot { animation: none; }
}
.listing-tab.has-unread .tab-unread { background: #f5222d; }
