/* ==========================================================================
   Jmak Simulator — Componentes derivados do Jimble Design System
   ========================================================================== */

html { scrollbar-gutter: stable; }
html, body { background: var(--surface); }

/* ---------- Layout shell ---------- */
.j-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.j-topbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  padding: 0 var(--space-6);
  margin: 0 auto;
  max-width: 1280px;
}
.j-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  color: var(--foreground);
}
.j-brand img { height: 24px; width: auto; }
.j-brand-pill {
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--muted-foreground);
  border-left: 1px solid var(--border);
  padding-left: var(--space-3);
  margin-left: var(--space-1);
}
.j-page {
  margin: 0 auto;
  max-width: 1280px;
  padding: var(--space-8) var(--space-6);
}
.j-page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.j-page-title {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  color: var(--foreground);
}
.j-page-subtitle {
  font-size: var(--text-sm);
  color: var(--muted-foreground);
  margin-top: 2px;
}

/* ---------- Card ---------- */
.j-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.j-card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.j-card-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--foreground);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.j-card-subtitle {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  margin-top: 2px;
  font-weight: 400;
}
.j-card-body { padding: var(--space-5) var(--space-6); }
.j-card-body-tight { padding: var(--space-4) var(--space-5); }

/* ---------- Buttons ---------- */
.j-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 36px;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: var(--text-sm);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.j-btn:active:not(:disabled) { transform: scale(0.99); }
.j-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.j-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
/* Click reliability: keep the entire button rect as the event target. Without
   this, clicking on a Lucide-generated <svg> child (or its <path>) can swallow
   the click before it bubbles up to the <button>. */
.j-btn > * { pointer-events: none; }

.j-btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.j-btn-xs { height: 24px; padding: 0 var(--space-2); font-size: var(--text-2xs); border-radius: var(--radius-sm); }
.j-btn-icon { padding: 0; width: 36px; }
.j-btn-icon.j-btn-sm { width: 30px; }

.j-btn-primary { background: var(--primary); color: var(--primary-foreground); }
.j-btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.j-btn-secondary { background: var(--secondary); color: var(--secondary-foreground); border-color: var(--border); }
.j-btn-secondary:hover:not(:disabled) { background: var(--accent); }

.j-btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.j-btn-destructive:hover:not(:disabled) { filter: brightness(0.94); }

.j-btn-warning { background: var(--warning); color: var(--warning-foreground); }
.j-btn-warning:hover:not(:disabled) { filter: brightness(0.94); }

.j-btn-info { background: var(--info); color: var(--info-foreground); }
.j-btn-info:hover:not(:disabled) { filter: brightness(0.94); }

.j-btn-ghost { background: transparent; color: var(--muted-foreground); }
.j-btn-ghost:hover:not(:disabled) { background: var(--accent); color: var(--foreground); }

.j-btn-link {
  background: transparent;
  color: var(--info);
  height: auto;
  padding: 0;
  border: 0;
}
.j-btn-link:hover:not(:disabled) { text-decoration: underline; }
.j-btn-link.is-destructive { color: var(--destructive); }

/* ---------- Inputs ---------- */
.j-input,
.j-textarea,
.j-select {
  width: 100%;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: 1.4;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.j-textarea { font-family: var(--font-mono); font-size: var(--text-xs); resize: vertical; }
.j-input:focus,
.j-textarea:focus,
.j-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}
.j-input::placeholder, .j-textarea::placeholder { color: var(--muted-foreground); }
.j-input.is-mono { font-family: var(--font-mono); }
.j-input-sm { padding: 4px var(--space-2); font-size: var(--text-xs); }

.j-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--foreground);
  margin-bottom: var(--space-1);
}

/* ---------- Tables ---------- */
.j-table {
  width: 100%;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  border-collapse: collapse;
}
.j-table thead { background: var(--surface); }
.j-table thead th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-2xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.j-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
.j-table tbody tr:hover td { background: color-mix(in oklab, var(--accent) 60%, transparent); }
.j-table tbody tr.is-expanded td { background: var(--surface); }

