/* components.css — komponen reusable (§6 prompt). Semua state: default, hover,
   focus, active, disabled, loading, error. Tanpa warna hardcode. */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow-1);
  min-width: 0;
}
.card-clickable { cursor: pointer; transition: transform var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease); }
.card-clickable:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.card-title { font-size: 16px; font-weight: 650; margin-bottom: var(--s-1); }
.card-sub { font-size: 12px; color: var(--text-muted); }

/* ---- StatCard ---- */
.stat-card { animation: fade-in 150ms var(--ease); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: var(--s-1); }
.stat-value { font-size: 26px; font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; }
.stat-value.sm { font-size: 20px; }
.stat-unit { font-size: 13px; color: var(--text-muted); font-weight: 400; margin-left: 2px; }
.stat-delta { font-size: 12px; font-family: var(--font-mono); }
.stat-delta.up { color: var(--ok); }
.stat-delta.down { color: var(--err); }
.stat-caption { font-size: 11px; color: var(--text-faint); margin-top: var(--s-1); }
.stat-card.flash .stat-value { animation: flash-bg 600ms var(--ease); border-radius: var(--r-sm); }

/* ---- StatusBadge ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; line-height: 1;
  padding: 5px 10px; border-radius: var(--r-full);
  background: var(--idle-soft); color: var(--idle); white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge.online, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.running { background: var(--ok-soft); color: var(--ok); }
.badge.running .dot { animation: pulse-dot 2s infinite; }
.badge.warning, .badge.warn, .badge.stale { background: var(--warn-soft); color: var(--warn); }
.badge.error, .badge.err, .badge.offline { background: var(--err-soft); color: var(--err); }
.badge.idle, .badge.disabled { background: var(--idle-soft); color: var(--idle); }
.badge.read-only, .badge.info { background: var(--info-soft); color: var(--info); }

/* ---- ActionButton ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 36px; padding: var(--s-2) var(--s-4);
  border-radius: var(--r-md); border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform 60ms var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-secondary { background: var(--surface-3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--err-soft); color: var(--err); }
.btn-danger:hover:not(:disabled) { background: var(--err); color: #fff; }
.btn .spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}
@media (max-width: 639px) { .btn { min-height: 44px; } }

/* ---- Skeleton ---- */
.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  color: transparent !important;
  min-height: 1em;
}

/* ---- Toast ---- */
.toast-wrap {
  position: fixed; right: var(--s-4); bottom: var(--s-4); z-index: 100;
  display: flex; flex-direction: column; gap: var(--s-2); max-width: min(360px, calc(100vw - 32px));
}
@media (max-width: 639px) {
  .toast-wrap { left: var(--s-4); right: var(--s-4); top: var(--s-4); bottom: auto; max-width: none; }
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); padding: var(--s-3) var(--s-4); font-size: 13px;
  box-shadow: var(--shadow-2); animation: fade-in 150ms var(--ease);
  border-left: 3px solid var(--info);
}
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast.err { border-left-color: var(--err); }

/* ---- Callout ---- */
.callout {
  border-radius: var(--r-md); padding: var(--s-3) var(--s-4); font-size: 13px;
  background: var(--info-soft); color: var(--text); border: 1px solid var(--border);
}
.callout.warn { background: var(--warn-soft); }
.callout.err { background: var(--err-soft); }

/* ---- Chips & Tabs ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--r-full); font-size: 12.5px; font-weight: 550;
  background: var(--surface-3); color: var(--text-muted); border: 1px solid transparent;
  cursor: pointer; transition: all var(--t-fast) var(--ease);
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--border-strong); }
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border); margin-bottom: var(--s-4); overflow-x: auto; }
.tab {
  padding: var(--s-2) var(--s-3); font-size: 13.5px; font-weight: 550; color: var(--text-muted);
  background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Progress / Gauge ---- */
