:root {
  --ink: #0B0F1F;              /* hitam kebiruan, bukan hitam pekat */
  --ink-soft: #131A30;
  --surface: #FFFFFF;
  --surface-muted: #F7F8FC;
  --border-subtle: #E7E9F3;

  --blue: #155EEF;
  --blue-dark: #0B3FB0;
  --purple: #7C3AED;

  --gradient-brand: linear-gradient(135deg, var(--purple) 0%, var(--blue) 100%);
  --gradient-dark: linear-gradient(180deg, #101733 0%, #0B0F1F 100%);

  --text-primary: #0B0F1F;
  --text-secondary: #5B6178;
  --text-inverse: #F7F8FC;

  --success: #22C55E;
  --danger: #EF4444;
  --warning: #F59E0B;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-soft: 0 10px 30px -12px rgba(11, 15, 31, 0.15);
  --shadow-card: 0 2px 10px rgba(11, 15, 31, 0.06);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--surface-muted);
  color: var(--text-primary);
  margin: 0;
}

h1, h2, h3, h4, .font-display { font-family: 'Sora', 'Inter', sans-serif; letter-spacing: -0.01em; }
.font-mono { font-family: 'JetBrains Mono', monospace; }

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

.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--gradient-dark);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 28px;
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--gradient-brand);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Sora', sans-serif;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 6px 16px -4px rgba(124, 58, 237, 0.5);
}
.brand-text strong { display: block; font-family: 'Sora', sans-serif; font-size: 16px; }
.brand-text small { color: #9AA3C2; font-size: 12px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  color: #C3C9E0;
  font-size: 14.5px;
  font-weight: 500;
  text-decoration: none;
  transition: all .15s ease;
  position: relative;
}
.sidebar .nav-link i { font-size: 17px; width: 20px; text-align: center; }
.sidebar .nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar .nav-link.active {
  background: var(--gradient-brand);
  color: #fff;
  box-shadow: 0 6px 18px -6px rgba(21, 94, 239, 0.6);
}
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}
.sidebar-footer { padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.08); }

/* ===== Main area ===== */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 28px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 20px; font-weight: 700; margin: 0; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.btn-icon { border: none; background: transparent; font-size: 22px; color: var(--text-primary); }

.connection-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600; color: #178A45;
  background: #E9FBF0; border: 1px solid #C7F3D9;
  padding: 6px 12px; border-radius: 999px;
}
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: pulseDot 1.8s infinite;
}
@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.55); }
  70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

.topbar-user { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.avatar-ring {
  width: 38px; height: 38px; border-radius: 50%;
  padding: 2px;
  background: var(--gradient-brand);
}
.avatar-fallback {
  width: 100%; height: 100%; border-radius: 50%;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--blue-dark); font-weight: 700; font-family: 'Sora', sans-serif;
}

.content-area { padding: 28px; flex: 1; }

/* ===== Cards ===== */
.card-premium {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
}
.stat-card .stat-icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--gradient-brand); color: #fff; font-size: 18px;
  margin-bottom: 12px;
}
.stat-card .stat-value { font-family: 'Sora', sans-serif; font-size: 28px; font-weight: 700; }
.stat-card .stat-label { color: var(--text-secondary); font-size: 13px; font-weight: 500; }

