/* OpenSquilla Web UI — Component styles */

/* Buttons — single .btn primitive with BEM modifiers per the OpenSquilla
   design system. Square corners (radius-md), no pill-shaped variants. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  line-height: 1.4;
  min-height: 40px;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-focus); }
.btn:active { background: var(--bg-hover); transform: translateY(0.5px); }
.btn:disabled,
.btn[disabled] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn:focus-visible,
.nav-item:focus-visible,
.chat-pill:focus-visible,
.chat-pill-seg:focus-visible,
.tab-btn:focus-visible,
.log-level-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.btn svg { width: 14px; height: 14px; }

.btn--sm { min-height: 40px; padding: 4px var(--sp-2); font-size: var(--fs-xs); }
.btn--lg { padding: 9px var(--sp-4); font-size: var(--fs-md); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--bg-hover); }
.btn--icon { padding: var(--sp-1); min-width: 40px; min-height: 40px; }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-foreground);
  font-weight: 600;
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--primary:active { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn--warn {
  background: var(--warn);
  border-color: var(--warn);
  color: #1a1300;
  font-weight: 600;
}
.btn--warn:hover { opacity: 0.9; }
.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 600;
}
.btn--danger:hover { opacity: 0.9; }

/* Button group — segmented control */
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-top-left-radius: var(--radius-md); border-bottom-left-radius: var(--radius-md); }
.btn-group .btn:last-child { border-top-right-radius: var(--radius-md); border-bottom-right-radius: var(--radius-md); }
.btn-group .btn:not(:first-child) { margin-left: -1px; }
.btn-group .btn.btn-primary { z-index: 1; }

/* Mobile action strip — shared header action contract for dense operator views. */
@media (max-width: 760px) {
  .mobile-action-strip {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .mobile-action-strip.mobile-action-strip { flex-wrap: nowrap; }
  .mobile-action-strip::-webkit-scrollbar { display: none; }
  .mobile-action-strip__item,
  .mobile-action-strip__button {
    flex: 0 0 auto;
  }
  .mobile-action-strip__button {
    width: var(--mobile-action-button-size, 40px);
    padding: 0;
    justify-content: center;
  }
  .mobile-action-strip__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
}

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Data table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.data-table th, .data-table td {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.data-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  user-select: none;
}
.data-table th:hover { color: var(--text); }
.table-sort-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.table-sort-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.data-table tbody tr:nth-child(even) td { background: rgba(255,255,255,0.015); }
[data-theme="light"] .data-table tbody tr:nth-child(even) td { background: rgba(0,0,0,0.02); }
.data-table tbody tr:hover td { background: var(--bg-hover); }
.data-table tbody td:first-child { font-weight: 500; }
.data-table .sort-arrow { opacity: 0.5; margin-left: var(--sp-1); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Chip / Badge */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--text-muted);
}
.chip.mono { font-family: var(--font-mono); }
.chip-ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip-warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip-danger { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.chip-info { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.chip-accent { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

/* Lifecycle aliases — semantic names from the OpenSquilla design system */
.chip-running { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip-queued { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip-failed { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.chip-cached { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }

/* Status dot — composes inside chips/pills via currentColor or as a standalone
   indicator. .ok/.warn carry a static 2px ring; .err/.off are bare. */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.ok { background: var(--ok); box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 2px color-mix(in srgb, var(--warn) 22%, transparent); }
.dot.err { background: var(--danger); }
.dot.off { background: var(--text-dim); }

/* Connection pill — uppercase mono-style state indicator with leading dot. */
.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  white-space: nowrap;
}
.conn-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 22%, transparent);
}
.conn-pill.ok {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 35%, var(--border));
  background: color-mix(in srgb, var(--ok) 10%, var(--bg-elevated));
}
/* Heartbeat halo on connected — barely there, just enough to read "alive".  */
.conn-pill.ok::before {
  animation: conn-pill-heartbeat 2.4s ease-in-out infinite;
}
@keyframes conn-pill-heartbeat {
  0%, 100% { box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 22%, transparent); }
  50%      { box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 6%, transparent); }
}
.conn-pill.warn {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--border));
  background: color-mix(in srgb, var(--warn) 10%, var(--bg-elevated));
}
/* Reconnecting (warn) pulses faster — signals "actively trying". */
.conn-pill.warn::before {
  animation: conn-pill-reconnect 0.9s ease-in-out infinite;
}
@keyframes conn-pill-reconnect {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(1.4); opacity: 0.55; }
}
.conn-pill.err {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  background: color-mix(in srgb, var(--danger) 10%, var(--bg-elevated));
}
@media (prefers-reduced-motion: reduce) {
  .conn-pill::before { animation: none !important; }
}