.progress { height: 7px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.progress > div { height: 100%; border-radius: var(--r-full); background: var(--ok); transition: width var(--t-base) var(--ease); }
.progress > div.warn { background: var(--warn); }
.progress > div.err { background: var(--err); }
.gauge-row { display: flex; align-items: center; gap: var(--s-3); font-size: 13px; }
.gauge-row .gauge-label { width: 44px; color: var(--text-muted); flex-shrink: 0; }
.gauge-row .progress { flex: 1; }
.gauge-row .gauge-num { width: 52px; text-align: right; font-family: var(--font-mono); font-size: 12px; }

/* ---- LogViewer ---- */
.logbox {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.6;
  background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4); height: 320px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
@media (max-width: 639px) { .logbox { height: 50vh; } }
.logbox .t-dim { color: var(--text-faint); }
.logbox .lvl-ok { color: var(--ok); }
.logbox .lvl-warn { color: var(--warn); }
.logbox .lvl-err { color: var(--err); }
.logbox .lvl-info { color: var(--text-muted); }

/* ---- DataTable ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  position: sticky; top: 0; text-align: left; font-size: 12px; color: var(--text-muted);
  padding: var(--s-2) var(--s-3); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--font-mono); }
table.data .sticky-col { position: sticky; left: 0; background: var(--surface); }

/* ---- CopyField ---- */
.copy-field {
  display: flex; align-items: center; gap: var(--s-2);
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3); font-family: var(--font-mono); font-size: 12px;
  overflow: hidden;
}
.copy-field span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Empty / Error states ---- */
.empty-state, .error-state {
  text-align: center; padding: var(--s-8) var(--s-4); color: var(--text-muted);
}
.empty-state .empty-ic, .error-state .empty-ic { font-size: 28px; margin-bottom: var(--s-2); }
.empty-state h3, .error-state h3 { color: var(--text); margin-bottom: var(--s-1); }
.error-state { color: var(--err); }
.error-state h3 { color: var(--err); }

/* ---- Alert strip ---- */
.alert-strip {
  display: flex; align-items: center; gap: var(--s-3);
  background: var(--warn-soft); border-bottom: 1px solid var(--border);
  padding: var(--s-2) var(--s-4); font-size: 13px;
}
.alert-strip.err { background: var(--err-soft); }
.alert-strip a { font-weight: 650; }

/* ---- Tooltip (CSS-only, via data-tip) ---- */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; z-index: 50;
  bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--border-strong);
  color: var(--text); font-size: 12px; font-family: var(--font-ui); white-space: nowrap;
  padding: 5px 9px; border-radius: var(--r-sm); box-shadow: var(--shadow-2); pointer-events: none;
}

/* ---- Modal (ConfirmDialog) ---- */
.modal-scrim {
  display: none; position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,0.55); align-items: center; justify-content: center; padding: var(--s-4);
}
.modal-scrim.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2); max-width: 440px; width: 100%; padding: var(--s-6);
  animation: fade-in 150ms var(--ease);
}
.modal h3 { margin-bottom: var(--s-2); }
.modal p { color: var(--text-muted); font-size: 13.5px; margin: 0 0 var(--s-4); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s-2); }

/* ---- Command palette ---- */
.cmd-palette {
  display: none; position: fixed; inset: 0; z-index: 95;
  background: rgba(0,0,0,0.5); align-items: flex-start; justify-content: center; padding-top: 12vh;
}
.cmd-palette.open { display: flex; }
.cmd-box {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2); width: min(560px, calc(100vw - 32px)); overflow: hidden;
  animation: fade-in 150ms var(--ease);
}
.cmd-input {
  width: 100%; background: none; border: none; border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 15px; padding: var(--s-4); outline: none;
}
.cmd-list { max-height: 320px; overflow-y: auto; padding: var(--s-2); }
.cmd-item {
  display: flex; gap: var(--s-3); align-items: center; width: 100%;
  padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); background: none; border: none;
  cursor: pointer; text-align: left; font-size: 13.5px; color: var(--text-muted);
}
.cmd-item:hover, .cmd-item.sel { background: var(--surface-2); color: var(--text); }
