* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #252830;
  --bg-hover: #2a2d3a;
  --border: #2e3140;
  --text: #e4e6eb;
  --text-dim: #8b8fa3;
  --accent: #25d366;
  --accent-hover: #1eba56;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --sidebar-w: 240px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ==================== AUTH ==================== */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.auth-logo {
  width: 56px;
  height: 56px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
}

.auth-card h2 { font-size: 1.4rem; margin-bottom: 0.3rem; }
.auth-subtitle { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 1.5rem; }

.auth-form { text-align: left; }
.auth-form .form-group { margin-bottom: 1rem; }
.auth-form label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.4rem; }

.error-text { color: var(--danger); font-size: 0.85rem; margin-top: 0.8rem; text-align: center; }

/* ==================== LAYOUT ==================== */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1.2rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item.active svg { stroke: #fff; }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 0.8rem;
}

.sidebar-user {
  padding: 0.5rem 0.8rem 0.6rem;
  display: flex;
  flex-direction: column;
}

.sidebar-user span:first-child { font-size: 0.85rem; font-weight: 500; }
.sidebar-role { font-size: 0.75rem; color: var(--text-dim); }

.nav-logout { color: var(--text-dim); }
.nav-logout:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* ==================== MAIN CONTENT ==================== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 2rem;
  max-width: 1200px;
}

.pg h1 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.page-hint {
  color: var(--text-dim);
  font-size: 0.95rem;
  padding: 2rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

/* ==================== STATS ==================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

/* ==================== SETTINGS ==================== */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.2rem;
}

.settings-section h3 {
  font-size: 1.05rem;
  margin-bottom: 0.3rem;
}

.settings-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.settings-section-header > div:first-child { flex: 1; }
.settings-section-header .section-desc { margin-bottom: 0; }

.settings-section-header .cd-ai-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.settings-section-header .cd-ai-label { font-size: 0.95rem; white-space: nowrap; }

.toggle-lg { width: 50px; height: 28px; }
.toggle-lg .toggle-slider::before { width: 20px; height: 20px; left: 4px; bottom: 4px; }
.toggle-lg input:checked + .toggle-slider::before { transform: translateX(22px); }

.section-desc {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.input-with-btn {
  display: flex;
  gap: 0.5rem;
}

.input-with-btn input { flex: 1; }

.field-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

.field-hint.success { color: var(--success); }
.field-hint.warning { color: var(--warning); }

.save-status {
  margin-left: 1rem;
  font-size: 0.85rem;
  color: var(--success);
}

/* ==================== AI SWITCH ==================== */
.ai-switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.ai-switch-info { flex: 1; }
.ai-switch-title { font-size: 1.05rem; font-weight: 600; }
.ai-switch-desc { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.2rem; }

.slider-on::before { transform: translateX(18px) !important; }

/* ==================== INPUTS ==================== */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

select {
  cursor: pointer;
}

/* ==================== BUTTONS ==================== */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.65rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full { width: 100%; }

.btn-icon {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  padding: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover { background: var(--border); }

/* ==================== TOAST ==================== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1000;
  transition: opacity 0.3s;
}

.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

/* ==================== CHATS PAGE ==================== */
.pg-fullheight {
  height: calc(100vh - 2rem);
  padding: 0 !important;
}

.chats-layout {
  display: flex;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.chats-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.chats-sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.chats-sidebar-header h3 { font-size: 1.1rem; }

.chats-search {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.chats-search input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}

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

.chats-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-dim);
}

.chats-item {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.chats-item:hover { background: var(--bg-hover); }
.chats-item-active { background: var(--bg-hover); border-left: 3px solid var(--accent); }

.chats-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.chats-item-name { font-weight: 500; font-size: 0.9rem; }
.chats-item-time { font-size: 0.75rem; color: var(--text-dim); }

.chats-item-bottom {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.chats-item-status { font-size: 0.78rem; }
.chats-item-ai { font-size: 0.8rem; }

.chats-unread {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  font-weight: 600;
  margin-left: auto;
}

/* Chat main area */
.chats-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.chats-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text-dim);
}

.chats-chat-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.chats-chat-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chats-chat-info strong { font-size: 0.95rem; }
.chats-chat-ai { font-size: 0.85rem; color: var(--text-dim); }

.btn-sm-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-sm-outline:hover { border-color: var(--accent); color: var(--accent); }

.chats-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chats-input-area {
  border-top: 1px solid var(--border);
  padding: 0.6rem;
  background: var(--bg-card);
}

/* ==================== EMOJI PICKER ==================== */
.chat-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.chat-input-wrap textarea {
  width: 100%;
  padding: 0.6rem 2.5rem 0.6rem 0.8rem;
  border-radius: 22px;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}

.chat-emoji-wrap {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
}

.chat-emoji-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: color 0.15s;
}
.chat-emoji-btn:hover { color: var(--accent); }

