/* =====================================================================
   Freeda — style.css
   Tema terang bersih, responsif (mobile-first), aksen copper & teal halus.
   ===================================================================== */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f2efea;
  --text: #232019;
  --text-muted: #7a736a;
  --border: #e7e2da;
  --border-strong: #d8d1c6;

  --copper: #b45309;
  --copper-600: #9a4708;
  --copper-soft: #fbeee0;
  --teal: #0f766e;
  --teal-soft: #e4f1ef;

  --danger: #b42318;
  --danger-soft: #fdecea;

  --user-bubble: #efe9e0;
  --shadow-sm: 0 1px 2px rgba(30, 25, 18, 0.06);
  --shadow-md: 0 4px 16px rgba(30, 25, 18, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --maxw: 760px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  /* Full viewport height, dynamic untuk mobile (menghindari bar browser) */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ------------------------------ Header ------------------------------ */
.app-header {
  flex: 0 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-avatar {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--copper), #d97706);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
  flex: 0 0 auto;
}
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.mode-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid #cfe6e2;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Tombol / penanda "Mode Intern" di header */
.header-actions { display: flex; align-items: center; gap: 8px; }
.intern-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--text-muted); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 5px 11px; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.intern-btn:hover { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
.intern-btn.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.intern-btn.active:hover { background: #0c5f58; }

/* Tombol "Percakapan Baru" (reset chat) — pil netral, hover aksen copper */
.newchat-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--text-muted); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 5px 11px; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.newchat-btn:hover { border-color: var(--copper); color: var(--copper); background: var(--copper-soft); }

/* Toggle "Suara" (TTS auto-play) di header */
.voice-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--text-muted); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 5px 11px; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.voice-btn:hover { border-color: var(--copper); color: var(--copper); background: var(--copper-soft); }
.voice-btn.active { background: var(--copper); border-color: var(--copper); color: #fff; }
.voice-btn.active:hover { background: var(--copper-600); }

/* Tombol "dengarkan" (speaker) di tiap pesan Freeda */
.speaker-btn {
  margin-top: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); cursor: pointer; transition: all .15s;
}
.speaker-btn:hover { border-color: var(--copper); color: var(--copper); background: var(--copper-soft); }
.speaker-btn.playing { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
.speaker-btn.loading { opacity: .6; cursor: default; }
.speaker-btn.loading svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }

/* Tombol mikrofon (STT) di composer */
.mic-btn { color: var(--text-muted); }
.mic-btn:hover { background: var(--surface-2); color: var(--copper); }
.mic-btn.recording { color: #fff; background: var(--danger); animation: micpulse 1.2s ease-in-out infinite; }
@keyframes micpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(180,35,24,.45); } 50% { box-shadow: 0 0 0 6px rgba(180,35,24,0); } }

/* Toggle bahasa mic (ID/EN) */
.lang-btn {
  flex: 0 0 auto; align-self: center;
  font-family: inherit; font-size: 11px; font-weight: 700; letter-spacing: .3px;
  color: var(--text-muted); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 5px 7px; cursor: pointer; transition: all .15s;
}
.lang-btn:hover { border-color: var(--copper); color: var(--copper); }

.composer-hint.hint-warn { color: var(--danger); font-weight: 600; }
body.intern-mode .voice-btn.active { background: var(--teal); border-color: var(--teal); }

/* Penanda mode intern aktif: aksen teal pada composer & tombol kirim */
body.intern-mode .composer-form:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
body.intern-mode .send-btn { background: var(--teal); }
body.intern-mode .send-btn:hover { background: #0c5f58; }

/* ------------------------------ Chat -------------------------------- */
.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}
.messages {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 22px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Baris pesan */
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff;
  flex: 0 0 auto; margin-top: 2px;
  background: linear-gradient(135deg, var(--copper), #d97706);
}
.msg-body { min-width: 0; }
.msg-name { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 3px; }
.msg-text {
  font-size: 15.5px; line-height: 1.62; color: var(--text);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg-text p { margin: 0 0 10px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text strong { font-weight: 650; }
.msg-text ul { margin: 6px 0; padding-left: 20px; }
.msg-text li { margin: 3px 0; }
.msg-text .msg-h { font-weight: 700; font-size: 15px; margin: 12px 0 5px; color: var(--text); }
.msg-text .msg-h:first-child { margin-top: 0; }
.msg-text .msg-hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg-text .msg-pre {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; margin: 8px 0; overflow-x: auto;
}
.msg-text .msg-pre code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px; white-space: pre; color: var(--text);
}

/* Pesan Freeda (kiri) */
.msg.freeda { }

/* Pesan pengguna (kanan, dengan bubble) */
.msg.user {
  flex-direction: row-reverse;
}
.msg.user .msg-avatar {
  background: var(--surface-2);
  color: var(--text-muted);
}
.msg.user .msg-body {
  display: flex; flex-direction: column; align-items: flex-end;
}
.msg.user .msg-text {
  background: var(--user-bubble);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  max-width: 100%;
}

/* Kursor kedip saat streaming */
.cursor::after {
  content: "▋";
  color: var(--copper);
  margin-left: 1px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* Indikator "sedang mengetik" */
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--border-strong);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .6; } 30% { transform: translateY(-5px); opacity: 1; } }

