/* Chat Pak Yanto — tata letak ponsel dulu; layar lebar hanya menambah margin. */
:root {
  --bg: #0b141a;
  --panel: #111b21;
  --bar: #1f2c33;
  --line: #22343d;
  --text: #e9edef;
  --muted: #8696a0;
  --in: #1f2c33;
  --out: #005c4b;
  --accent: #00a884;
  --danger: #f15c6d;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eae6df;
    --panel: #f7f5f3;
    --bar: #f0f2f5;
    --line: #d9d3cb;
    --text: #111b21;
    --muted: #667781;
    --in: #ffffff;
    --out: #d9fdd3;
    --accent: #008069;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--panel);
}

/* ------------------------------------------------------------------ header */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.avatar {
  width: 40px; height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #00a884, #056162);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .5px;
}

.who { flex: 1; min-width: 0; }
.who h1 { margin: 0; font-size: 16px; font-weight: 600; }
.who p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.who p.is-typing { color: var(--accent); }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: italic 600 15px/1 Georgia, serif;
  cursor: pointer;
}

/* -------------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1;
  padding: 11px 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .2px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.panel.is-active { display: flex; }

/* ----------------------------------------------------------------- mode bar */
.modebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.segmented {
  display: flex;
  flex: 1;
  background: var(--bar);
  border-radius: 999px;
  padding: 3px;
  gap: 3px;
}
.seg {
  flex: 1;
  padding: 7px 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.seg.is-active { background: var(--accent); color: #fff; }

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
}

/* ------------------------------------------------------------------ thread */
.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 4px;
  background:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,.03) 0 2px, transparent 2px) 0 0/28px 28px,
    var(--bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.daychip {
  align-self: center;
  background: var(--bar);
  color: var(--muted);
  font-size: 11.5px;
  padding: 5px 11px;
  border-radius: 999px;
  text-align: center;
  max-width: 90%;
}

.msg {
  max-width: 84%;
  padding: 8px 11px 6px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
  box-shadow: 0 1px 1px rgba(0,0,0,.18);
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(4px); opacity: 0; } }

.msg.in { align-self: flex-start; background: var(--in); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--out); border-top-right-radius: 4px; }
.msg.err { align-self: center; background: transparent; border: 1px solid var(--danger); color: var(--danger); font-size: 13px; }

.stamp {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
}

.sources { margin-top: 6px; border-top: 1px solid rgba(255,255,255,.09); padding-top: 4px; }
.sources summary { font-size: 11.5px; color: var(--muted); cursor: pointer; list-style: none; }
.sources summary::-webkit-details-marker { display: none; }
.sources ul { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.sources li { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.sources b { color: var(--text); font-weight: 600; }

.typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* --------------------------------------------------------------- suggestion */
.suggest {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px 2px;
  scrollbar-width: none;
}
.suggest::-webkit-scrollbar { display: none; }
.suggest:empty { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--bar);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 13px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--bar);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 130px;
  padding: 11px 13px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* < 16px membuat iOS zoom saat fokus */
  line-height: 1.35;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.send {
  width: 46px; height: 46px;
  flex: 0 0 46px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.send svg { width: 21px; height: 21px; fill: #fff; }
.send:disabled { opacity: .45; }

/* ------------------------------------------------------------------- arsip */
.searchbar { padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.searchbar input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bar);
  color: var(--text);
  font-size: 16px;
}
.searchbar input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px calc(16px + var(--safe-b));
  display: grid;
  gap: 8px;
  align-content: start;
}
.card {
  background: var(--in);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
}
.card .meta .tag {
  background: var(--bar);
  border-radius: 999px;
  padding: 2px 8px;
}
.card p { margin: 0; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 30px 12px; }

/* ------------------------------------------------------------------- sheet */
.sheet {
  border: 0;
  border-radius: 16px;
  padding: 18px;
  max-width: 460px;
  width: calc(100% - 32px);
  background: var(--panel);
  color: var(--text);
}
.sheet::backdrop { background: rgba(0,0,0,.55); }
.sheet h2 { margin: 0 0 10px; font-size: 16px; }
.sheet dl { margin: 0 0 14px; font-size: 13.5px; }
.sheet dt { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; margin-top: 10px; }
.sheet dd { margin: 2px 0 0; overflow-wrap: anywhere; }
