:root {
  --brand-1: #4f5bd5;
  --brand-2: #962fbf;
  --brand-grad: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  --ink: #1a1a2e;
  --ink-soft: #555;
  --muted: #8b8b99;
  --border: #e6e6ec;
  --bg: #f4f5fa;
  --card: #ffffff;
  --ok: #1f9d5c;
  --ok-bg: #e7f8ee;
  --danger: #d0342c;
  --danger-bg: #fdecec;
  --warn: #b4790a;
  --warn-bg: #fff6e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.04), 0 8px 24px rgba(20, 20, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

nav { background: var(--ink); color: white; padding: 12px 24px; display: flex; justify-content: space-between; }
nav a { color: #9bd; margin-left: 12px; }
main { max-width: 900px; margin: 24px auto; padding: 0 16px; }

/* --- Tabel & elemen dasar --- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  margin-bottom: 24px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

th, td { text-align: left; padding: 12px 16px; }

th {
  background: #fafafb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td { font-size: 14px; border-bottom: 1px solid var(--border); color: var(--ink-soft); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: #fafaff; }

input, select {
  padding: 9px 12px;
  margin: 4px 4px 4px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--brand-1);
  box-shadow: 0 0 0 3px rgba(79, 91, 213, 0.12);
}

button {
  padding: 9px 16px;
  margin: 4px 4px 4px 0;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: #eee;
  color: var(--ink-soft);
  transition: background 0.15s, transform 0.05s;
}

button:hover { background: #e2e2ea; }
button:active { transform: translateY(1px); }

/* --- Sidebar layout (dashboard) --- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: none;
  background: var(--ink);
  color: #ddd;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  font-weight: 700;
  color: white;
  font-size: 16px;
  letter-spacing: 0.02em;
}

.sidebar-brand .login-logo { width: 34px; height: 34px; font-size: 13px; margin: 0; border-radius: 10px; }

.sidebar-nav { display: flex; flex-direction: column; padding: 8px 12px; gap: 2px; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  background: none;
  border: none;
  color: #a6a6ba;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  width: 100%;
  transition: background 0.15s, color 0.15s;
}

.nav-item svg { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.nav-item:hover { background: rgba(255,255,255,0.07); color: white; }
.nav-item:active { transform: none; }
.nav-item.active { background: var(--brand-grad); color: white; box-shadow: 0 4px 14px rgba(79, 91, 213, 0.35); }
.nav-item.active svg { opacity: 1; }

.sidebar-footer { padding: 14px 12px; border-top: 1px solid rgba(255,255,255,0.08); }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; }

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-grad);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex: none;
}

.user-name { font-size: 13px; color: white; font-weight: 600; }
.user-role { font-size: 11px; color: #8888a0; text-transform: capitalize; }

.logout-link {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
  color: #e88;
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.logout-link:hover { background: rgba(255,255,255,0.06); }

.app-main { flex: 1; padding: 32px 40px; max-width: 1100px; }

.app-main h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.view-subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.app-main h3 { margin: 32px 0 14px; font-size: 15px; font-weight: 600; color: var(--ink); }
.app-main h4 { margin: 0; }

.panel-form {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  background: var(--card);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.panel-form button, .chat-input-form button, .login-box button {
  background: var(--brand-grad);
  color: white;
}
.panel-form button:hover, .chat-input-form button:hover { filter: brightness(1.06); }

.model-checklist {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfbfd;
  width: 100%;
  margin: 6px 0;
}

.checklist-item { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: normal; color: var(--ink-soft); }
.checklist-item input { margin: 0; }

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

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  background: var(--ink);
  color: white;
  text-decoration: none;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  transition: transform 0.1s, background 0.15s;
}

.download-btn svg { width: 16px; height: 16px; }
.download-btn:hover { background: #29294a; }
.download-btn:active { transform: translateY(1px); }

code { background: #eef0f7; padding: 2px 7px; border-radius: 5px; font-size: 13px; color: #3a3a55; }

.code-block {
  background: var(--ink);
  color: #d8d8e8;
  padding: 16px 18px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  box-shadow: var(--shadow);
}

.tab-bar { display: flex; gap: 6px; margin-bottom: 18px; }

.tab-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  box-shadow: none;
}

.tab-btn.active { background: var(--ink); color: white; border-color: var(--ink); }
.tab-btn:hover:not(.active) { background: #f0f0f5; }

.row-error td { background: var(--danger-bg); }
.row-slow td { background: var(--warn-bg); }

.monitor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }

.monitor-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border-top: 3px solid transparent;
  border-image: var(--brand-grad) 1;
}

.monitor-card h4 { margin: 0 0 10px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.monitor-value { font-size: 26px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.monitor-card .hint { margin-top: 4px; }
.status-ok { color: var(--ok); }
.status-down { color: var(--danger); }

.chat-window {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-height: 320px;
  max-height: 440px;
  overflow-y: auto;
  margin: 4px 0 12px;
  box-shadow: var(--shadow);
}

.chat-msg { padding: 10px 14px; font-size: 14px; line-height: 1.55; border-radius: 10px; margin-bottom: 8px; max-width: 80%; }
.chat-msg-user { background: var(--brand-grad); color: white; margin-left: auto; }
.chat-msg-assistant { background: #f1f1f6; color: var(--ink); }
.chat-msg strong { display: none; }

.chat-msg-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  margin-bottom: 6px;
  object-fit: cover;
}

.chat-text { white-space: pre-wrap; word-break: break-word; }

.chat-msg:has(.chat-code-block) { max-width: 92%; }

.chat-code-block {
  position: relative;
  background: var(--ink);
  color: #d8d8e8;
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.6;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  margin: 8px 0;
  white-space: pre;
}

.chat-code-lang {
  display: block;
  font-family: system-ui, sans-serif;
  font-size: 11px;
  color: #9a9ab5;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.chat-typing { display: flex; align-items: center; gap: 4px; padding: 14px; width: fit-content; }

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b0b0c0;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.chat-input-form { display: flex; gap: 8px; }
.chat-input-form input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 0;
  padding: 12px 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.chat-input-form button { border-radius: 10px; padding: 0 24px; }

.chat-attach-btn {
  flex: none;
  width: 44px;
  padding: 0;
  background: #f0f0f5;
  color: var(--ink-soft);
  border-radius: 10px;
}
.chat-attach-btn svg { width: 18px; height: 18px; }
.chat-attach-btn:hover { background: #e4e4ec; }

.chat-image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.chat-preview-thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; flex: none; }

.chat-preview-remove {
  margin-left: auto;
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  background: #f0f0f5;
  color: var(--muted);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-preview-remove svg { width: 13px; height: 13px; }
.chat-preview-remove:hover { background: var(--danger-bg); color: var(--danger); }

.chat-vision-hint { margin: 6px 2px 0; }

.chat-file-icon { width: 20px; height: 20px; flex: none; color: var(--brand-1); }

.chat-doc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.15);
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  margin-bottom: 6px;
}
.chat-doc-chip svg { width: 14px; height: 14px; }
.chat-msg-assistant .chat-doc-chip { background: rgba(79, 91, 213, 0.1); color: var(--brand-1); }

/* --- Chat layout: sidebar riwayat + jendela chat --- */
.chat-layout { display: flex; gap: 20px; align-items: flex-start; }

.chat-history-panel {
  width: 240px;
  flex: none;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--brand-grad);
  color: white;
  padding: 10px;
  border-radius: 9px;
  font-size: 13.5px;
  margin-bottom: 12px;
}
.new-chat-btn svg { width: 16px; height: 16px; }
.new-chat-btn:hover { filter: brightness(1.05); }

.chat-session-list { display: flex; flex-direction: column; gap: 2px; max-height: 480px; overflow-y: auto; }

.chat-session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-soft);
  transition: background 0.12s;
}
.chat-session-item:hover { background: #f4f4f9; }
.chat-session-item.active { background: #eef0fb; color: var(--brand-1); font-weight: 600; }

.chat-session-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-session-delete {
  flex: none;
  background: none;
  padding: 3px;
  margin: 0;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.12s;
}
.chat-session-item:hover .chat-session-delete { opacity: 1; }
.chat-session-delete:hover { background: var(--danger-bg); color: var(--danger); }
.chat-session-delete svg { width: 13px; height: 13px; display: block; }

.chat-main { flex: 1; min-width: 0; }

/* --- Status badges (aktif/nonaktif, status code) --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: #f0f0f5; color: var(--muted); }
.badge-error { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

/* --- Tombol aksi kecil di dalam tabel --- */
td button {
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 500;
  background: #f0f0f5;
  color: var(--ink-soft);
}
td button:hover { background: #e4e4ec; }
td button.btn-danger { background: var(--danger-bg); color: var(--danger); }
td button.btn-danger:hover { background: #fbdcdb; }

/* --- Aksi tabel sebagai ikon (API Keys, Manajemen Akun) --- */
.action-cell { display: flex; gap: 4px; align-items: center; white-space: nowrap; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  flex: none;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: #f0f0f5; color: var(--ink); }
.icon-btn-danger:hover { background: var(--danger-bg); color: var(--danger); }

/* --- Login page --- */
body:has(.login-box) { background: linear-gradient(160deg, #1a1a2e 0%, #16213e 100%); min-height: 100vh; }

.login-box {
  max-width: 380px;
  margin: 100px auto;
  background: white;
  padding: 40px 36px;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.login-brand { text-align: center; margin-bottom: 30px; }

.login-logo {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: var(--brand-grad);
  color: white;
  font-weight: 700;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
  box-shadow: 0 8px 20px rgba(79, 91, 213, 0.35);
}

.login-brand h1 { margin: 0; font-size: 23px; color: var(--ink); letter-spacing: -0.01em; }
.login-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 14px; }

.input-field {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  margin-bottom: 12px;
  background: #fafafc;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.input-field:focus-within { border-color: var(--brand-1); background: white; box-shadow: 0 0 0 3px rgba(79, 91, 213, 0.12); }

.input-field svg { flex: none; width: 18px; height: 18px; color: var(--muted); }

.input-field input {
  border: none;
  background: transparent;
  padding: 12px 0;
  margin: 0;
  width: 100%;
  outline: none;
  box-shadow: none;
}

.login-box button {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 8px 20px rgba(79, 91, 213, 0.3);
}

.login-box button:hover { filter: brightness(1.05); }

#error { color: var(--danger); font-size: 13px; text-align: center; min-height: 1.2em; margin: 14px 0 0; }

/* --- Modal: API key baru --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 40, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: modal-fade-in 0.15s ease-out;
}

.modal-overlay[hidden] { display: none; }

@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modal-box {
  background: var(--card);
  border-radius: 18px;
  padding: 32px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: modal-pop-in 0.18s ease-out;
}

.modal-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--ok-bg);
  color: var(--ok);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-icon svg { width: 26px; height: 26px; }

.modal-box h3 { margin: 0 0 8px; font-size: 19px; color: var(--ink); letter-spacing: -0.01em; }
.modal-subtitle { margin: 0 0 22px; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.modal-subtitle strong { color: var(--danger); }

.modal-key-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ink);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 8px;
}

.modal-key-box code {
  background: none;
  color: #d8ffe8;
  font-size: 13px;
  word-break: break-all;
  text-align: left;
  flex: 1;
  padding: 0;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 12.5px;
  padding: 8px 12px;
}
.copy-btn:hover { background: rgba(255,255,255,0.2); }
.copy-btn svg { width: 14px; height: 14px; }

.modal-copy-feedback { min-height: 1.2em; font-size: 12.5px; color: var(--ok); margin: 4px 0 18px; }

.modal-meta {
  display: flex;
  gap: 24px;
  justify-content: center;
  padding: 16px 0;
  margin-bottom: 22px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.modal-meta .hint { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }

.modal-close-btn {
  width: 100%;
  background: var(--brand-grad);
  color: white;
  padding: 12px;
  font-size: 14px;
  border-radius: 10px;
}
.modal-close-btn:hover { filter: brightness(1.05); }

/* --- Modal form (edit key/user) --- */
.modal-box-form { text-align: left; max-width: 420px; }
.modal-box-form h3 { text-align: center; }
.modal-box-form .modal-subtitle { text-align: center; }

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 14px 0 6px;
}
.form-label:first-of-type { margin-top: 4px; }

.modal-box-form input,
.modal-box-form select {
  width: 100%;
  margin: 0;
}

.modal-box-form .model-checklist {
  display: block;
  margin: 0;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px 14px;
}

.modal-box-form .checklist-item {
  padding: 9px 4px;
  border-bottom: 1px solid var(--border);
  border-radius: 6px;
  transition: background 0.12s;
}
.modal-box-form .checklist-item:last-child { border-bottom: none; }
.modal-box-form .checklist-item:hover { background: #f4f4f9; }
.modal-box-form .checklist-item input { flex: none; }

.modal-form-actions { display: flex; gap: 10px; margin-top: 24px; }
.modal-form-actions button { flex: 1; margin: 0; border-radius: 10px; padding: 11px; font-size: 14px; }

.modal-cancel-btn { background: #f0f0f5; color: var(--ink-soft); }
.modal-cancel-btn:hover { background: #e4e4ec; }

.modal-danger-btn { background: var(--danger); color: white; }
.modal-danger-btn:hover { filter: brightness(1.08); }

.modal-icon-danger { background: var(--danger-bg); color: var(--danger); }

/* --- Sidebar mobile toggle (hidden on desktop) --- */
.sidebar-toggle {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: 12px;
  background: var(--ink);
  color: white;
  border-radius: 8px;
  padding: 0;
}
.sidebar-toggle svg { width: 20px; height: 20px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 40, 0.5);
  z-index: 49;
}
.sidebar-overlay[hidden] { display: none; }

/* --- Charts (bar & pie, native SVG-free / CSS only) --- */
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.chart-card h4 { margin: 0 0 16px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

.chart-body { min-height: 140px; display: flex; align-items: center; }

.bar-chart { display: flex; flex-direction: column; gap: 14px; width: 100%; }

.bar-chart-row { display: grid; grid-template-columns: 90px 1fr 44px; align-items: center; gap: 10px; }

.bar-chart-label { font-size: 13px; color: var(--ink-soft); font-weight: 500; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar-chart-track { height: 10px; background: #f0f0f5; border-radius: 999px; overflow: hidden; }

.bar-chart-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease-out; }

.bar-chart-value { font-size: 13px; font-weight: 600; color: var(--ink); text-align: right; }

.pie-chart-wrap { display: flex; align-items: center; gap: 20px; width: 100%; }

.pie-chart {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  flex: none;
}

.pie-legend { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.pie-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pie-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ============================================================
   Responsive breakpoints
   ============================================================ */

/* Tablet: sidebar tetap, tapi lebih ramping; main padding dikurangi */
@media (max-width: 1024px) {
  .sidebar { width: 210px; }
  .app-main { padding: 24px; }
  .monitor-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .chart-row { grid-template-columns: 1fr; }
}

/* Mobile: sidebar jadi off-canvas, dibuka lewat hamburger */
@media (max-width: 860px) {
  .app-shell { display: block; }

  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 260px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform 0.2s ease-out;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay:not([hidden]) { display: block; }

  .app-main { padding: 16px; max-width: 100%; }
  .app-main h2 { font-size: 19px; }

  /* Tabel: biarkan scroll horizontal di dalam wrapper, jangan pecahkan layout */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  thead, tbody, tr { display: table; width: 100%; table-layout: fixed; }

  .panel-form { flex-direction: column; align-items: stretch; }
  .panel-form input, .panel-form select { width: 100%; margin: 4px 0; }
  .panel-form button { width: 100%; margin: 8px 0 0; }

  .model-checklist { max-height: none; }

  .monitor-grid { grid-template-columns: 1fr 1fr; gap: 12px; }

  .chat-window { min-height: 260px; max-height: 55vh; }
  .chat-msg { max-width: 90%; }

  .chat-layout { flex-direction: column; }
  .chat-history-panel { width: 100%; }
  .chat-session-list { max-height: 160px; }

  .tab-bar { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .tab-btn { flex: none; }

  .modal-box, .modal-box-form { max-width: 100%; padding: 24px 20px; }
  .modal-meta { flex-direction: column; gap: 12px; text-align: left; }

  .download-btn { width: 100%; justify-content: center; }
}

/* Small phones */
@media (max-width: 480px) {
  .app-main { padding: 12px; }
  .modal-form-actions { flex-direction: column; }
  .monitor-grid { grid-template-columns: 1fr; }
  .sidebar-brand span { font-size: 15px; }
}

@media (max-width: 480px), (max-height: 640px) {
  .login-box { margin: 32px auto; padding: 28px 24px; }
}
