
/* ========= SPARK Viewer — responsive overrides (append after existing <style>) ========= */

/* 1) Base tweaks */
html { -webkit-text-size-adjust: 100%; }
.mono, td, th { word-break: break-word; overflow-wrap: anywhere; }

/* 2) Toolbar: flexible on desktop, stacked on mobile */
.toolbar { gap: 10px; flex-wrap: wrap; align-items: end; }
.toolbar form { display: contents; } /* allows children to wrap naturally without extra markup */
@supports (display: grid) {
  @media (max-width: 900px) {
    .toolbar { display: grid; grid-template-columns: 1fr; gap: 8px; }
    .toolbar form > * { display: block; width: 100%; }
    .toolbar label { margin: 0 !important; }
    .toolbar input[type="search"],
    .toolbar select,
    .toolbar .btn,
    .toolbar .select { width: 100%; }
  }
}

/* 3) Cards + key-values */
.row { align-items: flex-start; }
.row > .kv { flex: 1 1 clamp(220px, 33%, 420px); }
.kv > .small { line-height: 1.2; }
.kv > div:last-child { font-weight: 600; }

/* 4) Tables */
.table-wrap { scrollbar-gutter: stable; }
.table-wrap::-webkit-scrollbar { height: 10px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
/* Subtle fade at the left/right edges during horizontal scroll */
.table-wrap {
  --fade: 16px;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--fade), #000 calc(100% - var(--fade)), transparent 100%);
          mask-image: linear-gradient(to right, transparent 0, #000 var(--fade), #000 calc(100% - var(--fade)), transparent 100%);
}
th, td { vertical-align: top; }
/* Ensure sticky header works for both <tr class="sticky-head"> and plain <thead> */
thead th.sticky-head, .sticky-head th {
  position: sticky; top: 0; background: var(--card); z-index: 1; box-shadow: var(--shadow-sm);
}

/* Compact mode on very small phones */
@media (max-width: 480px) {
  table { font-size: 12.5px; }
  th, td { padding: 6px 8px; }
}

/* 5) Buttons / inputs tap size */
.btn, .select, input[type="search"], select { min-height: 40px; }
@media (max-width: 768px) { .btn, .select, input[type="search"], select { min-height: 44px; }}

/* 6) Modals */
.modal-backdrop { align-items: center; justify-content: center; }
.modal .modal-header { position: sticky; top: 0; background: #fff; z-index: 10; }
@media (max-width: 640px) {
  .modal-backdrop { padding: 0; }
  .modal { width: 100%; height: 100vh; max-height: none; border-radius: 0; }
}

/* 7) Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* 8) Dark mode (auto by OS preference) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --card: #0f1428;
    --text: #e6eaf5;
    --muted: #98a2b3;
    --border: #1f2a44;
    --chip: #121a33;
    --row-alt: #0e1730;
    --row-hover: #1b2a55;
    --focus: #7aa2ff;
    --shadow-sm: 0 1px 0 rgba(6,10,24,.4), 0 2px 4px rgba(6,10,24,.6);
  }
  .btn:hover { background: #121a33; }
  .modal pre { background: #060a18; color: #d9e1ff; }
}

/* 9) Print */
@media print {
  body { background: #fff; color: #000; }
  .container { width: 100%; padding: 0; }
  .toolbar, .modal-backdrop { display: none !important; }
  .card { break-inside: avoid; border: 1px solid #ddd; box-shadow: none; }
  a::after { content: " (" attr(href) ")"; font-weight: normal; color: #666; }
}
