:root {
  --bg: #1f1e1d;
  --surface: #262624;
  --surface-2: #30302e;
  --border: #3d3c39;
  --text: #eeece7;
  --text-dim: #8e8c86;
  --accent: #cc785c;
  --accent-strong: #b96548;
  --good: #7a9a6e;
  --bad: #b3564a;
  --radius: 16px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  flex: 0 0 auto;
}
.topbar .brand-icon {
  width: 24px;
  height: 24px;
  color: var(--accent);
}
.topbar nav {
  display: flex;
  flex: 0 0 auto;
  white-space: nowrap;
}
.topbar nav a {
  margin-left: 12px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 8px;
  white-space: nowrap;
}
.topbar nav a:active { background: var(--surface-2); }

@media (max-width: 380px) {
  .topbar { padding: 10px 12px; }
  .topbar .brand { font-size: 0.92rem; }
  .topbar nav a { margin-left: 8px; padding: 6px; font-size: 0.9rem; }
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.hero { text-align: center; padding: 20px 8px 8px; }
.hero h1 { font-size: 1.4rem; margin: 0 0 6px; }
.hero p { color: var(--text-dim); margin: 0; }

.chat-quickbox {
  display: flex;
  gap: 8px;
  margin: 16px 0 24px;
}
.chat-quickbox input {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}
.chat-quickbox button {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.chat-quickbox button:active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.chat-quickbox input:focus { outline: 2px solid var(--accent); }

button, .btn {
  background: var(--accent-strong);
  color: #fff;
  border: none;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}
button:active { background: var(--accent); }
button.secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
button.danger { background: var(--bad); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 20px 0 8px;
}

.worktitle-list { display: flex; flex-direction: column; gap: 10px; }
.worktitle-item {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.worktitle-item .cat {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 6px;
}
.worktitle-item h3 { margin: 0 0 4px; font-size: 1.05rem; color: var(--text); }
.worktitle-item p { margin: 0; color: var(--text-dim); font-size: 0.9rem; }

/* Chat view */
.chat-view { display: flex; flex-direction: column; }
.chat-log { padding-bottom: 8px; }
.msg { margin-bottom: 12px; max-width: 92%; }
.msg.user { margin-left: auto; text-align: right; }
.msg .bubble {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 14px;
  text-align: left;
  line-height: 1.5;
}
.msg.user .bubble { background: var(--accent-strong); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.assistant.pending .bubble { min-width: 190px; }
.msg .sources { margin-top: 6px; font-size: 0.78rem; color: var(--text-dim); }
.msg .sources a { color: var(--accent); }

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.typing-phrases {
  position: relative;
  display: inline-block;
  min-width: 148px;
  height: 1.5em;
  overflow: hidden;
}
.typing-phrases span {
  position: absolute;
  inset: 0;
  opacity: 0;
  white-space: nowrap;
  animation: typing-phrase 6s ease-in-out infinite;
}
.typing-phrases span:nth-child(2) { animation-delay: 2s; }
.typing-phrases span:nth-child(3) { animation-delay: 4s; }
.typing-dots { display: inline-flex; align-items: center; gap: 4px; height: 18px; }
.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.42;
  animation: typing-bounce 1.05s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.14s; }
.typing-dots i:nth-child(3) { animation-delay: 0.28s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.38; }
  30% { transform: translateY(-5px); opacity: 1; }
}
@keyframes typing-phrase {
  0%, 28% { opacity: 1; transform: translateY(0); }
  33%, 100% { opacity: 0; transform: translateY(5px); }
}

/* Rendered markdown inside assistant bubbles */
.msg .bubble p { margin: 0 0 8px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble ul, .msg .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.msg .bubble ul:last-child, .msg .bubble ol:last-child { margin-bottom: 0; }
.msg .bubble li { margin-bottom: 4px; }
.msg .bubble li:last-child { margin-bottom: 0; }
.msg .bubble strong { font-weight: 700; }
.msg .bubble code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.88em;
}
.msg .bubble h3, .msg .bubble h4 { margin: 10px 0 6px; font-size: 1rem; }
.msg .bubble h3:first-child, .msg .bubble h4:first-child { margin-top: 0; }

/* Chat input pinned to bottom of the viewport so it's always reachable */
.chat-input-row {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 10px 0;
  margin-top: 8px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}
.chat-input-row button {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.chat-input-row button:active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.chat-input-row button:disabled { border-color: var(--border); color: var(--text-dim); }
.chat-input-row.is-loading button { min-width: 76px; }

/* Work title detail */
.doc-meta { color: var(--text-dim); font-size: 0.85rem; line-height: 1.6; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.tahap { margin-bottom: 16px; }
.tahap h4 { margin: 0 0 8px; color: var(--accent); }
.langkah { border-top: 1px solid var(--border); padding: 10px 0; }
.langkah:first-child { border-top: none; }
.langkah .no { color: var(--text-dim); font-size: 0.8rem; margin-right: 6px; }
.langkah .meta { display: block; font-size: 0.8rem; color: var(--text-dim); margin-top: 4px; }
.langkah .meta.risiko { color: var(--bad); }

/* Daftar Simak */
.ds-section { margin-bottom: 18px; }
.ds-section h4 { margin: 0 0 10px; }
.ds-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}
.ds-item .text { margin-bottom: 10px; font-size: 0.95rem; }
.toggle { display: flex; gap: 8px; }
.toggle button {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 600;
  min-height: 44px;
  padding: 10px;
}
.toggle button.active-pos { background: color-mix(in srgb, var(--good) 16%, transparent); border-color: var(--good); color: var(--good); }
.toggle button.active-neg { background: color-mix(in srgb, var(--bad) 16%, transparent); border-color: var(--bad); color: var(--bad); }

.ds-notes textarea, .signoff-grid input {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
.ds-notes textarea { min-height: 70px; resize: vertical; }
.signoff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.signoff-grid label { grid-column: 1 / -1; font-size: 0.8rem; color: var(--text-dim); margin-top: 6px; }

.ds-progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.ds-progress .bar {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  margin: 0 10px;
  overflow: hidden;
}
.ds-progress .bar > div { height: 100%; background: var(--good); }

.ds-recommendation-hint {
  margin: -4px 0 18px;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.45;
}

.ds-recommendation {
  display: grid;
  gap: 3px;
  padding: 12px;
  margin: 0 0 18px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.ds-recommendation-label {
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ds-recommendation strong { font-size: 0.95rem; }
.ds-recommendation > span:last-child { color: var(--text-dim); font-size: 0.8rem; }
.ds-recommendation.is-good { border-left-color: var(--good); background: color-mix(in srgb, var(--good) 13%, var(--surface)); }
.ds-recommendation.is-warning { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, var(--surface)); }
.ds-recommendation.is-bad { border-left-color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, var(--surface)); }

.actions-row { display: flex; gap: 8px; margin-top: 16px; }
.actions-row button { flex: 1; }

.back-link { display: inline-block; margin-bottom: 12px; color: var(--text-dim); }

.empty-state { text-align: center; color: var(--text-dim); padding: 40px 16px; }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf9f5;
    --surface: #ffffff;
    --surface-2: #f0eee6;
    --border: #e5e2d9;
    --text: #2d2c2a;
    --text-dim: #7a776e;
  }
  .msg.user .bubble { color: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  .typing-dots i { animation: none; opacity: 0.75; }
  .typing-phrases { min-width: auto; }
  .typing-phrases span { display: none; animation: none; position: static; }
  .typing-phrases span:first-child { display: inline; opacity: 1; }
}
