:root {
  --color-primary: #F5821F;
  --color-primary-dark: #D96F13;
  --color-navy: #16212B;
  --color-navy-soft: #22303D;
  --color-red-accent: #D93A3A;
  --color-white: #FFFFFF;
  --color-ink: #1A1F26;
  --color-muted: #5B6672;
  --color-border: #E7E2DA;
  --color-cream: #FBF8F3;
  --color-panel: #F5F1EA;
  --font-display: "Sora", "Segoe UI", system-ui, sans-serif;
  --font-body: "Manrope", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* The browser's default [hidden] rule loses to our own .empty-pane/.thread-pane
   { display: flex } rules of equal specificity that come later in the
   cascade, so both panels rendered stacked at once. Force it to always win. */
[hidden] { display: none !important; }

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

body {
  font-family: var(--font-body);
  color: var(--color-ink);
  background: var(--color-cream);
  line-height: 1.5;
  overscroll-behavior-y: contain;
}

h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--color-navy);
  margin: 0;
}

a { color: inherit; text-decoration: none; }

button, input, textarea, select {
  font-family: var(--font-body);
  font-size: 0.95rem;
}

.icon svg { width: 1em; height: 1em; display: block; }
.icon { display: inline-flex; width: 20px; height: 20px; }
.icon-inline { width: 14px; height: 14px; vertical-align: -2px; margin-right: 2px; color: var(--color-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; transform: none; }
.btn-sm { padding: 7px 14px; font-size: 0.82rem; }

.btn-primary { background: var(--color-primary); color: var(--color-navy); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-dark); }

.btn-ghost { background: transparent; color: var(--color-navy); border: 1.5px solid var(--color-border); }
.btn-ghost:hover { border-color: var(--color-navy); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(22,33,43,0.06); color: var(--color-navy); }
.icon-btn input[type="file"] { display: none; }

/* ==================== LOGIN ==================== */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(900px 500px at 80% -10%, rgba(245,130,31,0.12), transparent 60%), var(--color-cream);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-white);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 24px 60px -30px rgba(22,33,43,0.35);
}
.login-logo { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 16px; }
.login-card h1 { font-size: 1.4rem; margin-bottom: 6px; }
.login-card p.sub { color: var(--color-muted); font-size: 0.9rem; margin: 0 0 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--color-navy); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  background: var(--color-cream);
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--color-primary); border-color: var(--color-primary); }
.error-msg { color: var(--color-red-accent); font-size: 0.85rem; margin: 4px 0 16px; min-height: 1em; }

/* ==================== INBOX SHELL ==================== */
.inbox-shell {
  display: flex;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
}

.inbox-sidebar {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-white);
  border-right: 1px solid var(--color-border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-avatar { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand-text strong { font-family: var(--font-display); font-size: 0.92rem; color: var(--color-navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-brand-text span { font-size: 0.76rem; color: var(--color-muted); }

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 16px;
  padding: 9px 14px;
  background: var(--color-panel);
  border-radius: 10px;
}
.sidebar-search .icon { color: var(--color-muted); }
.sidebar-search input { flex: 1; border: none; background: transparent; outline: none; }

.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--color-border);
  background: var(--color-white);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-muted);
  cursor: pointer;
}
.chip.active { background: var(--color-navy); color: var(--color-white); border-color: var(--color-navy); }

.contact-list { flex: 1; overflow-y: auto; }
.contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}
.contact-row:hover { background: var(--color-panel); }
.contact-row.active { background: rgba(245,130,31,0.10); }
.contact-body { flex: 1; min-width: 0; }
.contact-row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.contact-name { font-weight: 700; color: var(--color-navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-time { font-size: 0.72rem; color: var(--color-muted); flex-shrink: 0; }
.contact-row-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 3px; }
.contact-preview { font-size: 0.83rem; color: var(--color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; min-width: 0; }

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-white);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.badge { font-size: 0.68rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; flex-shrink: 0; }
.badge-baru { background: rgba(217,58,58,0.12); color: var(--color-red-accent); }
.badge-dihubungi { background: rgba(245,130,31,0.14); color: var(--color-primary-dark); }
.badge-terdaftar { background: rgba(34,140,90,0.14); color: #1E7A4C; }
.badge-diabaikan { background: rgba(91,102,114,0.14); color: var(--color-muted); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--color-muted); font-size: 0.9rem; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 12px; border-top: 1px solid var(--color-border); }
.pagination-label { font-size: 0.8rem; color: var(--color-muted); }

/* ---------- Main pane ---------- */
.inbox-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--color-panel);
  background-image: radial-gradient(circle at 1px 1px, rgba(22,33,43,0.05) 1px, transparent 0);
  background-size: 22px 22px;
}

.empty-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--color-muted);
}
.empty-pane-icon { width: 64px; height: 64px; color: var(--color-border); }
.empty-pane-icon svg { width: 100%; height: 100%; }

.thread-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.thread-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
}
.back-btn { display: none; }
.thread-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.thread-title strong { font-family: var(--font-display); color: var(--color-navy); font-size: 0.98rem; }
.thread-title span { font-size: 0.78rem; color: var(--color-muted); }
.status-select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--color-border);
  background: var(--color-cream);
  color: var(--color-navy);
  font-weight: 600;
  font-size: 0.82rem;
}

.notes-bar {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 16px;
  background: rgba(245,130,31,0.06);
  border-bottom: 1px solid var(--color-border);
}
.notes-bar textarea {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--color-white);
  resize: none;
  font-size: 0.85rem;
  min-height: 36px;
}

.bubble-list { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 10px; }
.bubble-row { display: flex; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: 68%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(22,33,43,0.06);
}
.bubble-row.in .bubble { background: var(--color-white); border-bottom-left-radius: 4px; }
.bubble-row.out .bubble { background: var(--color-primary); color: var(--color-navy); border-bottom-right-radius: 4px; }
.bubble-time {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 0.68rem;
  color: var(--color-muted);
  margin-top: 4px;
}
.bubble-tick { width: 15px; height: 15px; color: var(--color-primary-dark); }
.bubble-image { display: block; max-width: 280px; width: 100%; height: auto; border-radius: 10px; }
.bubble-caption { margin-top: 8px; }

.reply-box { background: var(--color-white); border-top: 1px solid var(--color-border); padding: 12px 16px; }
.reply-box textarea {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  border-radius: 10px;
  border: 1.5px solid var(--color-border);
  padding: 10px 14px;
  resize: vertical;
  margin-bottom: 8px;
}
.reply-actions { display: flex; align-items: center; gap: 10px; }
.reply-filename { font-size: 0.78rem; color: var(--color-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-send { margin-left: auto; }
.reply-closed {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--color-red-accent);
  background: rgba(217,58,58,0.08);
  padding: 12px 14px;
  border-radius: 8px;
  margin: 0;
}
.reply-closed .icon { flex-shrink: 0; }

/* ==================== Responsive: WhatsApp-style single-pane below 900px ==================== */
@media (max-width: 899px) {
  .inbox-sidebar { width: 100%; }
  .inbox-main { display: none; }
  body.has-thread .inbox-sidebar { display: none; }
  body.has-thread .inbox-main { display: flex; }
  .back-btn { display: inline-flex; }
  .bubble { max-width: 82%; }
}

@media (min-width: 900px) and (max-width: 1099px) {
  .inbox-sidebar { width: 320px; }
}

@media (max-width: 480px) {
  .thread-topbar { padding: 8px 10px; }
  .bubble-list { padding: 14px; }
  .avatar { width: 40px; height: 40px; font-size: 0.85rem; }
}
