:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-alt: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-dim: #9aa0ac;
  --accent: #5b8cff;
  --accent-2: #7c6cff;
  --accent-dim: #2f3b5c;
  --accent-grad: linear-gradient(135deg, var(--accent-2) 0%, var(--accent) 55%, #3f6fe0 100%);
  --online: #3ddc84;
  --offline: #565c68;
  --danger: #e5484d;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.22);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.4);
  --shadow-accent: 0 6px 18px rgba(91, 140, 255, 0.35);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

/* Honeypot anti-bot: disembunyikan lewat CSS (bukan display:none/hidden),
   karena bot sederhana sering skip field yang jelas-jelas display:none tapi
   tetap ngisi field yang cuma "keluar layar" begini. Pengguna asli, mata &
   keyboard-nya tidak akan pernah nemu field ini. */
.hp-field {
  position: absolute !important;
  left: -9999px !important;
  top: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.screen {
  height: 100%;
  width: 100%;
}

/* Scrollbar & focus polish, dipakai di seluruh app */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
  background-clip: padding-box;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button, a, input, textarea {
  font-family: inherit;
}

/* Login screen */
#loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.loading-text {
  color: var(--text-dim);
  font-size: 0.9rem;
}

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(circle at 15% 20%, rgba(91, 140, 255, 0.12), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(91, 140, 255, 0.08), transparent 40%),
    var(--bg);
}

.auth-layout {
  display: flex;
  width: 100%;
  max-width: 880px;
  min-height: 480px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px 44px;
  background:
    radial-gradient(circle at 85% 10%, rgba(255, 255, 255, 0.14), transparent 45%),
    linear-gradient(150deg, var(--accent-2) 0%, var(--accent) 45%, #2c3e8f 80%, #1a2350 100%);
  color: white;
  overflow: hidden;
}

.auth-brand-icon {
  position: relative;
  z-index: 1;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 1.7rem;
  margin-bottom: 20px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.auth-brand h1 {
  position: relative;
  z-index: 1;
  margin: 0 0 14px;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.auth-brand p {
  margin: 0;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.92rem;
  line-height: 1.6;
  max-width: 320px;
}

.auth-form-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  padding: 40px;
}

.auth-form-card {
  width: 100%;
  max-width: 300px;
}

.auth-form-card h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 26px;
  line-height: 1.5;
}

.auth-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.auth-form-card input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 18px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-form-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

.auth-form-card button {
  width: 100%;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-accent);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.auth-form-card button:hover {
  box-shadow: 0 8px 22px rgba(91, 140, 255, 0.5);
  transform: translateY(-1px);
}

.auth-form-card button:active {
  transform: translateY(1px);
}

.auth-form-card button:disabled {
  opacity: 0.6;
  cursor: default;
}

.error {
  color: #ff6b6b;
  font-size: 0.85rem;
  margin-top: 10px;
}

@media (max-width: 720px) {
  .auth-layout {
    flex-direction: column;
    max-width: 380px;
    min-height: 0;
  }

  .auth-brand {
    padding: 32px 28px 24px;
    text-align: center;
    align-items: center;
  }

  .auth-brand-icon {
    margin-bottom: 14px;
  }

  .auth-brand p {
    display: none;
  }

  .auth-form-panel {
    padding: 32px 28px;
  }

  .auth-form-card input {
    font-size: 16px;
  }
}

/* App screen */
#app-screen {
  display: flex;
  height: 100%;
}

#sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 14px rgba(0, 0, 0, 0.25);
  position: relative;
  z-index: 3;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-dim);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 2;
}

.sidebar-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sidebar-identity #admin-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-small {
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.sidebar-header strong {
  color: var(--text);
}

.sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

#customer-search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.88rem;
}

#customer-search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.sidebar-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.icon-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 52px;
  flex-shrink: 0;
  padding: 12px 0;
  border-right: 1px solid var(--border);
}

.rail-icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.rail-icon-btn:active {
  transform: scale(0.94);
}

.rail-icon-btn-bottom {
  margin-top: auto;
}

.rail-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ff5b5b;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45), 0 0 0 2px var(--panel);
}

.rail-icon-btn:hover {
  background: var(--panel-alt);
  color: var(--text);
}

.rail-icon-btn.active {
  background: var(--accent-dim);
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(91, 140, 255, 0.35);
}

#customer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-width: 0;
}

.user-item {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.12s ease;
}

.user-item:hover {
  background: var(--panel-alt);
}

.user-item.active {
  background: var(--accent-grad);
  box-shadow: inset 3px 0 0 rgba(255, 255, 255, 0.5);
}

.user-item.active .customer-name-text,
.user-item.active .preview,
.user-item.active .dot,
.user-item.active .badge {
  color: white;
}

