/* ============================================================================
 *  ai-ui.css — gaya untuk Asisten Data dan AI Center.
 *
 *  Berkas ini MENUMPANG pada design system yang sudah ada di index.html:
 *  variabel --c-primary-*, kelas .dark untuk mode gelap, dan Tailwind untuk
 *  tata letak umum. Tidak ada satu pun aturan di sini yang menimpa selektor
 *  milik aplikasi; semuanya berawalan .ai- supaya bisa dicabut tanpa jejak.
 *
 *  Semua animasi dimatikan di bawah prefers-reduced-motion, sesuai perilaku
 *  yang sudah dipakai aplikasi.
 * ========================================================================== */

:root {
  --ai-radius:        18px;
  --ai-radius-sm:     12px;
  --ai-shadow:        0 10px 40px -10px rgba(15, 23, 42, .28), 0 2px 8px -2px rgba(15, 23, 42, .12);
  --ai-shadow-fab:    0 8px 24px -6px rgba(15, 23, 42, .35);
  --ai-surface:       #ffffff;
  --ai-surface-2:     #f8fafc;
  --ai-border:        #e2e8f0;
  --ai-text:          #0f172a;
  --ai-text-dim:      #64748b;
  --ai-ease:          cubic-bezier(.22, 1, .36, 1);
  --ai-drawer-w:      420px;
}

.dark {
  --ai-surface:   #0f172a;
  --ai-surface-2: #1e293b;
  --ai-border:    #334155;
  --ai-text:      #e2e8f0;
  --ai-text-dim:  #94a3b8;
  --ai-shadow:    0 10px 40px -10px rgba(0, 0, 0, .6), 0 2px 8px -2px rgba(0, 0, 0, .4);
}

/* ------------------------------------------------------------------ Tombol */
/* v1.6: variabel tema --c-primary-* berisi angka RGB ("33 83 139"), bukan warna jadi —
   dulu dipakai langsung sehingga tombol Asisten Data, tombol kirim, dan aksen lain
   kehilangan warna (tampil putih/transparan). Kini dibungkus rgb(). */

.ai-fab {
  position: fixed;
  right: 20px;
  bottom: 84px;                 /* di atas bottom-nav aplikasi di layar kecil */
  z-index: 60;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 999px;
  background: rgb(var(--c-primary-600, 79 70 229));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--ai-shadow-fab);
  transition: transform .18s var(--ai-ease), box-shadow .18s var(--ai-ease), opacity .18s;
}
.ai-fab:hover  { transform: translateY(-2px) scale(1.03); }
.ai-fab:active { transform: translateY(0) scale(.97); }
.ai-fab:focus-visible {
  outline: 3px solid rgb(var(--c-primary-300, 165 180 252));
  outline-offset: 3px;
}
.ai-fab[hidden] { display: none; }
.ai-fab.is-open { opacity: 0; pointer-events: none; }

.ai-fab__dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 10px; height: 10px;
  border-radius: 999px;
  background: #22c55e;
  border: 2px solid rgb(var(--c-primary-600, 79 70 229));
}
.ai-fab__dot--local { background: #f59e0b; }

@media (min-width: 768px) {
  .ai-fab { bottom: 24px; right: 24px; }
}

/* ------------------------------------------------------------------ Drawer */

.ai-scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(15, 23, 42, .35);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ai-ease);
}
.ai-scrim.is-open { opacity: 1; pointer-events: auto; }

.ai-drawer {
  position: fixed;
  z-index: 80;
  right: 0;
  top: 0;
  height: 100dvh;
  width: min(var(--ai-drawer-w), 100vw);
  background: var(--ai-surface);
  border-left: 1px solid var(--ai-border);
  box-shadow: var(--ai-shadow);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .26s var(--ai-ease);
  color: var(--ai-text);
}
.ai-drawer.is-open { transform: translateX(0); }

/* Di ponsel drawer naik dari bawah seperti sheet, bukan menggeser dari kanan. */
@media (max-width: 640px) {
  .ai-drawer {
    right: 0; left: 0;
    top: auto; bottom: 0;
    width: 100%;
    height: 88dvh;
    border-left: none;
    border-top: 1px solid var(--ai-border);
    border-radius: var(--ai-radius) var(--ai-radius) 0 0;
    transform: translateY(100%);
  }
  .ai-drawer.is-open { transform: translateY(0); }
}

