/* Chat Web App — SUCH-like 3-pane layout */
:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --surface-3: #475569;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
}

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

html, body {
  font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.6;
}

/* === Login Screen === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.login-logo {
  font-size: 64px;
  margin-bottom: 20px;
}
.login-card h1 {
  font-size: 22px;
  margin-bottom: 12px;
  color: var(--text);
}
.login-card p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 14px;
}
.login-note {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
}
#telegram-login-container iframe {
  border-radius: var(--radius-sm);
}

/* === Main Chat App === */
.chat-app {
  display: flex;
  height: 100vh;
  background: var(--bg);
}

/* === Sidebar === */
.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.agent-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.agent-details {
  flex: 1;
  min-width: 0;
}
.agent-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-status {
  font-size: 11px;
  color: var(--text-muted);
}
.availability-btn {
  padding: 6px 12px;
  border-radius: 20px;
  border: none;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.availability-btn.online {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}
.availability-btn.offline {
  background: rgba(148, 163, 184, 0.2);
  color: var(--text-muted);
}

.sidebar-search {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.sidebar-search input:focus {
  outline: none;
  border-color: var(--primary);
}

.sidebar-filters {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.filter-btn {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.15s;
}
.filter-btn:hover {
  background: var(--surface-2);
}
.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
}
.conv-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  gap: 10px;
}
.conv-item:hover {
  background: var(--surface-2);
}
.conv-item.selected {
  background: var(--surface-2);
  border-right: 3px solid var(--primary);
}
.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.conv-details {
  flex: 1;
  min-width: 0;
}
.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.conv-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-time {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 8px;
}
.conv-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.conv-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.conv-status-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.status-active { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.status-queued { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.status-closed { background: rgba(148, 163, 184, 0.2); color: var(--text-muted); }

.unread-badge {
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* === Chat Main === */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
}
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 72px;
  margin-bottom: 16px;
  opacity: 0.3;
}
.empty-state p {
  font-size: 16px;
}

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-header {
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-header-info {
  flex: 1;
  min-width: 0;
}
.chat-user-name {
  font-weight: 600;
  font-size: 15px;
}
.chat-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.chat-header-actions {
  display: flex;
  gap: 6px;
}
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.message {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.message-user {
  align-self: flex-start;
  background: var(--surface-2);
  border-bottom-right-radius: 4px;
}
.message-agent {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-left-radius: 4px;
}
.message-ai {
  align-self: flex-end;
  background: var(--surface-3);
  border-bottom-left-radius: 4px;
}
.message-system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}
.message-time {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
}

.typing-indicator {
  padding: 10px 20px;
  display: flex;
  gap: 4px;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

/* === Composer === */
.composer {
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.composer-toolbar {
  display: flex;
  gap: 4px;
}
.composer-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.composer-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
#message-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
}
#message-input:focus {
  outline: none;
  border-color: var(--primary);
}
.send-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.send-btn:hover {
  background: var(--primary-hover);
}
.send-btn:disabled {
  background: var(--surface-3);
  cursor: not-allowed;
}

/* === Quick Reply Panel === */
.quick-reply-panel {
  position: absolute;
  bottom: 70px;
  right: 80px;
  width: 320px;
  max-height: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.quick-reply-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
}
.small-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
.quick-reply-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.quick-reply-item {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}
.quick-reply-item:hover {
  background: var(--surface-2);
}
.quick-reply-item .qr-shortcut {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.quick-reply-item .qr-text {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Info Panel === */
.info-panel {
  width: 300px;
  min-width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.info-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.info-header h3 {
  font-size: 14px;
  font-weight: 600;
}
.info-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.info-section {
  margin-bottom: 20px;
}
.info-section h4 {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}
.info-label {
  color: var(--text-muted);
}
.info-value {
  font-weight: 500;
  text-align: left;
}
.assignment-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.assignment-item:last-child {
  border-bottom: none;
}
.assignment-item .agent-name {
  font-weight: 600;
  font-size: 13px;
}
.assignment-item .assignment-meta {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
}
.current-badge {
  display: inline-block;
  background: var(--success);
  color: white;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-right: 4px;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 1000;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
}

/* === Loading === */
.loading {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    min-width: 100%;
  }
  .chat-main {
    display: none;
  }
  .info-panel {
    display: none;
  }
  .sidebar.hidden-mobile {
    display: none;
  }
  .chat-main.visible-mobile {
    display: flex;
  }
}

/* === PIN Login === */
.login-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 12px;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.login-divider span {
  padding: 0 12px;
}
.pin-login-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pin-login-form input {
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  text-align: center;
}
.pin-login-form input:focus {
  outline: none;
  border-color: var(--primary);
}
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-primary:disabled {
  background: var(--surface-3);
  cursor: not-allowed;
}