.user-item.active .preview {
  color: rgba(255, 255, 255, 0.85);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.online { background: var(--online); }
.dot.offline { background: var(--offline); }

.customer-item {
  align-items: center;
  gap: 10px;
}

.customer-avatar {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm), 0 0 0 2px rgba(255, 255, 255, 0.06);
}

.customer-avatar svg {
  width: 25px;
  height: 25px;
  fill: rgba(255, 255, 255, 0.95);
}

.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--panel);
}

.presence-dot.online { background: var(--online); }
.presence-dot.offline { background: var(--offline); }

.presence-dot.online::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--online);
  animation: presence-pulse 2.2s ease-out infinite;
}

@keyframes presence-pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(2.4); opacity: 0; }
}

.user-item.active .presence-dot { box-shadow: 0 0 0 2px var(--accent); }

.customer-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.customer-item .name-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  font-weight: 600;
}

.customer-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}

.customer-item .preview {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-item .badge {
  flex-shrink: 0;
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

.customer-item .badge.archived-tag {
  background: var(--panel-alt);
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-weight: 600;
}

.user-item.active .badge.archived-tag {
  background: rgba(255, 255, 255, 0.18);
  color: white;
  border-color: transparent;
}

.customer-item.waiting .name-row {
  color: var(--text);
}

#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 2;
}

#chat-header-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-status {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
}

.chat-header-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.chat-header-status.online { color: var(--online); }
.chat-header-status.online::before { background: var(--online); }
.chat-header-status.offline { color: var(--text-dim); }
.chat-header-status.offline::before { background: var(--offline); }

.header-icon-btn {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.header-icon-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
  background: var(--panel-alt);
}

/* Panel info customer (khusus admin) */
#customer-panel {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 14px rgba(0, 0, 0, 0.25);
  position: relative;
  z-index: 3;
}

.customer-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 2;
}

#customer-panel-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-value {
  font-size: 0.95rem;
  word-break: break-word;
}

.archive-btn {
  margin-top: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.archive-btn:hover {
  border-color: var(--text-dim);
  background: var(--panel-alt);
}

.archive-btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.archive-btn.danger:hover {
  background: rgba(229, 72, 77, 0.12);
}

/* Saved Replies */
.saved-replies-card {
  max-width: 420px;
  text-align: left;
}

/* Dashboard Statistik (halaman penuh) */
#stats-view {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#stats-view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 1.05rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 2;
}

#stats-view-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px clamp(20px, 4vw, 56px);
}

.stats-summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
}

.stats-summary-card {
  flex: 1;
  min-width: 160px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-md);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stats-summary-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stats-summary-label {
  font-size: 0.74rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-summary-value {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stats-summary-sub {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.stats-delta {
  font-size: 0.78rem;
  font-weight: 600;
}

.stats-delta.up { color: var(--online); }
.stats-delta.down { color: #ff6b6b; }
.stats-delta.flat { color: var(--text-dim); }

.stats-chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px clamp(16px, 3vw, 32px);
  box-shadow: var(--shadow-md);
  max-width: 900px;
}

.stats-chart-title {
  margin: 0 0 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stats-chart-total {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.stats-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 220px;
  padding: 0 2px;
  border-bottom: 1px solid var(--border);
}

.stats-bar-wrap {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  position: relative;
}

.stats-bar {
  width: 100%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  opacity: 0.75;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.stats-bar-wrap:hover .stats-bar {
  opacity: 1;
  transform: scaleY(1.01);
}

.stats-bar-wrap.is-today .stats-bar {
  background: #ffb020;
  opacity: 1;
}

.stats-bar-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 0.72rem;
  white-space: nowrap;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
  z-index: 5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.stats-bar-wrap:hover .stats-bar-tooltip {
  opacity: 1;
}

.stats-chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.74rem;
  color: var(--text-dim);
}

@media (max-width: 640px) {
  .stats-summary-card {
    min-width: 130px;
  }

  .stats-summary-value {
    font-size: 1.6rem;
  }

  .stats-chart {
    height: 150px;
  }
}

.saved-replies-card h2 {
  text-align: center;
}

.saved-replies-card .hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 0 0 14px;
  text-align: center;
}

.saved-replies-card kbd {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.78rem;
  font-family: inherit;
}

#saved-replies-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.saved-reply-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  cursor: pointer;
  transition: background 0.12s ease;
}

.saved-reply-item:hover {
  background: var(--accent-dim);
}

.saved-reply-text {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  word-break: break-word;
}

.saved-reply-delete-btn {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 4px;
}

.saved-reply-delete-btn:hover {
  color: #ff6b6b;
}

.saved-reply-empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  padding: 12px 0;
}

.history-log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-log-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.history-log-item:hover {
  border-color: var(--text-dim);
  background: var(--accent-dim);
}

.history-log-icon {
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1.3;
}

.history-log-body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-log-title {
  font-size: 0.9rem;
  font-weight: 600;
  word-break: break-word;
}

.history-log-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
}

