/* ==========================================================================
   WA Gateway — Dashboard
   Ditulis manual tanpa framework CSS agar ringan dan tidak butuh CDN,
   sehingga tetap berfungsi di hosting dengan koneksi keluar terbatas.
   ========================================================================== */

:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1e222b;
  --border: #272c37;
  --border-soft: #21252e;
  --text: #e7e9ee;
  --text-dim: #9aa2b1;
  --text-faint: #6b7382;

  --green: #25d366;   /* warna khas WhatsApp */
  --green-dim: #1da851;
  --red: #f2545b;
  --amber: #f5a623;
  --blue: #4c8dff;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);

  --sidebar-w: 244px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
a { color: inherit; text-decoration: none; }

/* ============================= Login ============================= */

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(37, 211, 102, 0.13), transparent 60%),
    radial-gradient(700px 420px at 100% 100%, rgba(76, 141, 255, 0.11), transparent 55%),
    var(--bg);
  padding: 24px;
}

.login-wrap { width: 100%; max-width: 380px; }

.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px 28px;
  box-shadow: var(--shadow);
}

.login-logo {
  width: 50px;
  height: 50px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--green), var(--green-dim));
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #06210f;
  font-size: 17px;
  margin-bottom: 18px;
}

.login-card h1 { font-size: 20px; margin-bottom: 5px; }
.login-card .sub { color: var(--text-dim); margin-bottom: 22px; font-size: 13px; }

/* ============================= Layout ============================= */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--green), var(--green-dim));
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #06210f;
  font-size: 13px;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 14px; }
.brand-text span { font-size: 11px; color: var(--text-faint); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}

.nav-item:hover { background: var(--bg-elev-2); color: var(--text); }
.nav-item.active { background: rgba(37, 211, 102, 0.13); color: var(--green); }

.nav-icon { width: 17px; height: 17px; flex-shrink: 0; display: grid; place-items: center; }
.nav-icon svg { width: 100%; height: 100%; }

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

.conn-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.conn-badge.on .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.18); }
.conn-badge.warn .dot { background: var(--amber); }
.conn-badge.off .dot { background: var(--red); }
.conn-badge.on .conn-text { color: var(--green); }

.user-row { display: flex; align-items: center; gap: 9px; }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.user-info strong { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info span { font-size: 10.5px; color: var(--text-faint); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.page-title { font-size: 16px; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 9px; }

.pill {
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--mono);
}

.content { padding: 22px; flex: 1; }

.menu-btn { display: none; }

/* ============================= Komponen ============================= */

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.danger:hover { color: var(--red); }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
}

.card-title { font-size: 14px; margin-bottom: 3px; }
.card-sub { font-size: 12.5px; color: var(--text-dim); margin-bottom: 16px; }

.grid { display: grid; gap: 14px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px 17px;
}

.stat-label {
  font-size: 11.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 7px;
}

.stat-value { font-size: 25px; font-weight: 600; line-height: 1.15; }
.stat-sub { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-value.amber { color: var(--amber); }

/* Tombol */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: #262b35; border-color: #333947; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #06210f;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: #2ee070; border-color: #2ee070; }

.btn-danger { color: var(--red); border-color: rgba(242, 84, 91, 0.32); }
.btn-danger:hover:not(:disabled) { background: rgba(242, 84, 91, 0.12); border-color: var(--red); }

.btn-sm { padding: 6px 11px; font-size: 12px; }

/* Form */
.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-dim);
}
.field .hint { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }

input[type='text'],
input[type='password'],
input[type='number'],
input[type='url'],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.13);
}

textarea { resize: vertical; min-height: 96px; font-family: inherit; }
select { cursor: pointer; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 150px; }
.row > .no-grow { flex: 0 0 auto; }

/* Tabel */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border-soft); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  text-align: left;
  padding: 11px 14px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

