/* ===== KARSA AI — panel vibecoding ===== */

.sidebar-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--border);
}
.side-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.side-tab:hover { background: var(--bg-hover); color: var(--text); }
.side-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: var(--bg-3);
}

.side-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Sidebar melebar saat tab AI aktif */
.sidebar.ai-active { width: 340px; }

.ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 12px 6px;
}
.ai-plan-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg-3);
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.ai-plan-badge.warn {
  background: rgba(251, 191, 36, .15);
  color: #fbbf24;
}
.ai-plan-badge.pro {
  background: linear-gradient(135deg, rgba(124, 92, 255, .3), rgba(34, 211, 238, .2));
  color: #c4b5fd;
}
.pro-benefits {
  margin: 12px 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
}
.pro-dialog .pro-checkout-btn {
  width: 100%;
  margin-top: 8px;
  margin-bottom: 4px;
}
.pro-dialog .field { margin-top: 14px; }
.about-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}
.about-stat {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  text-align: center;
}
.about-stat strong { display: block; font-size: 18px; margin-bottom: 4px; }
.about-stat span { font-size: 11px; color: var(--muted); }

/* --- Baris mode AI + auto-terapkan --- */
.ai-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 10px 8px;
  border-bottom: 1px solid var(--border);
}
.ai-mode-toggle {
  display: flex;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.ai-mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  transition: background var(--transition), color var(--transition);
}
.ai-mode-btn:hover { color: var(--text); }
.ai-mode-btn.active {
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 2px 8px rgba(124, 92, 255, .35);
}
.ai-auto-apply {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.ai-auto-apply input { accent-color: var(--accent); cursor: pointer; }

/* Indikator sibuk di tab AI */
.side-tab.busy::after {
  content: '●';
  margin-left: 5px;
  font-size: 9px;
  color: var(--accent-2);
  animation: aiPulse 1s ease-in-out infinite;
}

/* Meta respons (durasi + model) */
.ai-meta {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed var(--border);
  font-size: 10.5px;
  color: var(--muted);
  font-family: var(--font-code);
}

/* --- Lampiran chat --- */
.ai-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 4px;
}
.ai-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 4px 7px;
  max-width: 100%;
}
.ai-attach-chip img {
  width: 30px; height: 30px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.ai-attach-icon { font-size: 15px; }
.ai-attach-name {
  font-size: 11px;
  font-family: var(--font-code);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-attach-remove {
  width: 17px; height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-size: 10px;
  color: var(--muted);
}
.ai-attach-remove:hover { background: var(--danger); color: #fff; }

/* Thumbnail gambar di gelembung pesan user */
.ai-user-thumb {
  display: block;
  max-width: 150px;
  max-height: 110px;
  border-radius: 8px;
  margin-top: 8px;
  border: 1px solid rgba(255, 255, 255, .35);
}

/* Pratinjau hasil screenshot di modal */
.shot-preview-img {
  display: block;
  max-width: 100%;
  max-height: 55vh;
  margin: 0 auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* Tombol coba lagi pada error */
.ai-retry-btn {
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  transition: filter var(--transition);
}
.ai-retry-btn:hover { filter: brightness(1.1); }

.ai-chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-msg {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  max-width: 100%;
  word-break: break-word;
}
.ai-msg-user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  max-width: 88%;
  white-space: pre-wrap;
}
.ai-msg-assistant {
  background: var(--bg-3);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.ai-msg-error {
  background: rgba(244, 63, 94, .12);
  border: 1px solid var(--danger);
  color: var(--danger);
  align-self: stretch;
  font-size: 12.5px;
}

.ai-msg-assistant pre {
  background: var(--console-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: var(--font-code);
  font-size: 11.5px;
  line-height: 1.5;
  max-height: 220px;
  overflow-y: auto;
}
.ai-msg-assistant code {
  font-family: var(--font-code);
  font-size: 12px;
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 4px;
}
.ai-msg-assistant pre code { background: none; padding: 0; }
.ai-msg-assistant p { margin: 6px 0; }
.ai-msg-assistant p:first-child { margin-top: 0; }
.ai-msg-assistant p:last-child { margin-bottom: 0; }

.ai-file-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 -4px;
  font-family: var(--font-code);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-2);
}

/* --- Kartu kode (pengganti wall of text) --- */
.ai-code-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 8px 0;
  overflow: hidden;
  background: var(--console-bg);
  transition: border-color var(--transition);
}
.ai-code-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 11px;
  font-family: var(--font-code);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.ai-code-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-code-meta {
  flex: 1;
  text-align: right;
  color: var(--muted);
  font-weight: 400;
  font-size: 10.5px;
}
.ai-code-caret {
  color: var(--muted);
  font-size: 10px;
  transition: transform var(--transition);
}
.ai-code-card.open .ai-code-caret { transform: rotate(180deg); }
.ai-code-card.open { border-color: var(--accent); }
.ai-msg-assistant pre.ai-code-body {
  margin: 0;
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  max-height: 260px;
}

/* Kartu yang sedang ditulis AI */
.ai-code-card.writing {
  border-color: var(--accent-2);
  animation: aiGlow 1.6s ease-in-out infinite;
}
.ai-code-card.writing .ai-code-head { color: var(--accent-2); cursor: default; }
.ai-spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent-2);
  animation: aiSpin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }
@keyframes aiGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(34, 211, 238, 0); }
  50% { box-shadow: 0 0 12px rgba(34, 211, 238, .25); }
}

.ai-thinking {
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ai-thinking::before {
  content: '💭';
  animation: aiPulse 1.2s ease-in-out infinite;
}
@keyframes aiPulse { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

.ai-apply-box {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-file-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px 10px;
  font-family: var(--font-code);
  font-size: 11px;
}
.ai-file-chip .chip-new { color: var(--ok); font-weight: 700; }
.ai-file-chip .chip-edit { color: var(--warn); font-weight: 700; }
.btn-apply {
  background: var(--gradient);
  color: #fff;
  font-weight: 700;
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 8px;
  transition: transform var(--transition), box-shadow var(--transition);
}
.btn-apply:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(124, 92, 255, .4); }
.btn-apply:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; }

/* Sapaan & contoh prompt */
.ai-welcome { text-align: center; padding: 18px 8px 6px; color: var(--muted); }
.ai-welcome .ai-welcome-icon {
  width: 44px; height: 44px;
  margin: 0 auto 10px;
  border-radius: 13px;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
}
.ai-welcome h3 { color: var(--text); font-size: 14px; margin-bottom: 4px; }
.ai-welcome p { font-size: 12px; margin-bottom: 12px; }
.ai-examples { display: flex; flex-direction: column; gap: 6px; }
.ai-example {
  text-align: left;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 12px;
  color: var(--text);
  transition: border-color var(--transition), background var(--transition);
}
.ai-example:hover { border-color: var(--accent); background: var(--bg-hover); }

/* Kotak input */
.ai-input-box {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#ai-input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: var(--font-ui);
  resize: vertical;
  min-height: 56px;
  max-height: 180px;
  outline: none;
  transition: border-color var(--transition);
}
#ai-input:focus { border-color: var(--accent); }
.ai-input-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.ai-status { flex: 1; font-size: 11.5px; color: var(--muted); }
.btn-sm { padding: 6px 13px; font-size: 12.5px; }