/* Connected state: demote pill to a quiet dot when healthy */
.conn-pill.ok.compact {
  padding: 3px;
  width: 12px;
  height: 12px;
  font-size: 0;
  gap: 0;
  border-radius: 50%;
  overflow: hidden;
}
.conn-pill.ok.compact::before {
  margin: 0;
  animation: conn-pill-heartbeat 2.4s ease-in-out infinite;
}

/* Tier badge — compact monospaced c0/c1/c2/c3 indicator for router decisions. */
.tier {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
}
.tier.c0 { background: color-mix(in srgb, var(--text-dim) 18%, transparent); color: var(--text-muted); border-color: var(--border); }
.tier.c2 { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, var(--border)); }
.tier.c3 { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, var(--border)); }

/* Spinner — generic 18px loading indicator. */
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-focus);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-3);
}
.field label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field input, .field textarea, .field select {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  font-family: var(--font-sans);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
}
.field-inline { flex-direction: row; align-items: center; gap: var(--sp-3); }

/* Stat tiles — design system spec. .stat-row is the grid container,
   .stat is each tile. Only one .stat--hero is allowed per row. */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.stat {
  position: relative;
  overflow: hidden;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-3) var(--sp-4) var(--sp-4) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 96px;
}
.stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--border);
}
.stat--hero::before { background: var(--accent); }
.stat--hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 0% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 55%);
  pointer-events: none;
}
.stat-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
  color: var(--text);
}
.stat-value.mono { font-family: var(--font-mono); font-size: 1.125rem; line-height: 1.3; }
.stat-hint { font-size: var(--fs-xs); color: var(--text-muted); }
.stat-hint .delta-up { color: var(--ok); }
.stat-hint .delta-dn { color: var(--danger); }

/* Skeleton loading */
.skel {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-elevated) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes skel-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modal-backdrop-in 180ms ease-out;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--sp-5) var(--sp-6) var(--sp-4);
  min-width: 360px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,0.6), 0 8px 32px var(--shadow);
  animation: modal-in 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
  position: relative;
}
.modal-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: 0;
  margin-bottom: var(--sp-3);
  padding-top: 4px;
}
.modal-body {
  margin-bottom: var(--sp-4);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.modal-body p { margin: 0 0 8px; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

@keyframes modal-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.approval-modal {
  width: min(560px, 92vw);
}
.approval-modal-tool {
  font-weight: 700;
  margin-bottom: var(--sp-1);
}
.approval-modal-meta {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  margin-bottom: var(--sp-3);
}
.approval-modal-command {
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: var(--sp-3);
  border-color: color-mix(in srgb, var(--warn) 35%, var(--border));
}
.approval-modal-detail {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Toast notifications */
.toast-stack {
  position: fixed;
  top: calc(var(--sp-4) + 48px); /* below the topbar */
  right: var(--sp-4);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 10px 16px 10px 14px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  box-shadow:
    0 12px 32px -10px rgba(0,0,0,0.45),
    0 4px 12px var(--shadow);
  animation: toast-in 220ms cubic-bezier(0.2, 0.7, 0.2, 1);
  max-width: 380px;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0;
  position: relative;
  overflow: hidden;
}
.toast::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}
.toast.ok::before {
  background: var(--ok);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ok) 30%, transparent);
}
.toast.warn::before {
  background: var(--warn);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--warn) 30%, transparent);
}
.toast.err::before {
  background: var(--danger);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 30%, transparent);
}
.toast.info::before {
  background: var(--info);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--info) 30%, transparent);
}
.toast.ok { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.toast.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.toast.err { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.toast.info { border-color: color-mix(in srgb, var(--info) 40%, var(--border)); }

@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
/* Keep the legacy slideIn alias for any third-party hookup */
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Markdown tables */
.content table,
.message-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.75em 0;
  font-size: var(--fs-sm);
}
.content table th,
.content table td,
.message-body table th,
.message-body table td {
  border: 1px solid var(--border);
  padding: 0.5em 0.75em;
  text-align: left;
}
.content table th,
.message-body table th {
  background: var(--bg-surface);
  font-weight: 600;
}
.content table tr:nth-child(even),
.message-body table tr:nth-child(even) {
  background: rgba(255,255,255,0.02);
}
.content table tr:hover,
.message-body table tr:hover {
  background: var(--bg-hover);
}

/* Code blocks */
.code-block {
  position: relative;
  margin: 0.75em 0;
}
.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-1) var(--sp-3);
  background: var(--bg-hover);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-hover));
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-size: var(--fs-xs);
}
.code-lang { color: var(--text-muted); }
.code-block pre {
  margin: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.inline-code {
  background: var(--bg-hover);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}
.math-raw {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-hover));
  color: color-mix(in srgb, var(--accent) 80%, var(--text));
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  font-size: 0.92em;
  white-space: pre-wrap;
  cursor: help;
}