/* --------------------- Empty state / sapaan ------------------------- */
.welcome { text-align: center; padding: 6vh 8px 0; }
.welcome-avatar {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--copper), #d97706);
  color: #fff; font-size: 28px; font-weight: 700;
  display: grid; place-items: center; box-shadow: var(--shadow-md);
}
.welcome h1 { font-size: 22px; margin: 0 0 6px; }
.welcome p { color: var(--text-muted); font-size: 14.5px; margin: 0 auto; max-width: 440px; line-height: 1.55; }
.suggestions {
  display: flex; flex-wrap: wrap; gap: 9px; justify-content: center;
  margin-top: 20px;
}
.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s ease;
  font-family: inherit;
}
.chip:hover { border-color: var(--copper); background: var(--copper-soft); color: var(--copper-600); }

/* ------------------------------ Kartu ------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-md);
  max-width: 100%;
  animation: rise .25s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.card-title { font-weight: 700; font-size: 16px; }
.card-sub { color: var(--text-muted); font-size: 13px; margin: 4px 0 14px; line-height: 1.5; }

.field { margin-bottom: 12px; display: flex; flex-direction: column; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field-narrow { max-width: 120px; }
.field label { font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #4a4238; }
.req { color: var(--copper); }

.field input, .field select {
  font-family: inherit;
  font-size: 14.5px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--copper);
  box-shadow: 0 0 0 3px var(--copper-soft);
}
.field-or { text-align: center; color: var(--text-muted); font-size: 12px; margin: 2px 0 10px; position: relative; }

/* Input file (drop) */
.file-drop {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  transition: all .15s;
  background: var(--surface-2);
}
.file-drop:hover, .file-drop:focus { border-color: var(--copper); background: var(--copper-soft); outline: none; }
.file-drop.has-file { border-style: solid; border-color: var(--teal); background: var(--teal-soft); }
.file-drop-icon { font-size: 20px; }
.file-drop-text { font-size: 13.5px; color: var(--text-muted); }
.file-drop.has-file .file-drop-text { color: var(--teal); font-weight: 600; }
.file-drop-sm { padding: 10px 12px; }
.opt { color: var(--text-muted); font-weight: 400; font-size: 12px; }
.field-note { font-size: 12px; color: var(--text-muted); margin: -2px 0 7px; line-height: 1.45; }

/* Consent */
.consent {
  display: flex; gap: 9px; align-items: flex-start;
  font-size: 13px; color: #4a4238; line-height: 1.45;
  margin: 6px 0 4px; cursor: pointer;
}
.consent input { margin-top: 2px; width: 16px; height: 16px; accent-color: var(--copper); flex: 0 0 auto; }

/* Aksi kartu */
.card-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.btn {
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 18px; border-radius: var(--radius-sm);
  cursor: pointer; border: 1px solid transparent; transition: all .15s;
}
.btn-primary { background: var(--copper); color: #fff; }
.btn-primary:hover { background: var(--copper-600); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.card-error {
  background: var(--danger-soft); color: var(--danger);
  font-size: 13px; padding: 9px 12px; border-radius: var(--radius-sm);
  margin-top: 4px; line-height: 1.45;
}
/* Catatan info netral (mis. status membaca CV desain, atau portfolio opsional) */
.card-note {
  background: var(--teal-soft); color: var(--teal);
  font-size: 12.5px; padding: 9px 12px; border-radius: var(--radius-sm);
  margin-top: 4px; line-height: 1.45;
}

/* CV-first: notis penggunaan data di kartu unggah */
.cv-notice {
  font-size: 12.5px; color: var(--text-muted); line-height: 1.5;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; margin: 2px 0 2px;
}

/* CV-first: field yang tidak terbaca dari CV (perlu diisi) */
.field.missing input {
  border-color: #d98a2b;
  background: #fff8ef;
}
.field-hint { font-size: 11.5px; color: var(--copper); margin-top: 4px; }
.field-hint-info { color: var(--teal); }

/* ------------------------- Stepper status --------------------------- */
.result-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-md); animation: rise .25s ease; }
.result-head { margin-bottom: 16px; }
.result-name { font-weight: 700; font-size: 15px; }
.result-meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.result-code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 7px; border-radius: 6px; font-size: 12.5px; }