.chat-emoji-picker {
  width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  z-index: 1000;
  overflow: hidden;
}

.emoji-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0.3rem;
  gap: 2px;
  overflow-x: auto;
}

.emoji-tab {
  background: none;
  border: none;
  font-size: 1.2rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.emoji-tab:hover { background: rgba(255,255,255,0.06); }
.emoji-tab.active { background: rgba(37,211,102,0.15); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}

.emoji-item {
  font-size: 1.4rem;
  padding: 0.25rem;
  text-align: center;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.1s;
  line-height: 1.3;
}
.emoji-item:hover { background: rgba(255,255,255,0.1); }

/* ==================== MIC / RECORDING ==================== */
.chat-mic-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  color: var(--text-dim);
}
.chat-mic-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-mic-btn.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: pulse-rec 1s ease-in-out infinite;
}
@keyframes pulse-rec { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }

.chat-rec-indicator {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 1rem;
}

.chat-rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink-rec 1s infinite;
}
@keyframes blink-rec { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

#rec-time {
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

/* ==================== TRANSFER MODAL ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  min-width: 320px;
}

.modal-card h3 { margin-bottom: 1rem; }

.transfer-select {
  width: 100%;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ==================== INSTANCES ==================== */
.instances-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.inst-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.inst-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.inst-phone { font-weight: 600; font-size: 1rem; }

.inst-status { font-size: 0.85rem; }
.inst-online { color: var(--success); }
.inst-offline { color: var(--text-dim); }

.inst-card-body { padding: 0.8rem 1rem; }

.inst-card-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border);
}

.btn-danger-outline { border-color: var(--danger) !important; color: var(--danger) !important; }
.btn-danger-outline:hover { background: rgba(239,68,68,0.1) !important; }

/* QR Section */
.qr-section { margin-top: 1rem; }

.qr-area {
  text-align: center;
  padding: 1.5rem;
}

.qr-status {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.qr-img {
  max-width: 280px;
  border-radius: 12px;
  background: #fff;
  padding: 0.5rem;
}

.qr-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
}

/* Instance Settings Modal */
.modal-wide { min-width: 400px; }

.inst-settings-grid {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.inst-setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  cursor: pointer;
  font-size: 0.9rem;
}

