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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --bg: #f1f5f9;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #4f46e5;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #22c55e;
}

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

/* Info Tooltip */
.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #cbd5e1;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  font-style: normal;
  cursor: help;
  position: relative;
  margin-left: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}
.info-tip:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: normal;
  width: max-content;
  max-width: 260px;
  z-index: 100;
  line-height: 1.4;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.section-title {
  display: flex;
  align-items: center;
  margin: 20px 0 12px;
  font-size: 14px;
  color: #64748b;
  font-weight: 600;
}

/* Login Page */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-box {
  background: var(--card-bg);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 380px;
}

.login-box h1 {
  text-align: center;
  margin-bottom: 8px;
  color: var(--primary);
  font-size: 24px;
}

.login-box .subtitle {
  text-align: center;
  color: var(--text-light);
  margin-bottom: 30px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
}

.form-group input, .form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
  padding: 12px;
}

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

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-sm { padding: 6px 14px; font-size: 13px; }

.error-msg {
  color: var(--danger);
  text-align: center;
  margin-top: 12px;
  font-size: 14px;
  min-height: 20px;
}

/* App Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
}

.sidebar .logo {
  padding: 0 20px 20px;
  font-size: 18px;
  font-weight: 700;
  color: white;
  border-bottom: 1px solid #334155;
  margin-bottom: 10px;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
}

.sidebar a:hover { background: #334155; color: white; }
.sidebar a.active { background: var(--sidebar-active); color: white; }

.sidebar .spacer { flex: 1; }

.sidebar .user-info {
  padding: 15px 20px;
  border-top: 1px solid #334155;
  font-size: 13px;
}

.sidebar .user-info .name { color: white; font-weight: 500; }
.sidebar .user-info .role { color: var(--text-light); font-size: 12px; }

/* Main Content */
.main-content {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.page-header h1 { font-size: 22px; }

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 16px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
}

table th, table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

table th {
  font-weight: 600;
  color: var(--text-light);
  font-size: 13px;
}

table tr:hover { background: #f8fafc; }

/* Clients Page - Chat Layout */
.clients-layout {
  display: flex;
  flex: 1;
  height: 100vh;
  overflow: hidden;
}

.clients-list {
  width: 300px;
  border-right: 1px solid var(--border);
  background: var(--card-bg);
  overflow-y: auto;
  flex-shrink: 0;
}

.clients-list-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 16px;
}

.clients-list-header select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  background: white;
  color: var(--text);
  cursor: pointer;
}

.client-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.client-item:hover { background: #f8fafc; }
.client-item.active { background: #ede9fe; }

.client-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}

.client-info { flex: 1; min-width: 0; }
.client-info .name { font-weight: 500; font-size: 14px; }
.client-info .last-time { font-size: 12px; color: var(--text-light); }

/* Channel Selector */
.channel-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.channel-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}

.channel-tab {
  padding: 12px 20px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  color: var(--text-light);
  transition: all 0.2s;
}

.channel-tab:hover { color: var(--text); }
.channel-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  min-height: 0;
  overflow: hidden;
}

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

.chat-empty {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  color: var(--text-light);
  font-size: 15px;
}

.message {
  max-width: 70%;
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  flex-shrink: 0;
}

.message.client {
  background: white;
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message.agent {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message .time {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.6;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 30px;
  width: 420px;
  max-width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal h2 {
  margin-bottom: 20px;
  font-size: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-secondary:hover { background: #cbd5e1; }

/* Badge */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fee2e2; color: #991b1b; }

/* Channel icons */
.channel-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: white;
  flex-shrink: 0;
}

.channel-icon.messenger { background: #0084ff; }
.channel-icon.instagram { background: #e1306c; }
.channel-icon.webchat { background: #22c55e; }
.channel-icon.whatsapp { background: #25d366; }

/* Chat Input */
.chat-input {
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  padding: 12px 16px;
}

.chat-input form {
  display: flex;
  gap: 10px;
}

.chat-input input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}

.chat-input input:focus {
  border-color: var(--primary);
}

.chat-input .btn {
  width: auto;
  flex-shrink: 0;
}

/* Settings Tabs */
.settings-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
  gap: 0;
}

.settings-tab {
  padding: 12px 24px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-light);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.settings-tab:hover {
  color: var(--text);
}

.settings-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.settings-panel {
  display: none;
}

.settings-panel.active {
  display: block;
}

.secret-field {
  position: relative;
  display: flex;
  align-items: center;
}

.secret-field input {
  flex: 1;
  padding-right: 40px;
}

.eye-toggle {
  position: absolute;
  right: 10px;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.5;
  user-select: none;
}

.eye-toggle:hover {
  opacity: 1;
}

/* Channel Header (tabs + details toggle) */
.channel-header {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}

.channel-header .channel-tabs {
  flex: 1;
  border-bottom: none;
}

.details-toggle {
  padding: 8px 14px;
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-light);
  white-space: nowrap;
  transition: all 0.2s;
}

.details-toggle:hover { color: var(--primary); }
.details-toggle.active { color: var(--primary); background: #f8fafc; }

/* Chat + Details wrapper */
.chat-details-wrapper {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.chat-details-wrapper .chat-area {
  flex: 1;
  min-width: 0;
}

/* Client Details Panel */
.client-details-panel {
  width: 0;
  overflow: hidden;
  border-left: 1px solid var(--border);
  background: var(--card-bg);
  transition: width 0.25s ease;
  flex-shrink: 0;
}

.client-details-panel.open {
  width: 280px;
}

.details-content {
  width: 280px;
  padding: 16px;
  overflow-y: auto;
  height: 100%;
}

.details-content h3 {
  font-size: 15px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.detail-form label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-light);
  margin-top: 10px;
  margin-bottom: 3px;
}

.detail-form input, .detail-form select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.detail-form input:focus { border-color: var(--primary); }

.email-indicator {
  font-size: 13px;
  padding: 4px 0;
}

.email-indicator .exists { color: var(--success); }
.email-indicator .not-exists { color: var(--text-light); }

/* Similar client alert */
.similar-alert {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 12px;
  color: #92400e;
}

.similar-alert a {
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
}

.similar-alert .clash-warning {
  color: #dc2626;
  font-weight: 500;
}

.channel-icon.web { background: #22c55e; }