.j-table-compact { font-size: var(--text-xs); }
.j-table-compact thead th,
.j-table-compact tbody td { padding: var(--space-2) var(--space-3); }
.j-table-bordered { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

/* ---------- Status dot + pulse ---------- */
.j-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  background: var(--muted-foreground);
}
.j-dot-live {
  background: var(--success);
  position: relative;
}
.j-dot-live::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: var(--radius-full);
  background: var(--success);
  opacity: 0.35;
  animation: jimble-pulse-ring 1.6s var(--ease-out) infinite;
}
@keyframes jimble-pulse-ring {
  0%   { transform: scale(0.6); opacity: 0.5; }
  80%  { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .j-dot-live::after { animation: none; opacity: 0.25; }
}
.j-dot-success { background: var(--success); }
.j-dot-warning { background: var(--warning); }
.j-dot-destructive { background: var(--destructive); }
.j-dot-info { background: var(--info); }
.j-dot-muted { background: var(--muted-foreground); opacity: 0.4; }

/* ---------- Status text ---------- */
.j-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}
.j-status-success { color: var(--success); }
.j-status-warning { color: var(--warning); }
.j-status-destructive { color: var(--destructive); }
.j-status-muted { color: var(--muted-foreground); }

/* ---------- Pills / badges ---------- */
.j-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-2xs);
  font-weight: 500;
  line-height: 1.6;
  border: 1px solid transparent;
  white-space: nowrap;
}
.j-pill-muted { background: var(--muted); color: var(--muted-foreground); }
.j-pill-success { background: var(--success-subtle); color: var(--primary-subtle-fg); }
.j-pill-warning { background: var(--warning-subtle); color: var(--warning-foreground); }
.j-pill-destructive { background: var(--destructive-subtle); color: var(--destructive); }
.j-pill-info { background: var(--info-subtle); color: var(--info); }
.j-pill-outline { border-color: var(--border); color: var(--muted-foreground); }

/* ---------- Modal ---------- */
.j-modal-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  /* Anchor to the top so native <select> dropdowns inside the modal always have
     room to open downward instead of flipping up. */
  align-items: flex-start;
  justify-content: center;
  padding: max(8vh, 48px) var(--space-4) var(--space-4);
  overflow-y: auto;
  z-index: 50;
}
.j-modal {
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  padding: var(--space-6);
  max-height: 90vh;
  overflow-y: auto;
}
.j-modal h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--foreground);
  letter-spacing: var(--tracking-tight);
}

/* ---------- Helpers ---------- */
.j-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.j-muted { color: var(--muted-foreground); }
.j-divider { border-top: 1px solid var(--border); }
.j-callout-warning {
  background: var(--warning-subtle);
  border: 1px solid color-mix(in oklab, var(--warning) 30%, transparent);
  color: var(--warning-foreground);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}
.j-callout-info {
  background: var(--info-subtle);
  border: 1px solid color-mix(in oklab, var(--info) 30%, transparent);
  color: var(--info);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}
.j-callout-success {
  background: var(--success-subtle);
  border: 1px solid color-mix(in oklab, var(--success) 30%, transparent);
  color: var(--primary-subtle-fg);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}
.j-error {
  color: var(--destructive);
  font-size: var(--text-sm);
}
.j-collapsible-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  padding: var(--space-4) var(--space-6);
  background: transparent;
  cursor: pointer;
  border: 0;
}
.j-collapsible-toggle:hover { background: color-mix(in oklab, var(--accent) 50%, transparent); }

.j-version {
  position: fixed;
  right: 8px;
  bottom: 6px;
  font-size: 10px;
  line-height: 1;
  font-family: var(--font-mono, ui-monospace, monospace);
  color: var(--muted-foreground);
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
  z-index: 10;
}