td { padding: 11px 14px; border-top: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:hover { background: rgba(255, 255, 255, 0.018); }

.mono { font-family: var(--mono); font-size: 12px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-green { background: rgba(37, 211, 102, 0.14); color: var(--green); }
.badge-red { background: rgba(242, 84, 91, 0.14); color: var(--red); }
.badge-amber { background: rgba(245, 166, 35, 0.14); color: var(--amber); }
.badge-blue { background: rgba(76, 141, 255, 0.14); color: var(--blue); }
.badge-gray { background: var(--bg-elev-2); color: var(--text-dim); }

/* Kartu sesi */
.session-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.session-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.session-head { display: flex; align-items: flex-start; gap: 11px; }

.session-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.session-meta { flex: 1; min-width: 0; }
.session-meta strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-meta span { font-size: 11.5px; color: var(--text-faint); font-family: var(--mono); }

.session-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 11px 0;
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
}

.mini-stat { text-align: center; }
.mini-stat b { display: block; font-size: 15px; font-weight: 600; }
.mini-stat span { font-size: 10.5px; color: var(--text-faint); }

.session-actions { display: flex; gap: 7px; flex-wrap: wrap; }

/* QR */
.qr-panel { text-align: center; padding: 18px; }

.qr-box {
  display: inline-block;
  padding: 13px;
  background: #fff;
  border-radius: var(--radius);
  line-height: 0;
  margin-bottom: 14px;
}

.qr-box img { width: 232px; height: 232px; display: block; }

.qr-empty {
  width: 232px;
  height: 232px;
  display: grid;
  place-items: center;
  background: var(--bg-elev-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-faint);
  font-size: 12.5px;
  text-align: center;
  padding: 20px;
  margin: 0 auto 14px;
  line-height: 1.6;
}

.pair-code {
  font-family: var(--mono);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--green);
  padding: 13px;
  background: rgba(37, 211, 102, 0.09);
  border: 1px dashed rgba(37, 211, 102, 0.35);
  border-radius: var(--radius);
  margin-bottom: 13px;
  user-select: all;
}

.steps { text-align: left; font-size: 12.5px; color: var(--text-dim); padding-left: 18px; margin: 0; }
.steps li { margin-bottom: 5px; }

/* Daftar pesan */
.msg-list { display: flex; flex-direction: column; gap: 9px; }

.msg {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.msg.in { border-left-color: var(--blue); }
.msg.out { border-left-color: var(--green); }
.msg.failed { border-left-color: var(--red); }

.msg-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
  flex-wrap: wrap;
  font-size: 12.5px;
}

.msg-head strong { font-weight: 600; }
.msg-time { color: var(--text-faint); font-size: 11.5px; margin-left: auto; font-family: var(--mono); }
.msg-body { font-size: 13.5px; color: var(--text-dim); white-space: pre-wrap; word-break: break-word; }

/* Toast */
.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  z-index: 100;
  max-width: 340px;
}

.toast {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 12px 15px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn 0.22s ease;
  display: flex;
  gap: 9px;
  align-items: flex-start;
}

.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }

@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 22px;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 22px;
  max-width: 430px;
  width: 100%;
  box-shadow: var(--shadow);
}

.modal h3 { font-size: 16px; margin-bottom: 9px; }
.modal p { color: var(--text-dim); font-size: 13.5px; margin: 0 0 19px; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; }

/* Utilitas */
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.mb-0 { margin-bottom: 0; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gap-8 { gap: 8px; }
.center { text-align: center; }
.hidden { display: none !important; }

.empty {
  text-align: center;
  padding: 46px 22px;
  color: var(--text-faint);
}

.empty-icon { width: 42px; height: 42px; margin: 0 auto 13px; opacity: 0.35; }
.empty-icon svg { width: 100%; height: 100%; }
.empty h3 { font-size: 15px; color: var(--text-dim); margin-bottom: 5px; }

/* Skeleton pemuatan */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elev) 25%, var(--bg-elev-2) 50%, var(--bg-elev) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================= Responsif ============================= */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: grid; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .truncate { max-width: 180px; }
  .toasts { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

@media (max-width: 560px) {
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 21px; }
  .session-grid { grid-template-columns: 1fr; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}