#saved-reply-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

#saved-reply-input {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.9rem;
}

#saved-reply-form button {
  flex-shrink: 0;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: white;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-accent);
  transition: transform 0.12s ease;
}

#saved-reply-form button:hover {
  transform: translateY(-1px);
}

#saved-replies-close-btn {
  width: 100%;
}

.header-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

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

#messages:empty {
  align-items: center;
  justify-content: center;
}

#messages:empty::after {
  content: "💬";
  font-size: 2.4rem;
  opacity: 0.25;
}

.date-divider {
  align-self: center;
  background: var(--panel-alt);
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 999px;
  margin: 4px 0;
}

.message {
  max-width: 65%;
  padding: 9px 13px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  background: var(--panel-alt);
  align-self: flex-start;
  box-shadow: var(--shadow-sm);
}

.message.mine {
  background: var(--accent-dim);
  align-self: flex-end;
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(91, 140, 255, 0.18);
}

.sender-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.message .sender {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.msg-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-image {
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}

.edited-badge {
  font-size: 0.68rem;
  color: var(--text-dim);
  font-style: italic;
}

.msg-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.msg-action-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 1px 3px;
  line-height: 1;
}

.msg-action-btn:hover {
  color: var(--text);
}

.edit-wrap {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.edit-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.edit-save-btn,
.edit-cancel-btn {
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  cursor: pointer;
}

.edit-save-btn {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}

.edit-cancel-btn {
  background: transparent;
  color: var(--text-dim);
}

.message p {
  margin: 0;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg-link {
  color: var(--accent-2);
  text-decoration: underline;
  word-break: break-all;
}

.msg-link:hover {
  text-decoration: none;
}

.option-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.option-btn {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.option-btn:hover {
  background: var(--accent-dim);
}

.option-btn:active {
  transform: scale(0.97);
}

.option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.option-btn:disabled:hover {
  background: transparent;
}

.option-limit-hint {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
}

/* Versi read-only dipakai di tampilan admin & arsip riwayat -- bukan
   tombol beneran, cuma nunjukin pilihan apa yang ditawarkan ke customer. */
.option-tag {
  cursor: default;
  border-style: dashed;
  color: var(--text-dim);
}

.option-tag:hover {
  background: transparent;
}

/* Di sisi customer, tombol pilihan dibikin berjejer ke bawah (list rapi)
   alih-alih baris pill yang bisa numpuk kalau labelnya panjang/banyak. */
#chat-screen .option-buttons {
  flex-direction: column;
  align-items: stretch;
}

#chat-screen .option-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  text-align: left;
}

#chat-screen .option-btn::after {
  content: "›";
  flex-shrink: 0;
  font-weight: 700;
  opacity: 0.6;
}

.typing-preview {
  padding: 12px 20px;
  font-size: 1.05rem;
  color: var(--text-dim);
  font-style: italic;
  border-top: 1px solid var(--border);
  background: var(--panel-alt);
  word-break: break-word;
}

.typing-preview strong {
  color: var(--text);
  font-style: normal;
  font-weight: 600;
}

.msg-time {
  display: block;
  margin-top: 4px;
  font-size: 0.65rem;
  color: var(--text-dim);
  text-align: right;
}

#message-form {
  position: relative;
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.18);
  z-index: 2;
}

#message-form.locked {
  pointer-events: none;
  opacity: 0.5;
}

.session-ended-banner {
  margin: 0;
  padding: 10px 20px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: #e5484d;
  background: rgba(229, 72, 77, 0.1);
  border-top: 1px solid var(--border);
}

.hours-offline-banner {
  margin: 0;
  padding: 10px 20px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: #ffb020;
  background: rgba(255, 176, 32, 0.12);
  border-bottom: 1px solid var(--border);
}

#login-screen .hours-offline-banner {
  border: 1px solid rgba(255, 176, 32, 0.35);
  border-radius: var(--radius-sm);
  margin: 14px 0;
  text-align: left;
}

.reply-suggestions {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 100%;
  margin-bottom: 6px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.reply-suggestion-item {
  padding: 9px 12px;
  font-size: 0.88rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

.reply-suggestion-item:last-child {
  border-bottom: none;
}

.reply-suggestion-item:hover,
.reply-suggestion-item.highlighted {
  background: var(--accent-dim);
}

#message-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#message-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

#message-form button {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: white;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-accent);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

#message-form button:hover {
  box-shadow: 0 8px 20px rgba(91, 140, 255, 0.45);
  transform: translateY(-1px);
}

#message-form button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(91, 140, 255, 0.35);
}

@media (max-width: 640px) {
  #app-screen { flex-direction: column; }
  #sidebar {
    width: 100%;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #customer-panel {
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* Standalone customer chat page (index.html) */
#chat-screen {
  display: flex;
  justify-content: center;
}

