* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #0f1115;
  --bg-2: #161a22;
  --bg-3: #1e2430;
  --fg: #e6e9ef;
  --muted: #8b93a5;
  --accent: #baE85c;
  --accent-fg: #17210a;
  --user: #2a3242;
  --danger: #ff6b6b;
  --border: #262d3b;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px;
  padding: 32px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { font-size: 22px; letter-spacing: .5px; }
.login-card input {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px;
  color: var(--fg); padding: 11px 12px; font-size: 15px;
}
.login-card button {
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 8px;
  padding: 11px; font-weight: 700; font-size: 15px; cursor: pointer;
}
.error { color: var(--danger); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- Layout ---------- */
.layout { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 280px; min-width: 280px; background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-head { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.brand { font-weight: 800; letter-spacing: .5px; }
.btn-primary {
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 8px;
  padding: 9px; font-weight: 700; cursor: pointer;
}
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.sidebar-controls {
  padding: 6px 14px; display: flex; justify-content: space-between; align-items: center;
}
.sidebar-controls select {
  background: var(--bg-3); color: var(--fg); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 6px;
}
.session-list { flex: 1; overflow-y: auto; padding: 6px; }
.session-item {
  padding: 10px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
.session-item:hover { background: var(--bg-3); }
.session-item.active { background: var(--bg-3); outline: 1px solid var(--border); }
.session-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.seg-chip {
  display: inline-block; background: var(--bg); border: 1px solid var(--border);
  color: var(--muted); border-radius: 20px; padding: 1px 8px; font-size: 10.5px; margin-top: 4px;
}
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }

/* ---------- Chat ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-area { flex: 1; overflow-y: auto; padding: 24px 0; }
.empty-state { text-align: center; margin-top: 18vh; padding: 0 24px; }
.empty-state h2 { margin-bottom: 8px; }
.messages { max-width: 780px; margin: 0 auto; padding: 0 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 14px; border-radius: 14px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble { background: var(--user); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--bg-3); border-bottom-left-radius: 4px; }
.msg-time { font-size: 10.5px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
/* FASE 2: slot tombol play TTS per pesan assistant — hidden sampai fase 2 */
.msg-audio-slot { display: none; }

.segment-divider {
  text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0;
  display: flex; align-items: center; gap: 10px;
}
.segment-divider::before, .segment-divider::after { content: ""; flex: 1; border-top: 1px dashed var(--border); }
.segment-divider button {
  background: var(--bg-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 20px; padding: 3px 12px; cursor: pointer; font-size: 11.5px;
}

.archive-banner {
  max-width: 780px; margin: 0 auto 6px; padding: 8px 14px; width: calc(100% - 40px);
  background: #23281a; border: 1px solid #3c4526; color: #c9d8a4;
  border-radius: 8px; font-size: 12.5px;
}

/* ---------- Composer ---------- */
.composer {
  display: flex; gap: 10px; padding: 14px 20px 18px; max-width: 820px; margin: 0 auto; width: 100%;
}
.composer textarea {
  flex: 1; resize: none; background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  font-size: 15px; font-family: inherit; max-height: 160px;
}
.composer textarea:focus { outline: 1px solid var(--accent); }
.composer button {
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 12px;
  padding: 0 22px; font-weight: 700; cursor: pointer;
}
.composer button:disabled { opacity: .5; cursor: default; }

/* ---------- Modal segmen ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
/* Atribut hidden kalah spesifisitas dari display:flex di atas — wajib override eksplisit,
   kalau tidak modal tampil terus sejak load dan tombol close "tidak berfungsi". */
.modal[hidden] { display: none; }
.modal-box {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 14px;
  width: min(760px, 94vw); max-height: 84vh; display: flex; flex-direction: column;
}
.modal-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; font-weight: 700;
}
.modal-messages { overflow-y: auto; padding: 18px 20px; }

/* ---------- Mobile ---------- */
/* Hamburger & backdrop: default mati di desktop; hanya aktif di media query bawah.
   Pakai class .show/.open (bukan atribut hidden) — hindari konflik specificity display. */
.btn-menu { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 40; height: 100dvh; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .msg { max-width: 96%; }

  .btn-menu {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 10px; left: 10px; z-index: 45;
    width: 40px; height: 40px; font-size: 20px; line-height: 1;
    background: var(--bg-2); color: var(--fg);
    border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  }
  .sidebar-backdrop.show {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 35;
  }
  /* Ruang untuk tombol hamburger supaya tidak menutupi pesan pertama */
  .chat-area { padding-top: 60px; }
  /* ...dan supaya tidak menimpa header sidebar (brand + New Chat) saat terbuka */
  .sidebar-head { padding-top: 60px; }
}