.inst-setting-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ==================== AI PAUSE MODAL ==================== */
.ai-pause-options {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.ai-pause-btn {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.8rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
}
.ai-pause-btn:hover { border-color: var(--danger); }

.ai-pause-timer {
  padding: 0.8rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.ai-pause-timer strong { display: block; margin-bottom: 0.5rem; }

.ai-pause-times {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.ai-pause-time-btn {
  padding: 0.4rem 0.8rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.ai-pause-time-btn:hover { border-color: var(--accent); color: var(--accent); }

.ai-pause-custom {
  display: flex;
  gap: 0.4rem;
}

.ai-pause-custom input {
  width: 100px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

/* ==================== CONTACTS TABLE ==================== */
.pg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.contacts-toolbar {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.contacts-toolbar input { flex: 1; max-width: 400px; }
.contacts-toolbar select { width: 200px; }

.contacts-table-wrap {
  overflow-x: auto;
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.contacts-table th {
  text-align: left;
  padding: 0.7rem 0.8rem;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.contacts-table td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.clickable-row { cursor: pointer; transition: background 0.1s; }
.clickable-row:hover { background: var(--bg-hover); }

.status-badge {
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}

.ai-on { color: var(--success); font-size: 0.8rem; font-weight: 600; }
.ai-off { color: var(--text-dim); font-size: 0.8rem; }

.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  margin-left: 0.4rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
}

.text-dim { color: var(--text-dim); font-size: 0.85rem; }

/* ==================== CONTACT DETAIL ==================== */
.cd-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.btn-back {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.btn-back:hover { background: var(--border); }

.cd-header-info { flex: 1; min-width: 150px; }
.cd-name { font-weight: 600; font-size: 1.1rem; display: block; }
.cd-phone { color: var(--text-dim); font-size: 0.85rem; }

.cd-status-select {
  width: auto;
  min-width: 160px;
  font-weight: 500;
}

.cd-ai-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cd-ai-label { font-size: 0.85rem; }

.cd-manager-select { width: auto; min-width: 150px; }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg-hover); border-radius: 22px; transition: 0.2s;
}
.toggle-slider::before {
  content: ''; position: absolute; width: 16px; height: 16px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Body: info + chat */
.cd-body {
  display: flex;
  gap: 1rem;
  height: calc(100vh - 180px);
}

.cd-info {
  width: 280px;
  flex-shrink: 0;
  overflow-y: auto;
}

.cd-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.8rem;
}

.cd-section h3 { font-size: 0.9rem; margin-bottom: 0.7rem; color: var(--text-dim); }

.cd-field {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.85rem;
}

.cd-label { color: var(--text-dim); }

.cd-files-list { display: flex; flex-direction: column; gap: 0.4rem; }

.cd-file-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg-input);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.82rem;
  transition: background 0.15s;
}
.cd-file-item:hover { background: var(--bg-hover); }
.cd-file-icon { font-size: 1rem; }
.cd-file-size { color: var(--text-dim); margin-left: auto; }

/* Chat panel */
.cd-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.cd-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
}

.msg {
  max-width: 75%;
  padding: 0.5rem 0.8rem;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.4;
}

.msg-in {
  align-self: flex-start;
  background: var(--bg-input);
}

.msg-out {
  align-self: flex-end;
  background: #1a5c38;
}

.msg-internal {
  align-self: center;
  background: #3d3520;
  border: 1px dashed #6b5c30;
  max-width: 85%;
}

.msg-sender {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
}

.msg-text { word-break: break-word; }

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.3rem;
  margin-top: 0.2rem;
}

.msg-time {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.msg-tick {
  flex-shrink: 0;
  vertical-align: middle;
  margin-left: 1px;
}

.msg-reactions {
  font-size: 1rem;
  line-height: 1;
  background: rgba(15, 17, 23, 0.5);
  border-radius: 10px;
  padding: 2px 5px;
  display: inline-block;
  margin-top: 2px;
}

/* Chat input */
.cd-input-area {
  border-top: 1px solid var(--border);
  padding: 0.6rem;
}

.cd-mode-tabs {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}

.cd-mode {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.cd-mode.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.cd-mode:hover:not(.active) { background: var(--bg-hover); }

.cd-input-row {
  display: flex;
  gap: 0.5rem;
}

.cd-input-row textarea {
  flex: 1;
  resize: none;
  padding: 0.6rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.cd-input-row textarea:focus { border-color: var(--accent); }

.btn-send {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 0 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.5; }

/* ==================== МЕДИА В ЧАТЕ ==================== */
.chat-msg-media { font-style: italic; color: #71717a; font-size: 0.85rem; }
.chat-media-box { border-radius: 6px; overflow: hidden; margin-bottom: 4px; }
.chat-media-placeholder {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1rem;
  cursor: pointer; color: #71717a; transition: color 0.15s;
}
.chat-media-placeholder:hover { color: #25d366; }
.chat-audio-placeholder { padding: 0.4rem 0.8rem; }
.chat-media-loading { padding: 1rem; display: flex; justify-content: center; }
.spinner {
  width: 24px; height: 24px; border: 2px solid #555; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Фото в чате — кроп как в WhatsApp */
.chat-img-wrap {
  position: relative; width: 330px; max-width: 100%; border-radius: 10px; overflow: hidden;
}
.chat-media-img {
  width: 100%; height: 220px; object-fit: cover; cursor: pointer; display: block;
}
.chat-img-time {
  position: absolute; bottom: 6px; right: 8px;
  font-size: 0.7rem; color: #fff; background: rgba(0,0,0,0.45);
  padding: 1px 6px; border-radius: 6px;
}
/* Убрать padding у сообщения с фото */
.msg:has(.chat-img-wrap) { padding: 3px; }
.msg:has(.chat-img-wrap) .msg-text { margin: 0; }
.chat-media-video { max-width: 300px; max-height: 300px; border-radius: 6px; display: block; }
.chat-media-audio { height: 36px; width: 220px; }
.chat-audio-box { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.chat-audio-time { font-size: 0.7rem; color: var(--text-dim); margin-left: auto; }
.chat-audio-transcript { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }
.chat-media-dl {
  display: flex; align-items: center; color: #71717a; padding: 4px;
  border-radius: 4px; transition: color 0.15s;
}
.chat-media-dl:hover { color: #25d366; }
.chat-media-caption { font-size: 0.85rem; margin-top: 4px; }
.chat-doc-link {
  display: flex; align-items: center; gap: 0.5rem; color: #25d366;
  text-decoration: none; padding: 0.5rem; font-size: 0.85rem;
}
.chat-doc-link:hover { text-decoration: underline; }
.chat-doc-box { position: relative; }
.doc-badge {
  font-size: 0.7rem; padding: 1px 6px; border-radius: 8px; display: inline-block; margin-top: 3px;
}
.doc-badge-medical { background: #1a4d2e; color: #4ade80; }
.doc-badge-other { background: #333; color: #888; }

/* Полноэкранный просмотр фото */
.chat-media-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 10000;
  background: rgba(0,0,0,0.9); display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.chat-media-overlay img { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 4px; }
.chat-media-overlay button {
  position: absolute; top: 1rem; right: 1.5rem; background: none; border: none;
  color: #fff; font-size: 2rem; cursor: pointer;
}

/* ==================== KNOWLEDGE BASE ==================== */
.pg-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.kb-search-test { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.kb-search-test input { flex: 1; padding: 0.5rem 0.8rem; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: #fff; }
.kb-result { background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 0.8rem; margin-bottom: 0.5rem; }
.kb-result-header { font-size: 0.8rem; color: var(--accent); margin-bottom: 0.3rem; }
.kb-result-text { font-size: 0.85rem; line-height: 1.5; color: var(--text-dim); white-space: pre-wrap; }

/* Форма добавления */
.kb-form-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 1.2rem; margin-bottom: 1.5rem;
}
.kb-form-card h3 { margin-bottom: 1rem; }
.kb-form-card textarea { width: 100%; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: #fff; padding: 0.6rem; resize: vertical; }
.kb-form-card input[type="text"] { width: 100%; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: #fff; padding: 0.5rem 0.8rem; }
.kb-form-card select { background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: #fff; padding: 0.5rem 0.8rem; width: 100%; }
.form-hint { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.3rem; display: block; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

/* Batch */
.kb-batch-item { background: var(--bg-input); border-radius: 8px; padding: 0.8rem; margin-bottom: 0.5rem; }
.kb-batch-num { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 0.3rem; }
.kb-batch-item input { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: #fff; padding: 0.4rem 0.6rem; margin-bottom: 0.4rem; }
.kb-batch-item textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: #fff; padding: 0.4rem 0.6rem; resize: vertical; }

/* Карточки документов */
.kb-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem; margin-bottom: 0.8rem; transition: border-color 0.15s;
}
.kb-card:hover { border-color: var(--accent); }
.kb-card-header strong { font-size: 0.95rem; }
.kb-card-meta { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.2rem; }
.kb-card-preview { font-size: 0.85rem; color: var(--text-dim); margin: 0.5rem 0; line-height: 1.4; }
.kb-card-actions { display: flex; gap: 0.5rem; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-brand span,
  .nav-item span,
  .sidebar-user,
  .sidebar-role { display: none; }
  .sidebar-brand { justify-content: center; padding: 1rem 0.5rem; }
  .nav-item { justify-content: center; padding: 0.65rem; }
  .main-content { margin-left: 60px; padding: 1rem; }
  .form-row { flex-direction: column; }
  .cd-body { flex-direction: column; height: auto; }
  .cd-info { width: 100%; }
  .cd-header { gap: 0.5rem; }
}