#chat-screen .chat-container {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
}

@media (max-width: 640px) {
  #chat-screen .chat-container {
    border-left: none;
    border-right: none;
  }

  #chat-screen #chat-header {
    padding: 14px 16px;
    font-size: 0.95rem;
  }

  #chat-screen #messages {
    padding: 12px 14px;
  }

  #chat-screen .message {
    max-width: 85%;
  }

  #chat-screen #message-form {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  #chat-screen #message-input {
    font-size: 16px;
  }

  #chat-screen .attach-btn {
    width: 38px;
  }

  #chat-screen #message-form button[type="submit"] {
    padding: 10px 12px;
  }
}

/* Attach-image button in chat forms */
.attach-btn {
  flex-shrink: 0;
  width: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-dim);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.attach-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
  background: var(--panel-alt);
}

/* Settings modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-overlay.lightbox {
  cursor: zoom-out;
}

.lightbox-image {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.image-confirm-card {
  max-width: 420px;
}

.image-confirm-preview {
  display: block;
  max-width: 100%;
  max-height: 50vh;
  margin: 14px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.history-detail-card {
  padding: 0;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  text-align: left;
  overflow: hidden;
}

.history-detail-card .customer-panel-header {
  border-radius: 0;
}

.history-detail-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.history-detail-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-card h2 {
  margin: 0 0 16px;
  font-size: 1.2rem;
}

/* Pengaturan (halaman penuh, tiap sub-menu punya section sendiri) */
#settings-profile-view,
#settings-appearance-view,
#settings-autochat-view {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.settings-view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 1.05rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 2;
}

.settings-view-layout {
  flex: 1;
  min-height: 0;
  display: flex;
}

.settings-sub-nav {
  flex-shrink: 0;
  width: 180px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 12px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.settings-sub-nav-btn {
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.settings-sub-nav-btn:hover {
  color: var(--text);
  background: var(--panel-alt);
}

.settings-sub-nav-btn.active {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.settings-view-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px clamp(20px, 4vw, 56px);
}

.settings-view-body > * {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

@media (max-width: 640px) {
  .settings-view-layout {
    flex-direction: column;
  }

  .settings-sub-nav {
    width: auto;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    overflow-x: auto;
  }

  .settings-sub-nav-btn {
    flex-shrink: 0;
  }
}

.settings-panel {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px clamp(20px, 3vw, 36px);
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
}

.settings-panel .avatar-preview-wrap {
  justify-content: center;
}

.settings-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 20px;
  line-height: 1.5;
}

.settings-panel input[type="text"],
.settings-panel textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  margin-bottom: 14px;
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.settings-panel input[type="text"]:focus,
.settings-panel textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

.settings-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.settings-checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.hours-days-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 16px;
}

.hours-days-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.hours-days-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.settings-panel input[type="time"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  flex: 1;
  margin-bottom: 0;
}

.color-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.color-input-row input[type="color"] {
  width: 48px;
  height: 42px;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  cursor: pointer;
  margin-bottom: 0;
}

.color-input-row input[type="text"] {
  flex: 1;
  margin-bottom: 0;
}

.settings-panel button {
  width: 100%;
  max-width: 260px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: white;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-accent);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.settings-panel button:hover {
  box-shadow: 0 8px 20px rgba(91, 140, 255, 0.45);
  transform: translateY(-1px);
}

.settings-panel button:active {
  transform: translateY(1px);
}

.btn-logout {
  width: 100%;
  max-width: 260px;
  margin-top: 8px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #ff6b6b;
  background: transparent;
  color: #ff6b6b;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-logout:hover {
  background: rgba(255, 107, 107, 0.12);
}

.avatar-preview-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.avatar-preview {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background-color: var(--accent-dim);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  box-shadow: var(--shadow-md), 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.file-btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 14px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.file-btn:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.modal-card input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.modal-card input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.rating-card .hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 0 0 4px;
}

.rating-card textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  margin-bottom: 14px;
  resize: vertical;
}

.rating-stars {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 2.2rem;
  line-height: 1;
  margin: 6px 0 18px;
}

.rating-star {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--border);
  transition: color 0.15s ease, transform 0.1s ease;
}

.rating-star.active {
  color: #ffb020;
  transform: scale(1.12);
}

.rating-thanks {
  margin: 4px 0 0;
  font-weight: 600;
  color: var(--online);
}

#rating-submit-btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease;
}

#rating-submit-btn:hover {
  transform: translateY(-1px);
}

#rating-submit-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.chat-header-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#rating-btn {
  margin-left: auto;
}

.btn-secondary {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn-secondary:hover {
  border-color: var(--text-dim);
  background: var(--panel-alt);
}

#settings-save-btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease;
}

#settings-save-btn:hover {
  transform: translateY(-1px);
}
