/* ---------- buttons ---------- */
.btn {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 26px; padding: 0 9px; font-size: var(--fs-sm); }
.btn.block { width: 100%; }
.btn.loading { color: transparent !important; position: relative; }
.btn.loading::after {
  content: "";
  position: absolute;
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 99px;
  animation: spin 0.7s linear infinite;
  color: var(--text);
}
.btn.primary.loading::after { color: var(--accent-ink); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- fields ---------- */
.field { display: grid; gap: var(--s1); }
.field > label { font-size: var(--fs-sm); color: var(--text-dim); }
.field .help { font-size: var(--fs-xs); color: var(--text-mute); }
.field .err { font-size: var(--fs-xs); color: var(--danger); }

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  height: 34px;
  padding: 0 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  outline: none;
  width: 100%;
  transition: border-color var(--transition);
}
textarea { height: auto; padding: 8px 10px; font-family: var(--mono); font-size: var(--fs-sm); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text-mute); }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }

.segmented { display: flex; gap: 2px; padding: 2px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-sm); }
.segmented button {
  flex: 1;
  height: 28px;
  border: 0;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: var(--fs-sm);
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------- badges & chips ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: 99px;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 99px; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.mute { background: var(--surface-2); color: var(--text-mute); }
.badge.plain::before { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 8px;
  font-size: var(--fs-sm);
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
}
.chip button { background: none; border: 0; color: inherit; cursor: pointer; opacity: 0.7; padding: 0; }
.chip button:hover { opacity: 1; }

/* ---------- cards & tables ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
.card > header {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line-soft);
}
.card > .body { padding: var(--s4); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mute);
  font-weight: 600;
  padding: 8px var(--s4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 9px var(--s4); border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.act, th.act { text-align: right; width: 1%; white-space: nowrap; }

/* ---------- modal & drawer ---------- */
.modal-wrap, .drawer-wrap {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.6);
  backdrop-filter: blur(4px);
  z-index: 50;
  animation: fade var(--transition);
}
.modal-wrap { display: grid; place-items: center; padding: var(--s4); }
@keyframes fade { from { opacity: 0; } }

.modal {
  width: 460px;
  max-width: 100%;
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.modal .strip { height: 3px; background: var(--danger); }
.modal .body { padding: var(--s5); display: grid; gap: var(--s3); }
.modal h2 { font-size: 15px; }
.modal .foot { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s2); }

.drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 100%;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow: auto;
  animation: slide var(--transition);
}
@keyframes slide { from { transform: translateX(16px); opacity: 0; } }
.drawer > header {
  position: sticky;
  top: 0;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s4);
  border-bottom: 1px solid var(--line);
  z-index: 1;
}
.drawer > .body { padding: var(--s4); display: grid; gap: var(--s4); }

.warnbox {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: var(--fs-sm);
}
.dangerbox { background: var(--danger-soft); color: var(--danger); border-radius: var(--r-sm);
  padding: 10px 12px; font-size: var(--fs-sm); }

/* ---------- code, toast, misc ---------- */
.code {
  font: var(--fs-sm) / 1.65 var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--s3);
  white-space: pre;
  overflow: auto;
  color: var(--text-dim);
  max-height: 320px;
}

#toasts {
  position: fixed;
  right: var(--s5);
  bottom: var(--s5);
  display: grid;
  gap: var(--s2);
  z-index: 60;
  max-width: 360px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ok);
  border-radius: var(--r-md);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  animation: slide var(--transition);
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast .t { font-weight: 600; margin-bottom: 2px; }
.toast .d { color: var(--text-dim); font-size: var(--fs-sm); }
.toast .x { float: right; background: none; border: 0; color: var(--text-mute); cursor: pointer; }

.empty {
  display: grid;
  gap: var(--s3);
  justify-items: center;
  text-align: center;
  padding: var(--s6) var(--s4);
  color: var(--text-dim);
}
.empty .icon { font-size: 28px; opacity: 0.6; }

.skeleton {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.meter { display: flex; align-items: center; gap: var(--s3); }
.meter text { fill: var(--text); }
