/* ============================================================
   RothaFlow V3 - CSS Principal (White Label)
   ============================================================ */

:root {
  --primary:       #7C3AED;
  --primary-dark:  #5B21B6;
  --primary-light: #EDE9FE;
  --secondary:     #4F46E5;
  --accent:        #06B6D4;
  --success:       #10B981;
  --warning:       #F59E0B;
  --danger:        #EF4444;
  --info:          #3B82F6;

  --bg:            #0F0F17;
  --bg-card:       #16161F;
  --bg-input:      #1E1E2D;
  --bg-hover:      #1A1A27;
  --border:        rgba(255,255,255,0.07);
  --border-light:  rgba(255,255,255,0.12);

  --text:          #E2E8F0;
  --text-muted:    #94A3B8;
  --text-dim:      #64748B;

  --sidebar-w:     260px;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:     0 2px 8px rgba(0,0,0,0.3);
  --transition:    all 0.2s ease;
}

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

html { font-size: 15px; scroll-behavior: smooth; }

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

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ---- Links ---- */
a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-light); }

/* ---- Typography ---- */
h1,h2,h3,h4,h5,h6 { font-weight: 600; line-height: 1.3; color: var(--text); }
p { color: var(--text-muted); }

/* ============================================================
   LAYOUT
   ============================================================ */

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease;
  position: relative;
  z-index: 100;
}

.sidebar.collapsed { width: 68px; min-width: 68px; }

.sidebar-logo {
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  min-height: 65px;
}

.sidebar-logo img {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.2s;
}

.sidebar.collapsed .sidebar-logo-text { opacity: 0; width: 0; }

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

.nav-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  padding: 8px 12px 4px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.2s;
}
.sidebar.collapsed .nav-section-label { opacity: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 0.9rem;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 99px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-badge { display: none; }

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

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.user-menu:hover { background: var(--bg-hover); }

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: #fff;
  flex-shrink: 0;
}

.user-info { overflow: hidden; flex: 1; }
.user-name { font-size: 0.85rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.72rem; color: var(--text-dim); }
.sidebar.collapsed .user-info { display: none; }

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  height: 65px;
  min-height: 65px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  gap: 16px;
}

.topbar-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: var(--transition);
}

.card:hover { border-color: var(--border-light); }

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

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

/* ---- Stat Cards ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: var(--transition);
}

.stat-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(124,58,237,0.15);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.purple { background: rgba(124,58,237,0.15); color: var(--primary); }
.stat-icon.blue   { background: rgba(59,130,246,0.15); color: var(--info); }
.stat-icon.green  { background: rgba(16,185,129,0.15); color: var(--success); }
.stat-icon.yellow { background: rgba(245,158,11,0.15); color: var(--warning); }
.stat-icon.red    { background: rgba(239,68,68,0.15);  color: var(--danger); }
.stat-icon.cyan   { background: rgba(6,182,212,0.15);  color: var(--accent); }

.stat-icon svg { width: 22px; height: 22px; }

.stat-body { flex: 1; min-width: 0; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.stat-change { font-size: 0.75rem; margin-top: 6px; }
.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(124,58,237,0.4); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-light); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

/* ============================================================
   FORMS
   ============================================================ */

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

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  transition: var(--transition);
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}

.form-control::placeholder { color: var(--text-dim); }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 100px; }

/* ============================================================
   TABLE
   ============================================================ */

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

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

.table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-card);
}

.table td {
  padding: 12px 16px;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
}

.table tr:hover td { background: var(--bg-hover); }

/* ============================================================
   BADGES
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger  { background: rgba(239,68,68,0.15);  color: var(--danger); }
.badge-info    { background: rgba(59,130,246,0.15);  color: var(--info); }
.badge-purple  { background: rgba(124,58,237,0.15);  color: var(--primary); }
.badge-gray    { background: rgba(148,163,184,0.1);  color: var(--text-dim); }

/* ============================================================
   MODAL
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal-overlay.open { opacity: 1; visibility: visible; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: var(--transition);
}

.modal-overlay.open .modal { transform: scale(1); }

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

.modal-title { font-size: 1rem; font-weight: 600; }

.modal-body { padding: 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ============================================================
   PLATFORM ICONS
   ============================================================ */

.platform-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.platform-icon.whatsapp { background: #25D366; color: #fff; }
.platform-icon.instagram { background: linear-gradient(135deg,#833ab4,#fd1d1d,#fcb045); color: #fff; }
.platform-icon.facebook  { background: #1877F2; color: #fff; }

/* ============================================================
   CHAT AREA
   ============================================================ */

.chat-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

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

.chat-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.chat-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: rgba(124,58,237,0.1); border-left: 3px solid var(--primary); }

.chat-contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
  position: relative;
}

.chat-item-body { flex: 1; min-width: 0; }
.chat-contact-name { font-size: 0.875rem; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
.chat-last-msg { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.chat-time { font-size: 0.7rem; color: var(--text-dim); }
.chat-unread {
  background: var(--primary);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

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

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

.message-bubble {
  max-width: 65%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

.message-bubble.inbound {
  background: var(--bg-input);
  color: var(--text);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.message-bubble.outbound {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

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

.chat-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-textarea {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.875rem;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  font-family: inherit;
  transition: var(--transition);
}
.chat-textarea:focus { outline: none; border-color: var(--primary); }

/* ============================================================
   UTILITIES
   ============================================================ */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 16px; }
.w-full { width: 100%; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-primary { color: var(--primary); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rounded { border-radius: var(--radius-sm); }
.rounded-full { border-radius: 9999px; }
.hidden { display: none !important; }

/* ---- Grid ---- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ---- Loading ---- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.875rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  min-width: 280px;
  max-width: 380px;
  animation: slideUp 0.2s ease;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--info); }

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}
.empty-state svg { width: 48px; height: 48px; color: var(--text-dim); margin: 0 auto 16px; }
.empty-state h3 { font-size: 1rem; margin-bottom: 8px; }
.empty-state p { font-size: 0.875rem; color: var(--text-dim); }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { width: 68px; min-width: 68px; }
  .sidebar .sidebar-logo-text,
  .sidebar .nav-item span,
  .sidebar .nav-badge,
  .sidebar .nav-section-label,
  .sidebar .user-info { display: none; }
  .page-content { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .chat-list { width: 100%; }
}

/* ---- Login page ---- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 30% 20%, rgba(124,58,237,0.15) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(79,70,229,0.1) 0%, transparent 60%),
              var(--bg);
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo-text {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-subtitle { text-align: center; color: var(--text-dim); font-size: 0.875rem; margin-top: 4px; }
