/* =====================================================================
   WhatsApp AI Bot Dashboard - Custom CSS
   ===================================================================== */

:root {
  --primary: #25D366;
  --primary-dark: #128C7E;
  --primary-light: #dcf8c6;
  --sidebar-bg: #1e293b;
  --sidebar-hover: #334155;
  --sidebar-active: #25D366;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  --content-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-width: 260px;
  --header-height: 65px;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
}

* { box-sizing: border-box; }

html {
  overflow-x: clip;
  max-width: 100%;
}

body {
  font-family: 'Poppins', sans-serif;
  background: var(--content-bg);
  color: var(--text-primary);
  margin: 0;
  overflow-x: clip;
  max-width: 100vw;
}

/* ─── Layout ─────────────────────────────────────────────────────── */
.wrapper {
  display: flex;
  min-height: 100vh;
  overflow-x: clip;
  max-width: 100%;
}

/* ─── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
  transition: transform 0.3s ease, width 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

.sidebar-brand {
  padding: 20px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  text-decoration: none;
  min-height: var(--header-height);
}

.sidebar-brand-icon {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sidebar-brand-icon svg { width: 22px; height: 22px; fill: #fff; }

.sidebar-brand-text {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.sidebar-brand-sub {
  font-size: 10px;
  color: var(--sidebar-text);
  font-weight: 400;
}

.sidebar-nav { padding: 12px 0; flex: 1; }

.sidebar-section {
  padding: 8px 22px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #475569;
  font-weight: 600;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 22px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
  position: relative;
  border-radius: 0;
  cursor: pointer;
}

.sidebar-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.sidebar-item.active {
  background: rgba(37, 211, 102, 0.15);
  color: var(--primary);
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-item i {
  font-size: 17px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-bottom {
  padding: 16px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* ─── Main Content ─────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;          /* penting: cegah flex child melampaui parent */
  max-width: 100%;
  /* clip: mencegah horizontal overflow TANPA membuat scroll container */
  /* sehingga position:sticky pada .top-header tetap bekerja          */
  overflow-x: clip;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease;
}

