/* ═══════════════════════════════════════════════════════════════════════
 * IPRS — Component Refinements & Responsive Layer
 * ───────────────────────────────────────────────────────────────────────
 * Loaded after theme.css and layout.css. Adds:
 *   • Mobile/tablet adaptive layout (sidebar collapses, toolbar wraps)
 *   • Focus-visible refinements (a11y)
 *   • Loading/empty states
 *   • Print styles for docs
 *   • Micro-component polish (table, chips, tooltips)
 * ═══════════════════════════════════════════════════════════════════════ */

/* ────────────────────────────────────────────────────────────────
 * Accessibility — focus rings
 * ──────────────────────────────────────────────────────────────── */
*:focus { outline: none; }
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sharp);
}

/* ────────────────────────────────────────────────────────────────
 * Loading & empty states
 * ──────────────────────────────────────────────────────────────── */
.empty-state {
  padding: var(--sp-6);
  text-align: center;
  color: var(--ink-soft);
  font-size: var(--fs-small);
  font-style: italic;
}
.loading-pulse {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
.loading-pulse + .loading-pulse { margin-left: 4px; animation-delay: 0.2s; }
.loading-pulse + .loading-pulse + .loading-pulse { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* ────────────────────────────────────────────────────────────────
 * Chips & tags (compact metadata display)
 * ──────────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--rule-soft);
  font-size: var(--fs-micro);
  color: var(--ink-soft);
  font-family: var(--font-mono);
}
.chip.success { background: rgba(96, 138, 90, 0.1); color: var(--green); border-color: rgba(96, 138, 90, 0.3); }
.chip.warning { background: rgba(184, 84, 26, 0.1); color: var(--accent); border-color: rgba(184, 84, 26, 0.3); }
.chip.error { background: rgba(192, 80, 65, 0.1); color: var(--coral); border-color: rgba(192, 80, 65, 0.3); }

/* ────────────────────────────────────────────────────────────────
 * Tooltips (lightweight, CSS-only)
 * ──────────────────────────────────────────────────────────────── */
[data-tooltip] {
  position: relative;
  cursor: help;
}
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 6px 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: var(--fs-micro);
  border-radius: var(--r-soft);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease-out;
  box-shadow: var(--shadow-2);
  z-index: 1000;
}
[data-tooltip]:hover::after {
  opacity: 1;
}

/* ────────────────────────────────────────────────────────────────
 * Result tables (used inside results modal)
 * ──────────────────────────────────────────────────────────────── */
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
  font-family: var(--font-mono);
}
.result-table th,
.result-table td {
  text-align: right;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--rule-soft);
}
.result-table th {
  font-family: var(--font-sans);
  font-weight: 500;
  text-align: left;
  color: var(--ink-soft);
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.result-table td:first-child { text-align: left; }
.result-table tr:last-child td { border-bottom: none; }
.result-table tr.total {
  font-weight: 600;
  background: var(--bg-elevated);
}

/* Upload status badge inline */
.upload-status {
  display: inline-block;
  margin-left: 6px;
  font-size: var(--fs-micro);
  color: var(--green);
  font-family: var(--font-mono);
}

/* ────────────────────────────────────────────────────────────────
 * Responsive — tablet (<1024px): collapse sidebar
 * ──────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 280px;
    --toolbar-h: 56px;
  }
  .toolbar {
    gap: var(--sp-4);
    padding: 0 var(--sp-4);
    overflow-x: auto;
  }
  .tool-group {
    flex-shrink: 0;
  }
  .sidebar {
    padding: var(--sp-3);
  }
}

/* ────────────────────────────────────────────────────────────────
 * Responsive — mobile (<768px): stack layout
 * ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body {
    grid-template-rows: var(--toolbar-h) 1fr auto var(--statusbar-h);
  }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .sidebar {
    max-height: 40vh;
    overflow-y: auto;
    border-left: none;
    border-top: 1px solid var(--rule);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
  }
  .toolbar {
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .toolbar .brand-mark {
    font-size: var(--fs-large);
  }
  .toolbar .run-all {
    margin-left: auto;
    padding: 0 var(--sp-3);
  }
  .modal {
    width: 95vw;
    max-height: 88vh;
    margin: var(--sp-2);
  }
  .canvas-overlay {
    top: var(--sp-2);
    left: var(--sp-2);
  }
  .canvas-badge {
    font-size: var(--fs-micro);
    padding: var(--sp-1) var(--sp-2);
  }
}

/* ────────────────────────────────────────────────────────────────
 * Responsive — small mobile (<480px)
 * ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .toolbar .label {
    display: none;  /* icon-only buttons */
  }
  .statusbar {
    font-size: var(--fs-micro);
  }
  .canvas-badge {
    display: none;  /* hide overlay info on tiny screens */
  }
}

/* ────────────────────────────────────────────────────────────────
 * Print styles (for docs pages)
 * ──────────────────────────────────────────────────────────────── */
@media print {
  body { background: white; color: black; }
  .toolbar, .sidebar, .statusbar, .canvas-overlay { display: none; }
  .main { grid-template-columns: 1fr; }
  .modal-overlay { position: static; background: none; backdrop-filter: none; }
  .modal { box-shadow: none; border: 1px solid #ccc; }
}

/* ────────────────────────────────────────────────────────────────
 * Animations refined — subtle, scientific (no flashy)
 * ──────────────────────────────────────────────────────────────── */
.svg-node {
  transition: filter 180ms ease-out, transform 180ms ease-out;
}
.svg-node:hover {
  filter: brightness(1.06) drop-shadow(0 2px 4px rgba(0,0,0,0.08));
}
.svg-edge {
  transition: stroke-width 180ms ease-out, stroke 180ms ease-out;
}
.svg-edge:hover {
  stroke-width: 2.5;
}

/* Node selected state — subtle ring instead of stark outline */
.svg-node.selected {
  filter: drop-shadow(0 0 0 2px var(--accent)) drop-shadow(0 2px 6px rgba(184,84,26,0.25));
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ────────────────────────────────────────────────────────────────
 * Access Gate — Login / MFA Modal
 * ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 27, 22, 0.85);
  backdrop-filter: blur(6px);
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: var(--r-soft);
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(31, 27, 22, 0.32);
}
.modal-box .icon {
  font-size: 28px;
  color: var(--accent);
  margin-bottom: 12px;
  text-align: center;
}
.modal-box h3 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 8px;
  text-align: center;
}
.modal-box .sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.5;
}
.modal-box input[type="email"],
.modal-box input[type="password"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  border-radius: var(--r-sharp);
  box-sizing: border-box;
}
.modal-box input:focus { outline: none; border-color: var(--accent); }
.modal-box .btn-row { display: flex; gap: 8px; margin-top: 4px; }
.modal-box .btn-row .btn { flex: 1; padding: 11px 16px; justify-content: center; }
.modal-box .btn-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.modal-box .btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
}
.modal-error {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--coral, #c05041);
  text-align: center;
  margin-top: 6px;
  min-height: 16px;
}
.modal-note {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-mute);
  text-align: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  line-height: 1.5;
}
.modal-note a { color: var(--accent); text-decoration: underline; }
