/* Dashboard styles */
:root {
  --primary: #4A90D9;
  --primary-dark: #3a7bc4;
  --bg: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-w: 230px;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ============ LOGIN ============ */
.login-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4A90D9 0%, #2c5f9e 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-icon {
  width: 64px; height: 64px; margin: 0 auto 12px;
  background: var(--primary); color: #fff;
  border-radius: 18px; display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.login-logo p { color: var(--text-muted); margin-top: 6px; font-size: 13px; }
.login-field { display: block; margin-bottom: 16px; }
.login-field span { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.login-field input {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.login-field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15); }
.login-error {
  background: #fef2f2; border: 1px solid #fecaca; color: var(--danger);
  border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-ai-active { background: #2d3142; border-color: #2d3142; color: #fff; }
.btn-icon {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.btn-icon:hover { background: #eef2ff; color: var(--primary); }

/* ============ LAYOUT ============ */
.layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w); background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-header { padding: 18px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.sidebar-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.sidebar-title { font-weight: 700; font-size: 15px; }
.sidebar-sub { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.sidebar-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; border: none; background: transparent;
  font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer;
  text-align: left; font-family: inherit; transition: background 0.15s;
}
.nav-btn:hover { background: #f1f5f9; }
.nav-btn.is-active { background: #eef2ff; color: var(--primary); font-weight: 600; }
.nav-icon { width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  border-radius: 20px; padding: 1px 8px; font-size: 11px; font-weight: 700;
}
.sidebar-footer {
  margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.operator-info { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
  flex-shrink: 0;
}
.op-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.op-role { font-size: 11px; color: var(--text-muted); }

/* ============ DOTS ============ */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-online { background: var(--success); box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2); }
.dot-offline { background: #cbd5e1; }
.dot-waiting { background: var(--warning); }

/* ============ CHAT LIST ============ */
.chats-panel {
  width: 320px; background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.panel-head { padding: 16px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.filter-tabs { display: flex; gap: 4px; }
.filter-tab {
  flex: 1; padding: 7px 6px; border-radius: 8px; border: none;
  background: transparent; font-size: 12px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.filter-tab:hover { background: #f1f5f9; }
.filter-tab.is-active { background: #eef2ff; color: var(--primary); font-weight: 600; }
.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  padding: 12px 14px; border-bottom: 1px solid #f1f5f9; cursor: pointer;
  transition: background 0.12s;
}
.chat-item:hover { background: #f8fafc; }
.chat-item.is-active { background: #eef2ff; border-left: 3px solid var(--primary); }
.chat-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.chat-name { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.chat-time { font-size: 11px; color: var(--text-muted); }
.chat-item-body { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-preview {
  font-size: 12.5px; color: var(--text-muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.chat-unread {
  background: var(--primary); color: #fff; border-radius: 20px;
  min-width: 20px; height: 20px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.chat-item-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.chat-status { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.chat-status.st-new { background: #fef3c7; color: #92400e; }
.chat-status.st-active { background: #dcfce7; color: #166534; }
.chat-status.st-waiting { background: #e0e7ff; color: #3730a3; }
.chat-status.st-closed { background: #f1f5f9; color: #64748b; }
.chat-operator { font-size: 11px; color: var(--text-muted); }
.chat-site {
  font-size: 10px; color: #1e40af; background: #dbeafe;
  padding: 1px 7px; border-radius: 10px; max-width: 130px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.head-site {
  font-size: 11px; color: #1e40af; background: #dbeafe;
  padding: 2px 8px; border-radius: 10px;
}
.site-add-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.site-add-row input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.embed-mini {
  display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 11px; color: var(--text-muted);
}
.muted { color: var(--text-muted); font-size: 12px; }
.ops-actions { white-space: nowrap; }
.site-access-list { display: flex; flex-direction: column; gap: 6px; min-width: 170px; }
.site-access-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.site-access-check input { accent-color: var(--primary); }
.chat-ai-badge {
  display: inline-block; background: #2d3142; color: #fff;
  font-size: 10px; font-weight: 700; letter-spacing: 0.3px;
  padding: 2px 8px; border-radius: 20px; margin-bottom: 5px;
}
.empty-state {
  padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 13px;
}

/* ============ CHAT PANEL ============ */
.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); gap: 6px;
}
.empty-icon { font-size: 48px; opacity: 0.4; }
.chat-empty h3 { font-size: 17px; color: var(--text); }
.chat-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-head {
  padding: 14px 18px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.head-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.head-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 400px; }
.head-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.head-id { font-size: 12px; color: var(--text-muted); }
.head-ai-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: #2d3142; color: #fff; font-size: 11px;
  padding: 2px 10px; border-radius: 20px; font-weight: 600;
}
.head-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }

.chat-body {
  flex: 1; overflow-y: auto; padding: 18px;
  display: flex; flex-direction: column; gap: 4px;
}
.chat-no-messages { text-align: center; color: var(--text-muted); padding: 30px; font-size: 13px; }

.msg { display: flex; flex-direction: column; margin-bottom: 8px; max-width: 65%; }
.msg-in { align-self: flex-start; align-items: flex-start; }
.msg-out { align-self: flex-end; align-items: flex-end; }
.msg-ai { align-self: flex-start; align-items: flex-start; }
.msg-system { align-self: center; max-width: 100%; }
.msg-meta { display: flex; gap: 8px; margin: 0 10px 3px; font-size: 11px; color: var(--text-muted); }
.msg-bubble {
  padding: 9px 14px; border-radius: 14px; line-height: 1.45; font-size: 13.5px;
  word-break: break-word; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.msg-in .msg-bubble { border-bottom-left-radius: 4px; }
.msg-out .msg-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-ai .msg-bubble { background: #2d3142; color: #f0f0f5; border-bottom-left-radius: 4px; }
.msg-system .msg-bubble { background: transparent; color: var(--text-muted); font-style: italic; font-size: 12px; box-shadow: none; }

.chat-input-area {
  padding: 10px 14px; background: #fff; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.typing-indicator { display: flex; align-items: center; gap: 8px; padding: 4px 6px; font-size: 12px; color: var(--text-muted); }
.typing-dots { display: flex; gap: 3px; }
.typing-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
  animation: blink 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.typing-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

.input-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input {
  flex: 1; border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 14px; font-size: 14px; resize: none; outline: none;
  font-family: inherit; max-height: 140px; transition: border-color 0.2s;
}
.chat-input:focus { border-color: var(--primary); }
.send-btn {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.closed-note { font-size: 12px; color: var(--text-muted); text-align: center; }
.closed-note a { color: var(--primary); }

/* ============ SETTINGS ============ */
.settings-layout { display: flex; height: 100vh; overflow: hidden; }
.settings-main { flex: 1; overflow-y: auto; background: var(--bg); }
.settings-page { max-width: 800px; margin: 0 auto; padding: 24px 28px 60px; }
.settings-page h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.settings-desc { color: var(--text-muted); margin-bottom: 18px; font-size: 13px; }
.settings-card {
  background: #fff; border-radius: var(--radius); padding: 20px 22px;
  border: 1px solid var(--border); margin-bottom: 16px;
}
.settings-card h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.settings-group {
  padding: 14px 0;
  border-top: 1px solid #f1f5f9;
}
.settings-group:first-child { border-top: 0; padding-top: 0; }
.settings-group h3 {
  font-size: 13px;
  font-weight: 800;
  color: #334155;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-row { margin-bottom: 12px; }
.form-label { font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text); }
.form-control { display: flex; align-items: center; gap: 8px; }
.form-control input[type="text"], .form-control input[type="url"], .form-control input[type="number"], .form-control select, .form-control textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13.5px; outline: none; font-family: inherit; transition: border-color 0.2s;
}
.form-control input:focus, .form-control select:focus, .form-control textarea:focus { border-color: var(--primary); }
.form-control textarea { resize: vertical; }
.form-help { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.color-picker { display: flex; gap: 8px; align-items: center; width: 100%; }
.color-picker input[type="color"] { width: 44px; height: 38px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; padding: 3px; }
.color-picker input[type="text"] { width: 120px; }
.size-row { display: flex; align-items: center; gap: 6px; }
.size-row input[type="number"] { width: 80px; }
.responsive-settings-grid {
  display: grid;
  grid-template-columns: 150px repeat(3, minmax(90px, 1fr));
  gap: 8px;
  align-items: center;
  overflow-x: auto;
}
.responsive-settings-grid > div {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.responsive-settings-grid label { font-size: 13px; font-weight: 600; color: var(--text); }
.responsive-settings-grid input {
  width: 100%;
  min-width: 78px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.checkbox-label input { width: 16px; height: 16px; accent-color: var(--primary); }
.days-row { display: flex; flex-wrap: wrap; gap: 8px; }
.day-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}
.day-check input { accent-color: var(--primary); }
.settings-save-bar {
  position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--border);
  padding: 14px 0; margin-top: 8px; display: flex; justify-content: flex-end;
}
.embed-box { display: flex; gap: 8px; align-items: flex-start; }
.embed-box textarea {
  flex: 1; background: #f8fafc; font-family: "Courier New", monospace;
  font-size: 12.5px; border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  resize: vertical; min-height: 90px; outline: none;
}
.settings-loading { padding: 60px; text-align: center; color: var(--text-muted); }

.ops-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ops-table th {
  text-align: left; padding: 8px 10px; border-bottom: 2px solid var(--border);
  font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px;
}
.ops-table td { padding: 9px 10px; border-bottom: 1px solid #f1f5f9; }
.ops-table tr:hover td { background: #f8fafc; }

/* ============ TOASTS ============ */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #fff; border-radius: 10px; padding: 12px 18px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15); font-size: 13.5px; font-weight: 500;
  border-left: 4px solid var(--success); animation: toastIn 0.25s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast-out { opacity: 0; transform: translateX(20px); transition: all 0.3s; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

@media (max-width: 900px) {
  .sidebar { width: 60px; }
  .sidebar-title, .sidebar-sub, .op-name, .op-role, .nav-btn span:not(.nav-icon) { display: none; }
  .sidebar-header { justify-content: center; padding: 14px; }
  .sidebar-logo { margin: 0; }
  .nav-btn { justify-content: center; padding: 12px; }
  .sidebar-footer { justify-content: center; }
  .operator-info { display: none; }
  .chats-panel { width: 250px; }
}
@media (max-width: 640px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-nav { flex-direction: row; padding: 6px; }
  .sidebar-footer { display: none; }
  .chats-panel { width: 100%; height: 35vh; border-right: none; border-bottom: 1px solid var(--border); }
  .chat-panel { height: 65vh; }
}