.stepper { display: flex; align-items: flex-start; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; position: relative; }
.step-dot {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: var(--surface);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--text-muted);
  z-index: 2;
}
.step-line { position: absolute; top: 12px; left: -50%; width: 100%; height: 2px; background: var(--border-strong); z-index: 1; }
.step:first-child .step-line { display: none; }
.step-label { font-size: 11px; margin-top: 7px; color: var(--text-muted); line-height: 1.2; overflow-wrap: normal; word-break: keep-all; hyphens: none; padding: 0 2px; }

.step.done .step-dot { background: var(--teal); border-color: var(--teal); color: #fff; }
.step.done .step-line { background: var(--teal); }
.step.current .step-dot { border-color: var(--copper); color: var(--copper); background: var(--copper-soft); box-shadow: 0 0 0 4px var(--copper-soft); }
.step.current .step-label { color: var(--copper-600); font-weight: 700; }
.step.done .step-label { color: var(--text); }

/* Hasil akhir keputusan (outcome) */
.outcome { margin-top: 16px; border-radius: 12px; padding: 15px 16px; }
.outcome-accepted { background: #e8f6ee; border: 1px solid #b6e2c8; }
.outcome-accepted .outcome-title { color: #157a45; font-weight: 700; font-size: 15.5px; }
.outcome-accepted .outcome-msg { color: #2c6b49; font-size: 13.5px; margin-top: 6px; line-height: 1.55; }
.outcome-rejected { background: var(--surface-2); border: 1px solid var(--border); text-align: center; padding: 22px 18px; }
.outcome-rejected .outcome-icon {
  width: 46px; height: 46px; border-radius: 50%;
  background: #f7e6e3; color: var(--danger);
  display: grid; place-items: center; font-size: 20px; font-weight: 700;
  margin: 0 auto 10px;
}
.outcome-rejected .outcome-title { font-weight: 700; font-size: 16px; color: var(--text); }
.outcome-rejected .outcome-msg { color: var(--text-muted); font-size: 13.5px; margin-top: 8px; line-height: 1.6; }

/* ------------------------- Composer (input) ------------------------- */
.composer {
  flex: 0 0 auto;
  background: linear-gradient(to top, var(--bg) 60%, rgba(247,246,243,0));
  padding-bottom: env(safe-area-inset-bottom);
}
.composer-inner { max-width: var(--maxw); margin: 0 auto; padding: 8px 16px 12px; }
.composer-form {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 7px 8px 7px 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.composer-form:focus-within { border-color: var(--copper); box-shadow: 0 0 0 3px var(--copper-soft); }
.composer-input {
  flex: 1; border: none; outline: none; resize: none;
  font-family: inherit; font-size: 15.5px; line-height: 1.5;
  background: transparent; color: var(--text);
  max-height: 160px; padding: 7px 2px; min-width: 0;
}
.composer-input::placeholder { color: #a49b8e; }

.icon-btn {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer; display: grid; place-items: center;
  transition: all .15s; background: transparent;
}
.attach-btn { color: var(--text-muted); }
.attach-btn:hover { background: var(--surface-2); color: var(--copper); }
.send-btn { background: var(--copper); color: #fff; }
.send-btn:hover { background: var(--copper-600); }
.send-btn:disabled { background: var(--border-strong); cursor: default; }

.composer-hint { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 7px; }

/* ------------------------------ Responsif --------------------------- */
@media (max-width: 480px) {
  .field-row { flex-direction: column; gap: 0; }
  .field-narrow { max-width: none; }
  .messages { padding: 16px 12px 22px; }
  .header-inner { padding: 9px 13px; }
  .intern-btn-label { display: none; }        /* sisakan ikon gembok saja */
  .intern-btn { padding: 6px 8px; }
  .newchat-btn-label { display: none; }       /* sisakan ikon + saja */
  .newchat-btn { padding: 6px 8px; }
  .voice-btn-label { display: none; }          /* sisakan ikon speaker saja */
  .voice-btn { padding: 6px 8px; }
  .brand-sub { display: none; }               /* beri ruang di header sempit */
  .composer-inner { padding: 6px 12px 10px; }
  .welcome h1 { font-size: 20px; }
  .step-label { font-size: 10px; }
  .card-actions { flex-direction: column-reverse; }
  .card-actions .btn { width: 100%; }
}

/* Scrollbar halus (desktop) */
.chat::-webkit-scrollbar { width: 10px; }
.chat::-webkit-scrollbar-thumb { background: #dcd6cc; border-radius: 10px; border: 3px solid var(--bg); }
.chat::-webkit-scrollbar-thumb:hover { background: #cfc7ba; }
