:root {
  --bg: #f8f4ec;
  --panel: #fffaf2;
  --text: #2c2118;
  --muted: #7d6b59;
  --line: #e7dac8;
  --accent: #6d4c2f;
  --accent-dark: #51351f;
  --soft: #efe3d2;
  --success: #276749;
  --danger: #9b2c2c;
  --shadow: 0 18px 45px rgba(88, 62, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fff8ea, var(--bg) 45%, #efe2cf);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 28px 22px;
  background: rgba(255, 250, 242, 0.92);
  backdrop-filter: blur(12px);
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #a7774d);
  color: white;
  font-size: 30px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.brand h1,
.brand p,
.panel h2,
.hero h2,
.hero p {
  margin: 0;
}

.brand h1 {
  font-size: 24px;
  letter-spacing: -0.03em;
}

.brand p {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 10px 24px rgba(88, 62, 38, 0.07);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.panel h2 {
  font-size: 16px;
  margin-bottom: 8px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 14px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin: 14px 0 7px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--text);
  border-radius: 14px;
  padding: 12px 13px;
  outline: none;
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 92px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(109, 76, 47, 0.12);
}

.checkbox-row {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 500;
}

.checkbox-row input {
  width: auto;
}

.primary-btn,
.ghost-btn {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 800;
  transition: 0.2s ease;
}

.primary-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  padding: 12px 16px;
  margin-top: 12px;
}

.primary-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.ghost-btn {
  background: var(--soft);
  color: var(--accent-dark);
  padding: 8px 10px;
  font-size: 12px;
}

.status {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.status.success {
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

.kitab-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.kitab-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fffdf8;
}

.kitab-item strong {
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.kitab-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.main-content {
  padding: 34px;
  min-width: 0;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: stretch;
  margin-bottom: 22px;
}

.badge {
  display: inline-flex;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 12px;
}

.hero h2 {
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.05;
  max-width: 820px;
  letter-spacing: -0.045em;
}

.hero p {
  max-width: 720px;
  color: var(--muted);
  margin-top: 12px;
  line-height: 1.6;
}

.hero-card {
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
  align-self: flex-end;
}

.hero-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.hero-card strong {
  font-size: 18px;
}

.chat-card {
  background: rgba(255, 250, 242, 0.86);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-log {
  height: calc(100vh - 290px);
  min-height: 360px;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 900;
  font-size: 12px;
}

.message.user .avatar {
  background: var(--accent);
  color: white;
}

.bubble {
  max-width: min(820px, 86%);
  background: white;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 15px 16px;
  line-height: 1.62;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.bubble p {
  margin: 0 0 9px;
}

.bubble ul {
  margin: 0;
  padding-left: 19px;
  white-space: normal;
}

.sample-title {
  font-weight: 800;
}

.sources {
  margin-top: 14px;
  display: grid;
  gap: 9px;
  white-space: normal;
}

.source-item {
  background: #fff8ec;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  font-size: 13px;
}

.source-item strong {
  display: block;
  margin-bottom: 5px;
}

.source-item span {
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

.chat-form {
  border-top: 1px solid var(--line);
  padding: 18px;
  background: #fffaf2;
}

.chat-actions {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
}

.chat-actions label {
  max-width: 160px;
  margin-top: 10px;
}

.chat-actions .primary-btn {
  max-width: 180px;
}

.loading {
  opacity: 0.72;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .hero {
    flex-direction: column;
  }

  .main-content {
    padding: 22px;
  }

  .chat-log {
    height: auto;
    max-height: 620px;
  }
}

.bubble {
  max-width: min(900px, 92%);
  font-size: 15px;
  line-height: 1.75;
  white-space: normal;
}

.answer-content p {
  margin: 0 0 12px;
}

.answer-content strong {
  font-weight: 800;
  color: var(--accent-dark);
}

.answer-content h3 {
  font-size: 17px;
  margin: 18px 0 8px;
  color: var(--accent-dark);
}

.answer-list {
  padding-left: 12px;
  border-left: 3px solid var(--soft);
}

.answer-content hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.sources {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.sources summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--accent-dark);
  background: #fff8ec;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  list-style: none;
}

.sources summary::-webkit-details-marker {
  display: none;
}

.sources summary::after {
  content: " +";
  float: right;
}

.sources[open] summary::after {
  content: " −";
}

.source-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.source-item {
  background: #fffaf2;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  font-size: 13px;
}

.source-snippet {
  color: #4a3a2a;
  line-height: 1.55;
}

.message.assistant .bubble {
  background: #ffffff;
}

.message.user .bubble {
  max-width: min(620px, 80%);
}

/* === Perapian jawaban AI === */
.bubble {
  max-width: min(900px, 92%);
  font-size: 15px;
  line-height: 1.75;
  white-space: normal;
}

.answer-content p {
  margin: 0 0 12px;
}

.answer-content strong {
  font-weight: 800;
  color: var(--accent-dark, #6b4327);
}

.answer-content em {
  font-style: italic;
}

.answer-content h3 {
  font-size: 17px;
  margin: 18px 0 8px;
  color: var(--accent-dark, #6b4327);
}

.answer-list {
  padding-left: 12px;
  border-left: 3px solid var(--soft, #ead8c2);
}

.answer-content hr {
  border: 0;
  border-top: 1px solid var(--line, #ead8c2);
  margin: 18px 0;
}

.sources {
  margin-top: 18px;
  border-top: 1px solid var(--line, #ead8c2);
  padding-top: 12px;
}

.sources summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--accent-dark, #6b4327);
  background: #fff8ec;
  border: 1px solid var(--line, #ead8c2);
  border-radius: 12px;
  padding: 10px 12px;
  list-style: none;
}

.sources summary::-webkit-details-marker {
  display: none;
}

.sources summary::after {
  content: " +";
  float: right;
}

.sources[open] summary::after {
  content: " −";
}

.source-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.source-item {
  background: #fffaf2;
  border: 1px solid var(--line, #ead8c2);
  border-radius: 14px;
  padding: 12px;
  font-size: 13px;
}

.source-item span {
  display: block;
  margin: 4px 0 8px;
  color: #7b6a58;
}

.source-snippet {
  color: #4a3a2a;
  line-height: 1.55;
}

.message.assistant .bubble {
  background: #ffffff;
}

.message.user .bubble {
  max-width: min(620px, 80%);
}

.answer-content h2 {
  font-size: 18px;
  margin: 20px 0 10px;
  color: var(--accent-dark, #6b4327);
  font-weight: 800;
}

.answer-content h3 {
  font-size: 16px;
  margin: 18px 0 8px;
  color: var(--accent-dark, #6b4327);
  font-weight: 800;
}

/* === Perbaikan arah teks Arab-Latin === */
.answer-content,
.source-snippet,
.source-item,
.bubble {
  direction: ltr;
  unicode-bidi: plaintext;
  text-align: left;
}

.answer-content p,
.answer-content h2,
.answer-content h3,
.answer-list {
  unicode-bidi: plaintext;
}

.source-snippet {
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: anywhere;
}

.arabic-text {
  direction: rtl;
  text-align: right;
  font-family: "Scheherazade New", "Amiri", "Times New Roman", serif;
  font-size: 18px;
  line-height: 2;
}

/* === Tombol hapus kitab === */
.kitab-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kitab-info {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.delete-kitab-btn {
  border: 1px solid #e6b8a8;
  background: #fff3ef;
  color: #9b2c1f;
  border-radius: 10px;
  padding: 7px 10px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.delete-kitab-btn:hover {
  background: #ffe5dc;
}

.delete-kitab-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* =========================================================
   PREMIUM UI - KitabAI Pesantren
   ========================================================= */

:root {
  --bg: #f5efe4;
  --panel: rgba(255, 252, 246, 0.92);
  --panel-solid: #fffaf2;
  --text: #21170f;
  --muted: #7a6652;
  --line: #e4d5c1;
  --accent: #214734;
  --accent-dark: #123321;
  --accent-2: #8a633a;
  --gold: #c9a66b;
  --soft: #eee2d1;
  --success: #18704a;
  --danger: #a12e25;
  --shadow: 0 22px 70px rgba(55, 39, 22, 0.16);
}

body {
  background:
    radial-gradient(circle at 12% 8%, rgba(201, 166, 107, 0.22), transparent 28%),
    radial-gradient(circle at 90% 12%, rgba(33, 71, 52, 0.16), transparent 26%),
    linear-gradient(135deg, #fbf6ec 0%, #f3eadc 52%, #eadcc8 100%);
  color: var(--text);
}

.app-shell {
  grid-template-columns: 360px minmax(0, 1fr);
}

.sidebar {
  background: rgba(255, 250, 242, 0.78);
  border-right: 1px solid rgba(120, 84, 45, 0.18);
  box-shadow: 12px 0 40px rgba(70, 47, 25, 0.08);
  backdrop-filter: blur(18px);
}

.brand {
  padding: 8px 6px 18px;
  border-bottom: 1px solid rgba(120, 84, 45, 0.14);
}

.brand-mark {
  background:
    linear-gradient(145deg, var(--accent), #2d6548);
  box-shadow: 0 16px 35px rgba(33, 71, 52, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.45);
}

.brand h1 {
  font-size: 27px;
  font-weight: 900;
  letter-spacing: -0.05em;
}

.brand p {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

.panel {
  background: rgba(255, 252, 246, 0.86);
  border: 1px solid rgba(116, 82, 47, 0.17);
  border-radius: 26px;
  box-shadow: 0 18px 45px rgba(62, 41, 20, 0.08);
}

.panel h2 {
  font-size: 17px;
  font-weight: 900;
}

.hint {
  font-size: 13px;
}

input,
select,
textarea {
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(125, 93, 59, 0.2);
  border-radius: 18px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(33, 71, 52, 0.12);
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), #2c6549);
  border-radius: 18px;
  box-shadow: 0 14px 28px rgba(33, 71, 52, 0.23);
}

.primary-btn:hover {
  background: linear-gradient(135deg, var(--accent-dark), #214734);
  transform: translateY(-2px);
}

.ghost-btn {
  background: #efe4d3;
  color: var(--accent-dark);
  border-radius: 16px;
}

.main-content {
  padding: 48px 42px;
}

.hero {
  position: relative;
  padding: 12px 0 8px;
  margin-bottom: 28px;
}

.hero::after {
  content: "";
  position: absolute;
  right: 0;
  top: -10px;
  width: 190px;
  height: 190px;
  background:
    radial-gradient(circle, rgba(201, 166, 107, 0.28), transparent 65%);
  pointer-events: none;
}

.badge {
  display: none !important;
}

.hidden-system-card,
.hero-card {
  display: none !important;
}

.hero h2 {
  max-width: 860px;
  font-size: clamp(38px, 5vw, 68px);
  line-height: 0.92;
  font-weight: 950;
  letter-spacing: -0.07em;
  color: #1f1710;
}

.hero p {
  max-width: 780px;
  margin-top: 22px;
  font-size: 18px;
  line-height: 1.75;
  color: var(--muted);
}

.chat-card {
  background: rgba(255, 252, 246, 0.76);
  border: 1px solid rgba(116, 82, 47, 0.16);
  border-radius: 34px;
  box-shadow: 0 28px 90px rgba(76, 50, 24, 0.13);
  overflow: hidden;
  backdrop-filter: blur(16px);
}

.chat-log {
  padding: 30px;
}

.message {
  gap: 14px;
  margin-bottom: 22px;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 18px;
  background: #efe2cf;
  color: var(--accent-dark);
  font-weight: 900;
}

.message.assistant .avatar {
  background: linear-gradient(145deg, #efe2cf, #f8f1e6);
}

.message.user {
  justify-content: flex-end;
}

.message.user .avatar {
  background: linear-gradient(145deg, var(--accent), #2d6548);
  color: white;
}

.bubble {
  border-radius: 24px;
  border: 1px solid rgba(116, 82, 47, 0.16);
  box-shadow: 0 14px 38px rgba(60, 39, 18, 0.08);
}

.message.assistant .bubble {
  background: rgba(255, 255, 255, 0.88);
}

.message.user .bubble {
  background: linear-gradient(135deg, #6f4a2e, #835a37);
  color: white;
  border: 0;
}

.answer-content h2,
.answer-content h3 {
  color: var(--accent-dark);
}

.answer-list {
  border-left: 4px solid rgba(201, 166, 107, 0.55);
  background: rgba(250, 244, 234, 0.58);
  border-radius: 0 14px 14px 0;
  padding: 9px 12px;
}

.sources summary {
  background: linear-gradient(135deg, #f8efe1, #fffaf2);
  color: var(--accent-dark);
  border-radius: 16px;
}

.source-item {
  background: rgba(255, 250, 242, 0.86);
  border-radius: 18px;
}

.chat-form {
  background: rgba(255, 250, 242, 0.84);
  border-top: 1px solid rgba(116, 82, 47, 0.16);
  padding: 22px;
}

.chat-form textarea {
  min-height: 110px;
  border-radius: 22px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.86);
}

.chat-actions {
  align-items: end;
}

.chat-actions .primary-btn {
  max-width: 250px;
  height: 54px;
}

#topK {
  max-width: 120px;
}

.kitab-item {
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.72);
  transition: 0.18s ease;
}

.kitab-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(68, 44, 19, 0.09);
}

.delete-kitab-btn {
  border-radius: 14px;
}

/* Responsive */
@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .main-content {
    padding: 28px 18px;
  }

  .hero h2 {
    font-size: 40px;
  }

  .chat-actions {
    display: grid;
    gap: 14px;
  }

  .chat-actions .primary-btn {
    max-width: none;
    width: 100%;
  }
}

#providerSelect {
  max-width: 190px;
  height: 54px;
  font-weight: 800;
  color: var(--accent-dark, #123321);
  background: rgba(255, 255, 255, 0.86);
}

.chat-actions label {
  font-size: 13px;
  font-weight: 900;
  color: var(--muted, #7a6652);
}

#providerSelect {
  max-width: 190px;
  height: 54px;
  font-weight: 800;
  color: var(--accent-dark, #123321);
  background: rgba(255, 255, 255, 0.86);
  border-radius: 18px;
}

.chat-actions label {
  font-size: 13px;
  font-weight: 900;
  color: var(--muted, #7a6652);
}

.ai-mode-field {
  display: grid;
  gap: 6px;
}

.ai-mode-field label {
  font-size: 13px;
  font-weight: 900;
  color: var(--muted, #7a6652);
}

#providerSelect {
  width: 190px;
  height: 54px;
  font-weight: 800;
  color: var(--accent-dark, #123321);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(125, 93, 59, 0.2);
  border-radius: 18px;
  padding: 0 14px;
}

/* === Mode Kitab Arab === */
#kitabMode {
  height: 54px;
  font-weight: 800;
  color: var(--accent-dark, #123321);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(125, 93, 59, 0.2);
  border-radius: 18px;
  padding: 0 14px;
}

.status.success {
  line-height: 1.55;
}

.ai-mode-field {
  display: none !important;
}

/* === Format jawaban AI lebih rapi === */
.answer-content h2,
.answer-content h3 {
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(120, 84, 45, 0.16);
  color: var(--accent-dark, #123321);
  font-weight: 900;
}

.answer-content p {
  margin: 0 0 10px;
  line-height: 1.75;
}

.answer-content blockquote {
  margin: 10px 0 14px;
  padding: 14px 18px;
  border-right: 4px solid var(--gold, #c9a66b);
  border-left: none;
  background: #fff8ec;
  border-radius: 16px;
  direction: rtl;
  text-align: right;
  font-family: "Times New Roman", "Amiri", "Scheherazade New", serif;
  font-size: 18px;
  line-height: 2;
}

.answer-content .answer-list {
  margin: 8px 0;
  padding: 10px 14px;
  background: rgba(250, 244, 234, 0.65);
  border-left: 4px solid rgba(201, 166, 107, 0.6);
  border-radius: 0 14px 14px 0;
}

.sources {
  margin-top: 18px;
}

.sources summary {
  font-size: 14px;
}

.source-snippet {
  max-height: 90px;
  overflow: hidden;
}

/* === Jawaban AI bersih dan profesional === */
.answer-content h2,
.answer-content h3 {
  margin: 20px 0 10px;
  padding: 0 0 8px;
  border-bottom: 1px solid rgba(120, 84, 45, 0.15);
  color: var(--accent-dark, #123321);
  font-size: 18px;
  font-weight: 900;
}

.answer-content p {
  margin: 0 0 12px;
  line-height: 1.8;
}

.answer-content p:has(+ p) {
  margin-bottom: 10px;
}

.answer-list {
  margin: 8px 0;
  padding: 10px 14px;
  background: rgba(250, 244, 234, 0.65);
  border-left: 4px solid rgba(201, 166, 107, 0.65);
  border-radius: 0 14px 14px 0;
}

.answer-content blockquote,
.answer-content .arabic-quote {
  margin: 12px 0 16px;
  padding: 16px 20px;
  background: #fff8ec;
  border-right: 4px solid var(--gold, #c9a66b);
  border-left: none;
  border-radius: 16px;
  direction: rtl;
  text-align: right;
  font-family: "Times New Roman", "Amiri", "Scheherazade New", serif;
  font-size: 18px;
  line-height: 2;
}

.bubble {
  max-width: min(920px, 94%);
}

.source-snippet {
  max-height: 100px;
  overflow: hidden;
}

/* === Label Penanya dan KitabAI lebih profesional === */
.avatar {
  min-width: 58px;
  width: 58px;
  height: 42px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.01em;
}

.message.user .avatar {
  background: linear-gradient(135deg, #1f5b3c, #2b744f);
  color: #ffffff;
  box-shadow: 0 10px 22px rgba(31, 91, 60, 0.22);
}

.message.assistant .avatar {
  background: #efe3d0;
  color: #123321;
  border: 1px solid rgba(120, 84, 45, 0.15);
}

/* === Bubble pertanyaan lebih elegan === */
.message.user {
  align-items: flex-start;
}

.message.user .bubble {
  background: linear-gradient(135deg, #7a4f30, #8d6040);
  color: #ffffff;
  border-radius: 28px 28px 8px 28px;
  padding: 20px 24px;
  font-weight: 700;
  box-shadow: 0 18px 42px rgba(90, 55, 27, 0.22);
}

/* === Bubble jawaban lebih rapi === */
.message.assistant .bubble {
  border-radius: 28px 28px 28px 8px;
  padding: 24px 28px;
}

/* === Judul bagian jawaban: tebal + batas bawah === */
.answer-section-title,
.answer-content h2,
.answer-content h3 {
  display: block;
  margin: 22px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(120, 84, 45, 0.18);
  color: var(--accent-dark, #123321);
  font-size: 18px;
  font-weight: 950;
  line-height: 1.35;
}

.answer-content .answer-section-title:first-child,
.answer-content h3:first-child {
  margin-top: 0;
}

/* === Paragraf jawaban nyaman dibaca === */
.answer-content p {
  font-size: 16px;
  line-height: 1.85;
  margin: 0 0 13px;
}

/* === Kutipan Arab lebih bagus === */
.answer-content blockquote,
.arabic-quote {
  margin: 14px 0 18px;
  padding: 16px 20px;
  background: #fff8ec;
  border-right: 5px solid var(--gold, #c9a66b);
  border-left: none;
  border-radius: 18px;
  direction: rtl;
  text-align: right;
  font-family: "Times New Roman", "Amiri", "Scheherazade New", serif;
  font-size: 19px;
  line-height: 2.1;
  color: #20160f;
}

/* === Input pertanyaan lebih profesional === */
.chat-form {
  border-top: 1px solid rgba(120, 84, 45, 0.16);
  background: rgba(255, 250, 242, 0.92);
}

.chat-form textarea {
  border-radius: 26px;
  border: 1px solid rgba(120, 84, 45, 0.18);
  background: rgba(255, 255, 255, 0.92);
  font-size: 16px;
  line-height: 1.7;
  padding: 20px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
}

.chat-form textarea:focus {
  border-color: #1f5b3c;
  box-shadow: 0 0 0 4px rgba(31, 91, 60, 0.12);
}

/* === Tombol kirim lebih premium === */
.chat-actions .primary-btn {
  border-radius: 22px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.01em;
}

/* === Sumber kitab tidak terlalu mengganggu === */
.sources summary {
  margin-top: 16px;
  font-weight: 900;
  border-radius: 16px;
}

.source-snippet {
  max-height: 92px;
  overflow: hidden;
}

/* === Avatar ikon chat: Anda dan KitabAI === */
.avatar-wrap {
  width: 58px;
  min-width: 58px;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 6px;
  margin-top: 6px;
}

.avatar-icon {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1f5b3c, #2b744f);
  color: #ffffff;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(31, 91, 60, 0.22);
}

.kitab-icon {
  background: linear-gradient(135deg, #efe3d0, #fff7eb);
  color: #123321;
  border: 1px solid rgba(120, 84, 45, 0.18);
  font-family: "Times New Roman", "Amiri", "Scheherazade New", serif;
  font-size: 26px;
  line-height: 1;
}

.avatar-label {
  font-size: 11px;
  font-weight: 900;
  color: var(--muted, #7a6652);
  text-align: center;
  line-height: 1.1;
}

/* Matikan gaya avatar lama agar tidak bentrok */
.avatar {
  display: none !important;
}

/* Posisi user tetap enak dilihat */
.message.user {
  align-items: flex-start;
}

.message.assistant {
  align-items: flex-start;
}

/* Bubble user lebih rapi dengan avatar ikon */
.message.user .bubble {
  border-radius: 28px 28px 8px 28px;
}

/* Bubble AI lebih rapi dengan avatar ikon */
.message.assistant .bubble {
  border-radius: 28px 28px 28px 8px;
}

/* === Checklist kitab rujukan === */
.kitab-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.kitab-check-wrap {
  display: grid;
  place-items: center;
  cursor: pointer;
}

.kitab-check {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.kitab-checkmark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(31, 91, 60, 0.25);
  background: #fffaf2;
  color: transparent;
  font-size: 16px;
  font-weight: 900;
  transition: 0.15s ease;
}

.kitab-check:checked + .kitab-checkmark {
  background: linear-gradient(135deg, #1f5b3c, #2b744f);
  color: #ffffff;
  border-color: #1f5b3c;
  box-shadow: 0 8px 18px rgba(31, 91, 60, 0.22);
}

.mini-btn {
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 12px;
}

.panel-header {
  gap: 8px;
  flex-wrap: wrap;
}

.kitab-info {
  min-width: 0;
}

/* === Checklist kitab rujukan === */
.kitab-item {
  display: grid !important;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
}

.kitab-check-wrap {
  display: grid;
  place-items: center;
  cursor: pointer;
}

.kitab-check {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.kitab-checkmark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(31, 91, 60, 0.25);
  background: #fffaf2;
  color: transparent;
  font-size: 16px;
  font-weight: 900;
  transition: 0.15s ease;
}

.kitab-check:checked + .kitab-checkmark {
  background: linear-gradient(135deg, #1f5b3c, #2b744f);
  color: #ffffff;
  border-color: #1f5b3c;
  box-shadow: 0 8px 18px rgba(31, 91, 60, 0.22);
}

.kitab-info {
  min-width: 0;
}

/* === Checklist kitab versi elegan === */
.kitab-item {
  position: relative;
  display: grid !important;
  grid-template-columns: 1fr auto !important;
  align-items: center;
  gap: 12px;
  padding: 18px 16px !important;
  border-radius: 22px !important;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(120, 84, 45, 0.16);
  transition: 0.18s ease;
}

.kitab-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(70, 44, 22, 0.10);
}

.kitab-check-wrap {
  position: absolute;
  top: 12px;
  right: 78px;
  cursor: pointer;
  z-index: 2;
}

.kitab-check {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.kitab-checkmark {
  width: auto;
  min-width: 74px;
  height: 28px;
  padding: 0 10px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid rgba(31, 91, 60, 0.20);
  background: #f5efe4;
  color: #7a6652;
  font-size: 0;
  font-weight: 900;
  box-shadow: none;
}

.kitab-checkmark::after {
  content: "Tidak dipakai";
  font-size: 11px;
}

.kitab-check:checked + .kitab-checkmark {
  background: linear-gradient(135deg, #1f5b3c, #2b744f);
  color: #ffffff;
  border-color: #1f5b3c;
  box-shadow: 0 8px 18px rgba(31, 91, 60, 0.20);
}

.kitab-check:checked + .kitab-checkmark::after {
  content: "Dipakai";
  font-size: 11px;
}

.kitab-info {
  min-width: 0;
  padding-right: 88px;
}

.kitab-info strong {
  display: block;
  font-size: 15px;
  line-height: 1.25;
  font-weight: 900;
  color: #21170f;
  margin-bottom: 6px;
}

.kitab-info span {
  display: block;
  font-size: 12px;
  line-height: 1.35;
  color: #7a6652;
  word-break: break-word;
}

.delete-kitab-btn {
  align-self: end;
  justify-self: end;
  border-radius: 999px !important;
  padding: 8px 14px !important;
  font-size: 13px !important;
  font-weight: 900;
  background: #fff3ef !important;
}

/* Hilangkan gaya checkbox kotak lama */
.kitab-checkmark {
  border-radius: 999px !important;
}

/* Kalau sidebar sempit, badge turun sedikit agar tidak tabrakan */
@media (max-width: 1100px) {
  .kitab-check-wrap {
    right: 70px;
  }

  .kitab-info {
    padding-right: 78px;
  }
}

/* =========================================================
   FIX FINAL: Checklist daftar kitab + Top-K lebih rapi
   ========================================================= */

/* Card daftar kitab */
.kitab-item {
  position: relative !important;
  display: grid !important;
  grid-template-columns: 28px 1fr auto !important;
  align-items: center !important;
  gap: 12px !important;
  padding: 16px 14px !important;
  border-radius: 22px !important;
  background: rgba(255, 255, 255, 0.78) !important;
  border: 1px solid rgba(120, 84, 45, 0.16) !important;
  box-shadow: none !important;
  min-height: 92px !important;
}

/* Jangan ada badge besar di kanan atas */
.kitab-check-wrap {
  position: static !important;
  width: 28px !important;
  height: 28px !important;
  display: grid !important;
  place-items: center !important;
  cursor: pointer !important;
  z-index: 1 !important;
}

/* Input checkbox asli disembunyikan */
.kitab-check {
  position: absolute !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Kotak checklist kecil seperti checkbox upload */
.kitab-checkmark {
  width: 26px !important;
  min-width: 26px !important;
  height: 26px !important;
  padding: 0 !important;
  border-radius: 8px !important;
  border: 1px solid rgba(31, 91, 60, 0.28) !important;
  background: #f7f0e6 !important;
  color: transparent !important;
  display: grid !important;
  place-items: center !important;
  font-size: 0 !important;
  box-shadow: none !important;
}

/* Hilangkan teks Dipakai/Tidak dipakai */
.kitab-checkmark::after {
  content: "" !important;
}

/* Saat aktif muncul centang kecil */
.kitab-check:checked + .kitab-checkmark {
  background: linear-gradient(135deg, #1f5b3c, #2b744f) !important;
  border-color: #1f5b3c !important;
  box-shadow: 0 6px 14px rgba(31, 91, 60, 0.20) !important;
}

.kitab-check:checked + .kitab-checkmark::after {
  content: "✓" !important;
  color: #ffffff !important;
  font-size: 18px !important;
  font-weight: 900 !important;
  line-height: 1 !important;
}

/* Informasi kitab */
.kitab-info {
  min-width: 0 !important;
  padding-right: 0 !important;
}

.kitab-info strong {
  display: block !important;
  font-size: 15px !important;
  line-height: 1.25 !important;
  font-weight: 900 !important;
  color: #21170f !important;
  margin-bottom: 5px !important;
  word-break: normal !important;
}

.kitab-info span {
  display: block !important;
  font-size: 12px !important;
  line-height: 1.35 !important;
  color: #7a6652 !important;
  word-break: break-word !important;
}

/* Tombol hapus lebih kecil */
.delete-kitab-btn {
  justify-self: end !important;
  align-self: center !important;
  border-radius: 999px !important;
  padding: 8px 13px !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  background: #fff3ef !important;
  color: #9b2c1f !important;
  border: 1px solid #e6b8a8 !important;
  white-space: nowrap !important;
}

/* Daftar kitab tidak terlalu sempit */
#kitabList {
  display: grid !important;
  gap: 12px !important;
}

/* Top-K sumber lebih rapi */
.chat-actions {
  display: grid !important;
  grid-template-columns: 150px 1fr 240px !important;
  gap: 18px !important;
  align-items: end !important;
}

.chat-actions label {
  display: block !important;
  margin-bottom: 7px !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  color: var(--muted, #7a6652) !important;
}

#topK {
  width: 130px !important;
  max-width: 130px !important;
  height: 48px !important;
  border-radius: 18px !important;
  padding: 0 16px !important;
  font-size: 16px !important;
  font-weight: 800 !important;
}

/* Tombol kirim tetap proporsional */
.chat-actions .primary-btn {
  width: 100% !important;
  height: 54px !important;
  border-radius: 22px !important;
}

/* Kalau Mode AI disembunyikan, Top-K tetap rapi */
.ai-mode-field {
  display: none !important;
}

@media (max-width: 980px) {
  .chat-actions {
    grid-template-columns: 1fr !important;
  }

  #topK {
    width: 100% !important;
    max-width: none !important;
  }
}

/* === Kembalikan tombol Kirim Pertanyaan seperti sebelumnya === */
.chat-actions {
  display: flex !important;
  align-items: end !important;
  justify-content: space-between !important;
  gap: 18px !important;
}

.chat-actions .primary-btn {
  width: 240px !important;
  max-width: 240px !important;
  height: 54px !important;
  margin-left: auto !important;
  border-radius: 22px !important;
}

/* Top-K dibuat kecil saja di kiri */
#topK {
  width: 120px !important;
  max-width: 120px !important;
  height: 48px !important;
  border-radius: 18px !important;
  padding: 0 16px !important;
  font-size: 16px !important;
  font-weight: 800 !important;
}

.chat-actions label {
  display: block !important;
  margin-bottom: 7px !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  color: var(--muted, #7a6652) !important;
}

/* Mode AI tetap disembunyikan sementara */
.ai-mode-field {
  display: none !important;
}

@media (max-width: 980px) {
  .chat-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
  }

  .chat-actions .primary-btn {
    width: 100% !important;
    max-width: none !important;
    margin-left: 0 !important;
  }

  #topK {
    width: 100% !important;
    max-width: none !important;
  }
}