/* ─── Header ───────────────────────────────────────────────────────── */
.top-header {
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.page-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.user-avatar {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

/* ─── Page Content ─────────────────────────────────────────────────── */
.page-content {
  padding: 24px;
  flex: 1;
  min-width: 0;
  overflow-x: clip;
}

/* ─── Cards ────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  font-weight: 600;
  font-size: 14px;
}

.card-body { padding: 20px; }

/* ─── Stat Cards ────────────────────────────────────────────────────── */
.stat-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 50px; height: 50px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.green { background: rgba(37, 211, 102, 0.12); color: var(--primary); }
.stat-icon.blue  { background: rgba(59, 130, 246, 0.12); color: var(--info); }
.stat-icon.amber { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.stat-icon.red   { background: rgba(239, 68, 68, 0.12);  color: var(--danger); }

.stat-info { min-width: 0; }
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

/* ─── Status Badge ───────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.status-badge .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
}

.status-connected  { background: rgba(34, 197, 94, 0.12); color: var(--success); }
.status-connected .dot { background: var(--success); }

.status-disconnected { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.status-disconnected .dot { background: var(--danger); }

.status-qr { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.status-qr .dot { background: var(--warning); animation: pulse 1.5s infinite; }

.status-connecting { background: rgba(59, 130, 246, 0.12); color: var(--info); }
.status-connecting .dot { background: var(--info); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ─── QR Code Card ───────────────────────────────────────────────── */
.qr-container {
  text-align: center;
  padding: 20px;
}

.qr-container img {
  max-width: 220px;
  border-radius: 12px;
  border: 4px solid var(--primary);
  padding: 4px;
}

.qr-instruction {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 12px;
}

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn-primary-custom {
  background: var(--primary);
  border: none;
  color: #fff;
  padding: 9px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13.5px;
  transition: background 0.2s, transform 0.1s;
  cursor: pointer;
}

.btn-primary-custom:hover {
  background: var(--primary-dark);
  color: #fff;
}

.btn-primary-custom:active { transform: scale(0.98); }

.btn-danger-custom {
  background: var(--danger);
  border: none;
  color: #fff;
  padding: 9px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13.5px;
  transition: background 0.2s;
  cursor: pointer;
}

.btn-danger-custom:hover { background: #dc2626; color: #fff; }

/* ─── Tables ─────────────────────────────────────────────────────── */
.table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.table td { font-size: 13.5px; vertical-align: middle; }

/* ─── Forms ──────────────────────────────────────────────────────── */
.form-label { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.form-control, .form-select {
  font-size: 13.5px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 9px 12px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}

.form-text { font-size: 12px; }

/* ─── Badge ──────────────────────────────────────────────────────── */
.badge-category {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  font-weight: 600;
}

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

.toast-custom {
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  min-width: 240px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInRight 0.3s ease;
  color: #fff;
}

.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--info); }
.toast-warning { background: var(--warning); }

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

@keyframes fadeOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(30px); }
}

/* ─── Login Page ──────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  width: 60px; height: 60px;
  background: var(--primary);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
}

.login-logo svg { width: 35px; height: 35px; fill: #fff; }

/* ─── Message Bubble ──────────────────────────────────────────────── */
.msg-incoming {
  background: #f0f0f0;
  border-radius: 0 12px 12px 12px;
  padding: 8px 12px;
  font-size: 13px;
  max-width: 70%;
  display: inline-block;
}

.msg-outgoing {
  background: var(--primary-light);
  border-radius: 12px 0 12px 12px;
  padding: 8px 12px;
  font-size: 13px;
  max-width: 70%;
  display: inline-block;
}

/* ─── Spinner ─────────────────────────────────────────────────────── */
.spinner-wa {
  width: 40px; height: 40px;
  border: 4px solid rgba(37,211,102,0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── Connection Card ─────────────────────────────────────────────── */
.conn-card-icon {
  width: 70px; height: 70px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  margin: 0 auto 16px;
}

/* ─── Responsive ─────────────────────────────────────────────────── */

/* Sidebar overlay on tablet & mobile (< lg = 992px) */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 30px rgba(0, 0, 0, 0.25);
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    max-width: 100vw;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
  }

  .sidebar-overlay.show {
    display: block;
  }
}

/* Tablet (576px – 991px) */
@media (min-width: 576px) and (max-width: 991.98px) {
  .page-content {
    padding: 20px;
  }
}

/* Mobile (< 576px) */
@media (max-width: 575.98px) {
  .page-content {
    padding: 12px;
  }

  .card-body {
    padding: 12px !important;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-value {
    font-size: 22px;
  }

  .top-header {
    padding: 0 12px;
    height: 56px;
  }

  .page-title {
    font-size: 14px;
  }

  .table th,
  .table td {
    font-size: 12px;
    padding: 8px 6px;
  }

  .btn-sm {
    font-size: 11px;
    padding: 4px 8px;
  }

  /* Alert banner jangan overflow */
  .alert {
    font-size: 12px;
    padding: .5rem .75rem;
    word-break: break-word;
  }

  /* Toast tidak melampaui layar */
  .toast-custom {
    min-width: unset;
    max-width: calc(100vw - 24px);
    font-size: 12px;
  }
}

/* ─── Utilities ──────────────────────────────────────────────────── */
.text-primary-custom { color: var(--primary) !important; }
.bg-primary-custom   { background: var(--primary) !important; }
.border-primary-custom { border-color: var(--primary) !important; }

.fw-600 { font-weight: 600; }
.fs-12  { font-size: 12px; }
.fs-13  { font-size: 13px; }
.fs-14  { font-size: 14px; }

.rounded-10 { border-radius: 10px; }
.rounded-12 { border-radius: 12px; }

.cursor-pointer { cursor: pointer; }

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }

/* ─── Orders Filter Bar ──────────────────────────────────────────── */
.orders-filter-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.status-tabs-scroll {
  display: flex;
  gap: .25rem;
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
  flex: 1;
}

.status-tabs-scroll::-webkit-scrollbar {
  display: none;
}

.status-tabs-scroll .btn {
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─── Responsive Table: stacked card pada layar kecil ──────────────── */
@media (max-width: 767.98px) {

  /* Bungkus kartu di mobile: hilangkan shadow luar supaya tidak double */
  .orders-table-wrap {
    box-shadow: none !important;
    border: none !important;
    background: transparent !important;
    overflow: visible;
  }
  .orders-table-wrap .table-responsive {
    /* Tetap overflow hidden agar viewport tidak melebar */
    overflow-x: hidden;
    background: transparent;
  }

  .table-responsive > table.table thead {
    display: none;
  }

  .table-responsive > table.table,
  .table-responsive > table.table tbody,
  .table-responsive > table.table tbody tr {
    display: block;
    width: 100%;
  }

  .table-responsive > table.table tbody tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: .75rem;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
    overflow: hidden;
    /* Pastikan tidak lebih lebar dari layar */
    max-width: 100%;
  }

  .table-responsive > table.table tbody tr:last-child {
    margin-bottom: 0;
  }

  .table-responsive > table.table tbody td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .5rem;
    padding: .5rem .85rem;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13px;
    /* Paksa teks wrap, jangan overflow */
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    text-align: right;
    min-height: 36px;
    max-width: 100%;
  }

  .table-responsive > table.table tbody td:last-child {
    border-bottom: none;
  }

  /* Label dari data-label */
  .table-responsive > table.table tbody td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 11px;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
    width: 90px;
    min-width: 90px;
    padding-right: .5rem;
    text-transform: uppercase;
    letter-spacing: .025em;
    line-height: 1.8;
  }

  /* Baris colspan (kosong / error) tetap center */
  .table-responsive > table.table tbody td[colspan] {
    justify-content: center;
    text-align: center;
    min-height: unset;
  }
  .table-responsive > table.table tbody td[colspan]::before {
    display: none;
  }

  /* Kolom Aksi: tombol rata kanan, tanpa label */
  .table-responsive > table.table tbody td:last-child {
    justify-content: flex-end;
    flex-wrap: wrap;
    padding-top: .5rem;
    padding-bottom: .5rem;
  }
  .table-responsive > table.table tbody td:last-child[data-label]::before {
    display: none;
  }
}