.ai-drawer__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ai-border);
  background: var(--ai-surface-2);
  flex-shrink: 0;
}
.ai-drawer__grip {
  display: none;
}
@media (max-width: 640px) {
  .ai-drawer__grip {
    display: block;
    width: 38px; height: 4px;
    border-radius: 999px;
    background: var(--ai-border);
    margin: 8px auto 0;
  }
}
.ai-drawer__title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.ai-drawer__sub   { font-size: 11.5px; color: var(--ai-text-dim); margin-top: 2px; }
.ai-drawer__spacer{ flex: 1; }

.ai-iconbtn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ai-text-dim);
  width: 34px; height: 34px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.ai-iconbtn:hover { background: var(--ai-border); color: var(--ai-text); }
.ai-iconbtn:focus-visible { outline: 2px solid rgb(var(--c-primary-500, 99 102 241)); outline-offset: 2px; }

/* ------------------------------------------------------------------ Isi */

.ai-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
}

.ai-empty { padding: 8px 2px; }
.ai-empty__title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.ai-empty__text  { font-size: 12.5px; color: var(--ai-text-dim); line-height: 1.6; }

.ai-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ai-chip {
  border: 1px solid var(--ai-border);
  background: var(--ai-surface-2);
  color: var(--ai-text);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, transform .12s var(--ai-ease);
}
.ai-chip:hover { border-color: rgb(var(--c-primary-400, 129 140 248)); transform: translateY(-1px); }
.ai-chip:focus-visible { outline: 2px solid rgb(var(--c-primary-500, 99 102 241)); outline-offset: 2px; }

/* ------------------------------------------------------------------ Pesan */

.ai-msg { display: flex; flex-direction: column; gap: 8px; }
.ai-msg--user { align-items: flex-end; }

.ai-bubble {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: var(--ai-radius-sm);
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-bubble--user {
  background: rgb(var(--c-primary-600, 79 70 229));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-bubble--bot {
  background: var(--ai-surface-2);
  border: 1px solid var(--ai-border);
  border-bottom-left-radius: 4px;
  max-width: 100%;
}

/* Kursor ketik saat jawaban sedang dirangkai. */
.ai-caret {
  display: inline-block;
  width: 7px; height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: rgb(var(--c-primary-500, 99 102 241));
  animation: ai-blink 1s steps(2, start) infinite;
}
@keyframes ai-blink { to { visibility: hidden; } }

.ai-thinking { display: flex; gap: 5px; padding: 12px 13px; }
.ai-thinking span {
  width: 7px; height: 7px; border-radius: 999px;
  background: var(--ai-text-dim);
  animation: ai-bounce 1.1s infinite ease-in-out;
}
.ai-thinking span:nth-child(2) { animation-delay: .15s; }
.ai-thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------------------------------------------------------- Kartu jawaban */

.ai-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--ai-text-dim);
}
.ai-tag {
  border: 1px solid var(--ai-border);
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--ai-surface);
  white-space: nowrap;
}
.ai-tag--period { border-color: rgb(var(--c-primary-300, 165 180 252)); }
.ai-tag--scope  { border-style: dashed; }

.ai-numbers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  margin-top: 2px;
}
.ai-num {
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius-sm);
  background: var(--ai-surface);
  padding: 9px 11px;
}
.ai-num__v { font-size: 17px; font-weight: 700; line-height: 1.1; }
.ai-num__k { font-size: 10.5px; color: var(--ai-text-dim); margin-top: 3px; line-height: 1.35; }