.btn-brand {
  background: var(--gradient-brand);
  border: none; color: #fff; font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  box-shadow: 0 8px 20px -8px rgba(21, 94, 239, 0.55);
}
.btn-brand:hover { color: #fff; filter: brightness(1.06); }

.badge-status-connected { background: #E9FBF0; color: #178A45; border: 1px solid #C7F3D9; }
.badge-status-disconnected { background: #FDEDED; color: #C43535; border: 1px solid #F6CFCF; }
.badge-status-pending { background: #FFF6E5; color: #B9770E; border: 1px solid #FBE3B0; }

/* ===== Chat page ===== */
.chat-shell { display: flex; height: calc(100vh - 140px); border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border-subtle); box-shadow: var(--shadow-card); }
.chat-list { width: 320px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border-subtle); overflow-y: auto; }
.chat-list-item { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border-subtle); cursor: pointer; text-decoration: none; color: inherit; }
.chat-list-item:hover, .chat-list-item.active { background: var(--surface-muted); }
.chat-avatar { position: relative; width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; }
.chat-avatar .ring { width: 100%; height: 100%; border-radius: 50%; padding: 2px; background: var(--gradient-brand); }
.chat-avatar .fallback { width: 100%; height: 100%; border-radius: 50%; background: var(--surface-muted); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--blue-dark); }
.chat-avatar .online-dot { position: absolute; bottom: 0; right: 0; width: 11px; height: 11px; border-radius: 50%; background: var(--success); border: 2px solid var(--surface); animation: pulseDot 1.8s infinite; }
.chat-window { flex: 1; display: flex; flex-direction: column; background: var(--surface-muted); }
.chat-window-header { padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; gap: 12px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 65%; padding: 10px 14px; border-radius: 16px; font-size: 14.5px; line-height: 1.45; }
.bubble-in { background: var(--surface); align-self: flex-start; border-bottom-left-radius: 4px; box-shadow: var(--shadow-card); }
.bubble-out { background: var(--gradient-brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble-meta { font-family: 'JetBrains Mono', monospace; font-size: 10.5px; opacity: 0.65; margin-top: 4px; display: block; }
.chat-input-bar { padding: 14px 20px; background: var(--surface); border-top: 1px solid var(--border-subtle); display: flex; gap: 10px; }
.chat-input-bar input { flex: 1; border-radius: 999px; border: 1px solid var(--border-subtle); padding: 10px 18px; }
.chat-input-bar input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(21,94,239,0.12); }

/* ===== Agent (AI persona) cards ===== */
.agent-card { border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 20px; background: var(--surface); box-shadow: var(--shadow-card); }
.agent-avatar { width: 46px; height: 46px; border-radius: 12px; background: var(--gradient-brand); display: flex; align-items: center; justify-content: center; color: #fff; font-family: 'Sora', sans-serif; font-weight: 700; }

.form-control, .form-select { border-radius: var(--radius-sm); border: 1px solid var(--border-subtle); }
.form-control:focus, .form-select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(21,94,239,0.12); }

.form-switch .form-check-input:checked { background-color: var(--blue); border-color: var(--blue); }

/* ===== Auth pages ===== */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--gradient-dark);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-soft);
}

@media (max-width: 992px) {
  .sidebar { position: fixed; left: -280px; z-index: 40; transition: left .2s ease; }
  .sidebar.open { left: 0; }
  .chat-shell { flex-direction: column; height: auto; }
  .chat-list { width: 100%; max-height: 260px; }
}

/* Sidebar mobile overlay */
.sidebar-overlay { display:none; position: fixed; inset: 0; background: rgba(11,15,31,0.55); z-index: 35; }
.sidebar-overlay.show { display: block; }
.sidebar-close { background: transparent; border: none; color: #fff; font-size: 20px; margin-left: auto; }

/* Chat window pas di layar HP, input selalu kelihatan */
@media (max-width: 992px) {
  .chat-window { height: 65vh; min-height: 420px; }
}

/* Chat: nomor di bawah nama, tombol hapus */
.chat-list-item { position: relative; }
.chat-list-number { font-size: 11.5px; color: var(--text-secondary); font-family: 'JetBrains Mono', monospace; }
.btn-delete-convo {
  border: none; background: transparent; color: var(--text-secondary);
  opacity: 0; transition: opacity .15s; padding: 4px 8px; align-self: center;
}
.chat-list-item:hover .btn-delete-convo { opacity: 1; }
.btn-delete-convo:hover { color: var(--danger); }
.btn-back-list { border: none; background: transparent; font-size: 18px; margin-right: 8px; color: var(--text-primary); }

/* Chat di HP: full-screen, ganti antara daftar & jendela chat, tidak perlu scroll halaman */
@media (max-width: 992px) {
  .chat-shell { height: calc(100dvh - 130px); border: none; box-shadow: none; }
  .chat-list { width: 100%; max-height: none; display: block; }
  .chat-window { display: none; height: 100%; }
  .chat-shell.show-window .chat-list { display: none; }
  .chat-shell.show-window .chat-window { display: flex; }
}
