/* ========================================
   JOHA APP — DASHBOARD STYLES
   ======================================== */

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

:root {
  --bg: #080808;
  --surface: #111111;
  --surface2: #1a1a1a;
  --border: #222222;
  --purple: #9333ea;
  --purple-light: #a855f7;
  --purple-dim: rgba(147, 51, 234, 0.15);
  --text: #ffffff;
  --muted: #888888;
  --muted2: #555555;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===== AUTH PAGES ===== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse 80% 60% at 50% -20%, rgba(147,51,234,0.12), transparent);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 36px;
  display: block;
  text-decoration: none;
  color: var(--text);
}
.auth-logo span { color: var(--purple); }

.auth-title { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.auth-sub { color: var(--muted); font-size: 14px; margin-bottom: 32px; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 8px; color: #ccc; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--purple);
}
.form-group textarea { resize: vertical; min-height: 120px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
  font-family: inherit;
}
.btn-primary { background: var(--purple); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--purple-light); }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--purple); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-footer { margin-top: 24px; text-align: center; font-size: 13px; color: var(--muted); }
.auth-footer a { color: var(--purple); text-decoration: none; }

.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 20px;
  display: none;
}
.error-msg.visible { display: block; }

.success-msg {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: var(--radius-sm);
  color: #86efac;
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 20px;
  display: none;
}
.success-msg.visible { display: block; }

/* ===== DASHBOARD SHELL ===== */
.dashboard {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px;
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  display: block;
}
.sidebar-logo span { color: var(--purple); }

.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }

.nav-section { margin-bottom: 24px; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted2);
  padding: 0 8px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--purple-dim); color: var(--purple-light); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--purple);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-plan { font-size: 11px; color: var(--muted); text-transform: capitalize; }

.logout-btn {
  padding: 6px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.15s;
}
.logout-btn:hover { color: var(--red); }

/* Main content */
.main {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  padding: 28px 32px 0;
}
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 14px; }

.page-body { padding: 24px 32px; flex: 1; }

/* ===== OVERVIEW PAGE ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 800; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.section-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

/* ===== CONVERSATIONS PAGE ===== */
.conv-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.conv-list {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conv-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.conv-list-header h3 { font-size: 14px; font-weight: 600; }

.conv-filter {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filter-btn {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font-family: inherit;
  transition: all 0.15s;
}
.filter-btn.active { background: var(--purple-dim); color: var(--purple-light); border-color: var(--purple); }

.conv-items { flex: 1; overflow-y: auto; }

.conv-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.conv-item:hover { background: var(--surface2); }
.conv-item.active { background: var(--purple-dim); border-left: 3px solid var(--purple); }

.conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.platform-wa { background: rgba(37,211,102,0.15); color: #25d366; }
.platform-ig { background: rgba(225,48,108,0.15); color: #e1306c; }
.platform-ms { background: rgba(24,119,242,0.15); color: #1877f2; }

.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-meta { font-size: 11px; color: var(--muted2); margin-top: 2px; }

.conv-unread {
  background: var(--purple);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* Chat pane */
.chat-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-header-info { flex: 1; }
.chat-contact-name { font-size: 15px; font-weight: 600; }
.chat-contact-meta { font-size: 12px; color: var(--muted); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
}
.msg-bubble.user {
  background: var(--surface2);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg-bubble.assistant {
  background: var(--purple-dim);
  border: 1px solid rgba(147,51,234,0.3);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg-bubble.human-reply {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg-time { font-size: 10px; color: var(--muted2); margin-top: 4px; }
.msg-label { font-size: 10px; color: var(--muted); margin-bottom: 2px; }

.chat-reply {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}
.chat-reply textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  height: 44px;
  outline: none;
  transition: border-color 0.2s;
}
.chat-reply textarea:focus { border-color: var(--purple); }
.send-btn {
  padding: 10px 20px;
  background: var(--purple);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.2s;
  white-space: nowrap;
}
.send-btn:hover { background: var(--purple-light); }

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

/* ===== AGENT BUILDER ===== */
.agent-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.card-sub { font-size: 13px; color: var(--muted); margin-bottom: 24px; }

/* ===== CHANNELS PAGE ===== */
.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.channel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.channel-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.channel-icon.wa { background: rgba(37,211,102,0.1); }
.channel-icon.ig { background: rgba(225,48,108,0.1); }
.channel-icon.ms { background: rgba(24,119,242,0.1); }

.channel-info { flex: 1; }
.channel-name { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.channel-desc { font-size: 13px; color: var(--muted); }

.channel-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.status-dot.active { background: var(--green); }
.status-dot.inactive { background: var(--muted2); }

/* ===== BILLING PAGE ===== */
.plans-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 700px;
}

.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  position: relative;
}
.plan-card.featured { border-color: var(--purple); }
.plan-badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--purple);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.plan-name { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.plan-price { font-size: 36px; font-weight: 800; margin-bottom: 20px; }
.plan-price span { font-size: 14px; font-weight: 400; color: var(--muted); }
.plan-features { list-style: none; margin-bottom: 24px; }
.plan-features li {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.plan-features li::before { content: '✓'; color: var(--green); font-weight: 700; flex-shrink: 0; }

/* ===== UTILITIES ===== */
.loading { color: var(--muted); font-size: 14px; text-align: center; padding: 32px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 48px 24px; }
.empty-icon { font-size: 40px; margin-bottom: 12px; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tag-purple { background: var(--purple-dim); color: var(--purple-light); }
.tag-green { background: rgba(34,197,94,0.1); color: var(--green); }
.tag-red { background: rgba(239,68,68,0.1); color: var(--red); }
.tag-yellow { background: rgba(234,179,8,0.1); color: var(--yellow); }

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

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 1000;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s;
}
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* Spinner */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TRAINING ===== */
.training-entry {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}
.training-entry-body { flex: 1; min-width: 0; }
.training-entry-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.training-entry-content { font-size: 12px; color: var(--muted); line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.training-empty {
  padding: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .page-header { padding: 20px 16px 0; }
  .page-body { padding: 16px; }
  .agent-grid { grid-template-columns: 1fr; }
  .plans-grid { grid-template-columns: 1fr; }
  .conv-layout { grid-template-columns: 1fr; }
}