/* Card grid */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--sp-4); }

/* Tabs */
.tab-bar { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); }
.tab-btn { padding: var(--sp-2) var(--sp-4); font-size: var(--fs-sm); font-weight: 400; color: var(--text-muted); background: transparent; border: none; border-bottom: 2px solid transparent; cursor: pointer; transition: color var(--transition), border-color var(--transition); }
.tab-btn:hover { color: var(--text); }
.tab-btn.is-active { color: var(--text); font-weight: 500; border-bottom-color: var(--accent); }

/* Form group */
.form-group { display: flex; flex-direction: column; gap: var(--sp-1); margin-bottom: var(--sp-4); }
.form-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Search input */
.search-input { width: 100%; max-width: 320px; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text); outline: none; transition: border-color var(--transition), box-shadow var(--transition); }
.search-input:focus { border-color: var(--accent); box-shadow: var(--shadow-sm); }

/* Generic input */
.input { min-height: 36px; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text); outline: none; transition: border-color var(--transition); }
.input:focus { border-color: var(--accent); }

/* View actions */
.view-actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); }

/* Summary bar */
.summary-bar { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; flex-wrap: wrap; }

/* Bulk bar */
.bulk-bar { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: var(--sp-3); box-shadow: var(--shadow-sm); }

/* Page size bar */
.page-size-bar { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-muted); padding: var(--sp-2) 0; }

/* Cron card */
.cron-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-4); box-shadow: var(--shadow-sm); transition: border-color var(--transition), box-shadow var(--transition); }
.cron-card:hover { border-color: var(--border-focus); box-shadow: var(--shadow-md); }
.cron-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-2); }
.cron-card-meta { font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: var(--sp-3); }
.cron-card-actions { display: flex; gap: var(--sp-2); }

/* Slide panel */
.sheet { position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 90vw; background: var(--bg-surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-xl); z-index: 100; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sheet-body { flex: 1; overflow-y: auto; padding: var(--sp-4); }

/* Empty / error / loading state — design system .state family. */
.state {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  padding: var(--sp-8) var(--sp-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  text-align: center;
}
.state-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.state-icon svg { width: 22px; height: 22px; }
.state-icon.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--border)); background: color-mix(in srgb, var(--warn) 12%, var(--bg-elevated)); }
.state-icon.err { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: color-mix(in srgb, var(--danger) 12%, var(--bg-elevated)); }
.state-icon.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 35%, var(--border)); background: color-mix(in srgb, var(--info) 12%, var(--bg-elevated)); }
.state-title { font-size: var(--fs-lg); font-weight: 600; letter-spacing: 0; }
.state-text {
  width: 100%;
  max-width: 52ch;
  box-sizing: border-box;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}