.ai-sources { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-source {
  font-size: 10.5px;
  border: 1px solid var(--ai-border);
  border-radius: 8px;
  padding: 4px 8px;
  background: var(--ai-surface-2);
  color: var(--ai-text-dim);
}

.ai-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.ai-btn {
  border: 1px solid var(--ai-border);
  background: var(--ai-surface);
  color: var(--ai-text);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.ai-btn:hover { border-color: rgb(var(--c-primary-400, 129 140 248)); }
.ai-btn:focus-visible { outline: 2px solid rgb(var(--c-primary-500, 99 102 241)); outline-offset: 2px; }
.ai-btn--primary {
  background: rgb(var(--c-primary-600, 79 70 229));
  border-color: rgb(var(--c-primary-600, 79 70 229));
  color: #fff;
}
.ai-btn--primary:hover { background: rgb(var(--c-primary-700, 67 56 202)); }
.ai-btn--danger { color: #dc2626; border-color: #fecaca; }
.dark .ai-btn--danger { border-color: #7f1d1d; }
.ai-btn[disabled] { opacity: .5; cursor: not-allowed; }

.ai-note {
  font-size: 11.5px;
  line-height: 1.55;
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #92400e;
}
.dark .ai-note { background: #422006; border-color: #78350f; color: #fcd34d; }

.ai-note--info   { border-color: #bfdbfe; background: #eff6ff; color: #1e40af; }
.dark .ai-note--info { background: #172554; border-color: #1e3a8a; color: #93c5fd; }
.ai-note--danger { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.dark .ai-note--danger { background: #450a0a; border-color: #7f1d1d; color: #fca5a5; }

/* ---------------------------------------------------------------- Komposer */

.ai-composer {
  border-top: 1px solid var(--ai-border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--ai-surface-2);
  flex-shrink: 0;
}
.ai-composer__row { display: flex; gap: 8px; align-items: flex-end; }
.ai-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius-sm);
  background: var(--ai-surface);
  color: var(--ai-text);
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  font-family: inherit;
  max-height: 140px;
  min-height: 42px;
}
.ai-input:focus {
  outline: none;
  border-color: rgb(var(--c-primary-500, 99 102 241));
  box-shadow: 0 0 0 3px rgb(var(--c-primary-500, 99 102 241) / .18);
}
.ai-send {
  width: 42px; height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--ai-radius-sm);
  background: rgb(var(--c-primary-600, 79 70 229));
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .12s var(--ai-ease);
}
.ai-send:hover:not([disabled]) { background: rgb(var(--c-primary-700, 67 56 202)); }
.ai-send:active:not([disabled]) { transform: scale(.94); }
.ai-send[disabled] { opacity: .45; cursor: not-allowed; }

.ai-composer__hint {
  font-size: 10.5px;
  color: var(--ai-text-dim);
  margin-top: 6px;
  line-height: 1.45;
}

/* =========================================================== AI CENTER ==== */

.ai-center { display: flex; flex-direction: column; gap: 18px; }

.ai-center__tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--ai-border);
  padding-bottom: 2px;
}
.ai-tab {
  border: none;
  background: transparent;
  color: var(--ai-text-dim);
  font-size: 13px; font-weight: 600;
  padding: 9px 13px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -3px;
}
.ai-tab:hover { color: var(--ai-text); }
.ai-tab.is-active {
  color: rgb(var(--c-primary-600, 79 70 229));
  border-bottom-color: rgb(var(--c-primary-600, 79 70 229));
}
.ai-tab:focus-visible { outline: 2px solid rgb(var(--c-primary-500, 99 102 241)); outline-offset: -2px; }

.ai-panel[hidden] { display: none; }

.ai-card {
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius);
  background: var(--ai-surface);
  padding: 16px;
}
.ai-card__head {
  display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 12px;
}
.ai-card__title { font-weight: 700; font-size: 14px; }
.ai-card__sub { font-size: 11.5px; color: var(--ai-text-dim); margin-top: 3px; line-height: 1.5; }

.ai-grid { display: grid; gap: 12px; }
@media (min-width: 720px) {
  .ai-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ai-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ai-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.ai-stat { border: 1px solid var(--ai-border); border-radius: var(--ai-radius-sm); padding: 13px; background: var(--ai-surface-2); }
.ai-stat__v { font-size: 21px; font-weight: 700; line-height: 1.1; }
.ai-stat__k { font-size: 11px; color: var(--ai-text-dim); margin-top: 4px; }

.ai-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--ai-border);
}
.ai-status::before { content: ''; width: 7px; height: 7px; border-radius: 999px; background: currentColor; }
.ai-status--ok      { color: #16a34a; border-color: #bbf7d0; background: #f0fdf4; }
.ai-status--error   { color: #dc2626; border-color: #fecaca; background: #fef2f2; }
.ai-status--unknown { color: #64748b; }
.ai-status--off     { color: #94a3b8; }
.dark .ai-status--ok    { background: #052e16; border-color: #14532d; }
.dark .ai-status--error { background: #450a0a; border-color: #7f1d1d; }

.ai-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  letter-spacing: .05em;
  color: var(--ai-text-dim);
}

.ai-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.ai-field__label { font-size: 12px; font-weight: 600; }
.ai-field__help  { font-size: 11px; color: var(--ai-text-dim); line-height: 1.5; }
.ai-field input[type="text"],
.ai-field input[type="password"],
.ai-field input[type="number"],
.ai-field select {
  border: 1px solid var(--ai-border);
  border-radius: 10px;
  background: var(--ai-surface);
  color: var(--ai-text);
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
.ai-field input:focus, .ai-field select:focus {
  outline: none;
  border-color: rgb(var(--c-primary-500, 99 102 241));
  box-shadow: 0 0 0 3px rgb(var(--c-primary-500, 99 102 241) / .18);
}

.ai-switch { display: flex; align-items: center; gap: 9px; font-size: 12.5px; cursor: pointer; padding: 5px 0; }
.ai-switch input { width: 16px; height: 16px; accent-color: rgb(var(--c-primary-600, 79 70 229)); }

.ai-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ai-table th {
  text-align: left; font-weight: 600; color: var(--ai-text-dim);
  padding: 8px 10px; border-bottom: 1px solid var(--ai-border);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
}
.ai-table td { padding: 9px 10px; border-bottom: 1px solid var(--ai-border); vertical-align: top; }
.ai-table tr:last-child td { border-bottom: none; }
.ai-tablewrap { overflow-x: auto; }

/* Garis waktu audit */
.ai-timeline { list-style: none; margin: 0; padding: 0 0 0 20px; position: relative; }
.ai-timeline::before {
  content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px;
  width: 2px; background: var(--ai-border);
}
.ai-timeline li { position: relative; padding: 0 0 15px 4px; }
.ai-timeline li::before {
  content: ''; position: absolute; left: -19px; top: 5px;
  width: 9px; height: 9px; border-radius: 999px;
  background: var(--ai-surface); border: 2px solid var(--ai-border);
}
.ai-timeline li[data-sev="warning"]::before { border-color: #f59e0b; }
.ai-timeline li[data-sev="alert"]::before   { border-color: #dc2626; }
.ai-timeline__ev   { font-size: 12.5px; font-weight: 600; }
.ai-timeline__meta { font-size: 11px; color: var(--ai-text-dim); margin-top: 2px; line-height: 1.5; }

/* Grafik batang sederhana tanpa pustaka luar */
.ai-bars { display: flex; align-items: flex-end; gap: 4px; height: 92px; margin-top: 8px; }
.ai-bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.ai-bar__fill {
  background: rgb(var(--c-primary-500, 99 102 241));
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height .3s var(--ai-ease);
}
.ai-bar__fill--err { background: #ef4444; }
.ai-bar__lab { font-size: 9px; color: var(--ai-text-dim); text-align: center; margin-top: 4px; }

.ai-meter { height: 7px; border-radius: 999px; background: var(--ai-border); overflow: hidden; margin-top: 6px; }
.ai-meter__fill { height: 100%; background: rgb(var(--c-primary-500, 99 102 241)); border-radius: 999px; transition: width .3s var(--ai-ease); }
.ai-meter__fill--warn { background: #f59e0b; }
.ai-meter__fill--over { background: #dc2626; }

/* --------------------------------------------------------------- Modal */

.ai-modal {
  position: fixed; inset: 0; z-index: 90;
  display: none;
  align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, .45);
}
.ai-modal.is-open { display: flex; }
.ai-modal__box {
  width: min(460px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--ai-surface);
  color: var(--ai-text);
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius);
  box-shadow: var(--ai-shadow);
  padding: 20px;
}
.ai-modal__title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.ai-modal__sub { font-size: 12px; color: var(--ai-text-dim); margin-bottom: 14px; line-height: 1.55; }
.ai-modal__foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.ai-skel {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--ai-border) 25%, var(--ai-surface-2) 50%, var(--ai-border) 75%);
  background-size: 200% 100%;
  animation: ai-shimmer 1.3s infinite;
  height: 14px;
}
@keyframes ai-shimmer { to { background-position: -200% 0; } }

.ai-sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------- Gerak berkurang */

@media (prefers-reduced-motion: reduce) {
  .ai-fab, .ai-drawer, .ai-scrim, .ai-chip, .ai-send,
  .ai-bar__fill, .ai-meter__fill {
    transition: none !important;
  }
  .ai-caret, .ai-thinking span, .ai-skel {
    animation: none !important;
  }
  .ai-caret { visibility: visible; }
  .ai-skel  { background: var(--ai-border); }
}
/* Perbaikan tombol Tambah Koneksi pada website utama */
.ai-card > .ai-btn.ai-btn--primary {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: auto !important;
    min-height: 38px !important;
    margin-top: 4px !important;
    padding: 9px 16px !important;
    background: #2563eb !important;
    border: 1px solid #2563eb !important;
    color: #ffffff !important;
    position: relative !important;
    z-index: 2 !important;
}