.state-actions { display: flex; gap: 8px; margin-top: var(--sp-2); }
.state-meta {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px dashed var(--border);
  width: 100%;
  max-width: 520px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-around;
  gap: var(--sp-3);
}
.state-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-4);
}
@media (max-width: 1100px) {
  .state-grid { grid-template-columns: 1fr; }
}


/* Log level button */
.log-level-btn { padding: var(--sp-1) var(--sp-2); font-size: var(--fs-xs); border-radius: var(--radius-sm); border: 1px solid var(--border); background: transparent; color: var(--text-muted); cursor: pointer; transition: all var(--transition); }
.log-level-btn:hover { border-color: var(--border-focus); color: var(--text); }
.log-level-btn.is-active { background: var(--bg-hover); color: var(--text); border-color: var(--border-focus); }

/* Config dirty field — accent is used because dirty state IS a signal, not
   chrome. Background tint is dialed from a hard-coded peach to a derived
   accent mix so it tracks both themes correctly. */
.field-dirty { border-left: 2px solid var(--accent); padding-left: var(--sp-3); background: color-mix(in srgb, var(--accent) 5%, transparent); border-radius: var(--radius-sm); }

/* Skill detail dialog */
.skill-dialog {
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text);
  box-shadow: var(--shadow-xl);
  /* `inset: 0; margin: auto` centers the dialog vertically too — browser
     default places <dialog> at the top of the viewport otherwise. */
  position: fixed;
  inset: 0;
  margin: auto;
  animation: skill-dialog-in 160ms ease-out;
}
.skill-dialog::backdrop {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  animation: skill-backdrop-in 160ms ease-out;
}
@keyframes skill-dialog-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes skill-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.skill-install-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-1) 0; }
.skill-install-row .btn { min-width: 96px; }

/* ──────────────────────────────────────────────────────────────────────── */
/* Drawer (right-side slide-out panel; sits above modal at z-index 1100)    */
/* ──────────────────────────────────────────────────────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 1100;
  opacity: 0;
  transition: opacity 180ms ease-out;
  display: flex;
  justify-content: flex-end;
}
.drawer-backdrop.is-open { opacity: 1; }
.drawer-backdrop.is-closing { opacity: 0; }
.drawer {
  position: relative;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  box-shadow: -16px 0 40px -8px rgba(0, 0, 0, 0.4);
  height: 100vh;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.2, 0.7, 0.2, 1);
  max-width: 100vw;
}
.drawer--right { margin-left: auto; }
.drawer.is-open { transform: translateX(0); }
.drawer.is-closing { transform: translateX(100%); }

.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.drawer__title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: 0;
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.drawer__close {
  background: none;
  border: 0;
  color: var(--text-muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.drawer__close:hover { background: var(--bg-elevated); color: var(--text); }

.drawer__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--sp-5);
}

.drawer__foot {
  flex: 0 0 auto;
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
}
.drawer__foot:empty { display: none; }

@media (max-width: 640px) {
  .drawer { width: 100vw !important; }
}

/* ──────────────────────────────────────────────────────────────────────── */
/* Combobox (input + listbox + create-on-miss row)                          */
/* ──────────────────────────────────────────────────────────────────────── */
.ui-combo {
  position: relative;
  width: 100%;
}
.ui-combo__input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input, var(--bg-surface));
  color: var(--text);
  font-size: var(--fs-sm);
  font-family: inherit;
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}
.ui-combo__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.ui-combo__list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.35);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1200;
}
.ui-combo__option {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  color: var(--text);
  font-size: var(--fs-sm);
}
.ui-combo__option:hover,
.ui-combo__option.is-active {
  background: var(--bg-elevated);
}
.ui-combo__option.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.ui-combo__label { font-weight: 500; }
.ui-combo__sublabel {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  margin-left: auto;
  font-family: var(--font-mono, monospace);
}
.ui-combo__option--create {
  border-top: 1px dashed var(--border);
  margin-top: 4px;
  padding-top: 8px;
  color: var(--accent);
  font-weight: 500;
  position: sticky;
  bottom: 0;
  background: var(--bg-surface);
}
.ui-combo__option--create:hover,
.ui-combo__option--create.is-active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.ui-combo__empty {
  padding: 8px 10px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  text-align: center;
  font-style: italic;
}
