/* ── HelgiChartsGallery · main stylesheet ────────────────────────────── */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: #111827;
  background: #f5f6f8;
  min-height: 100vh;
}

a { color: #4f46e5; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top toolbar ─────────────────────────────────────────────────────── */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  padding: 12px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.toolbar h1 {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
  margin-right: 8px;
  letter-spacing: -0.01em;
}

.toolbar .sub {
  font-size: 12px;
  color: #6b7280;
  font-weight: 400;
}

.toolbar .group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #4b5563;
}

.toolbar select,
.toolbar input[type="text"],
.toolbar input[type="number"] {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #111827;
}

.toolbar input[type="text"],
.toolbar input[type="number"] { min-width: 90px; }
.toolbar input[type="text"]:focus,
.toolbar input[type="number"]:focus,
.toolbar select:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.toolbar button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #111827;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.toolbar button:hover { background: #f3f4f6; border-color: #9ca3af; }
.toolbar button.primary {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
}
.toolbar button.primary:hover { background: #4338ca; border-color: #4338ca; }

.toolbar .spacer { flex: 1; }

.toolbar .counts { gap: 4px; }
.cnt-pill {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
  min-width: 38px;
  text-align: center;
}
.cnt-pill.cnt-loaded  { background:#ecfdf5; color:#047857; border-color:#a7f3d0; }
.cnt-pill.cnt-loading { background:#fffbeb; color:#b45309; border-color:#fde68a; }
.cnt-pill.cnt-error   { background:#fef2f2; color:#b91c1c; border-color:#fecaca; }

/* ── Wall layout ─────────────────────────────────────────────────────── */
/*
   The wall is a fixed-pixel CSS grid. Cells are 882 × 790 (the canonical
   web embedding size). Headers stick on top, the chart-type label sticks
   on the left so users always know what they're looking at while
   scrolling around the wall.
*/

:root {
  --cell-w: 882px;
  --cell-h: 790px;
  --type-col-w: 110px;
  --hdr-row1-h: 32px;
  --hdr-row2-h: 28px;
  --gap: 12px;
}

.wall-scroll {
  /* The wall is wider than the viewport. Let the page itself scroll
     horizontally rather than nesting an inner scroll container — that
     way sticky position works against the page. */
  width: 100%;
  overflow-x: auto;
}

.wall {
  display: grid;
  grid-template-columns: var(--type-col-w) repeat(12, var(--cell-w));
  /* 2 header rows (group + sub-header) + 6 chart-type rows */
  grid-template-rows: var(--hdr-row1-h) var(--hdr-row2-h) repeat(6, var(--cell-h));
  gap: var(--gap);
  padding: 16px 24px 64px;
  align-items: stretch;
  /* Make absolutely sure we span exactly the wall width — needed because
     children are fixed-pixel and the grid container itself shrinks to
     content. */
  width: max-content;
}

/* Group header (Yearly · Quarterly · Monthly) */
.wall-group-hdr {
  position: sticky;
  top: 60px;        /* below the toolbar */
  z-index: 20;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #3730a3;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.wall-group-hdr.yearly    { grid-column: 2 / span 4; }
.wall-group-hdr.quarterly { grid-column: 6 / span 4; }
.wall-group-hdr.monthly   { grid-column: 10 / span 4; }

/* Sub header (live · PNG · SVG · MP4) */
.wall-sub-hdr {
  position: sticky;
  top: calc(60px + var(--hdr-row1-h) + var(--gap));
  z-index: 19;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.wall-sub-hdr.live { background:#f0fdf4; color:#166534; border-color:#bbf7d0; }
.wall-sub-hdr.png  { background:#fff7ed; color:#9a3412; border-color:#fed7aa; }
.wall-sub-hdr.svg  { background:#eff6ff; color:#1d4ed8; border-color:#bfdbfe; }
.wall-sub-hdr.mp4  { background:#fdf4ff; color:#86198f; border-color:#f5d0fe; }

/* Top-left empty corner */
.wall-corner {
  position: sticky;
  top: 60px;
  left: 0;
  z-index: 30;
  background: #f5f6f8;
  grid-column: 1;
  grid-row: 1 / span 2;
}

/* Chart-type label (sticky left) */
.wall-type-label {
  position: sticky;
  left: 0;
  z-index: 18;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  text-align: center;
  padding: 8px;
  flex-direction: column;
  gap: 2px;
}
.wall-type-label .desc {
  font-size: 10px;
  font-weight: 400;
  color: #9ca3af;
  line-height: 1.2;
}

/* ── Cell ────────────────────────────────────────────────────────────── */

.cell {
  width: var(--cell-w);
  height: var(--cell-h);
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 10px;
  color: #6b7280;
  background: #fafafa;
  height: 24px;
  flex-shrink: 0;
}
.cell-head .stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}
.cell-head .stat-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #d1d5db;
}
.cell-head .stat-dot.idle    { background: #d1d5db; }
.cell-head .stat-dot.loading { background: #fbbf24; animation: pulse 1.2s infinite; }
.cell-head .stat-dot.loaded  { background: #10b981; }
.cell-head .stat-dot.error   { background: #ef4444; }

@keyframes pulse {
  0%,100% { opacity: 1;   }
  50%     { opacity: 0.3; }
}

.cell-head .cell-meta { color: #9ca3af; font-family: 'SF Mono', Menlo, Consolas, monospace; }

.cell-head .cell-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.cell-head .cell-actions button,
.cell-head .cell-actions a {
  font-size: 10px;
  font-family: inherit;
  padding: 1px 6px;
  border: 1px solid #e5e7eb;
  border-radius: 3px;
  background: #fff;
  color: #4b5563;
  cursor: pointer;
  text-decoration: none;
}
.cell-head .cell-actions button:hover,
.cell-head .cell-actions a:hover { background: #f3f4f6; color: #111827; }

.cell-head .errors-toggle { color:#b91c1c; font-weight:600; cursor:pointer; }
.cell-head .errors-toggle:hover { text-decoration: underline; }
.cell-head .bug-toggle    { color:#6366f1; font-weight:600; cursor:pointer; }
.cell-head .bug-toggle:hover { text-decoration: underline; }
.cell-head .bug-toggle.has  { color:#4338ca; }

.cell-body {
  flex: 1;
  position: relative;
  background: #fff;
  overflow: hidden;
}
.cell-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.cell-body img,
.cell-body object,
.cell-body video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  display: block;
}

.cell-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: #9ca3af;
  font-size: 12px;
  background: #fafafa;
  text-align: center;
  padding: 20px;
}
.cell-placeholder.error { background:#fef2f2; color:#b91c1c; }
.cell-placeholder button {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #111827;
  cursor: pointer;
}
.cell-placeholder button:hover { background:#4f46e5; border-color:#4f46e5; color:#fff; }
.cell-placeholder button:disabled { opacity:0.5; cursor:wait; }
.cell-placeholder .hint {
  font-size: 11px;
  color: #6b7280;
  max-width: 380px;
  line-height: 1.4;
}
.cell-placeholder .progress {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11px;
  color: #6366f1;
}

/* ── Modal ────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h2 { font-size: 16px; font-weight: 600; }
.modal-head .close {
  border: 0; background: none; cursor: pointer;
  font-size: 20px; color: #6b7280;
}
.modal-head .close:hover { color: #111827; }

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-body label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #4b5563;
  margin-bottom: 4px;
}
.modal-body textarea {
  width: 100%;
  min-height: 200px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 10px;
  resize: vertical;
}

.modal-body .meta {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 11px;
  color: #4b5563;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.modal-foot {
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: #fafafa;
}
.modal-foot button {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.modal-foot button.primary {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
}
.modal-foot button:hover { background: #f3f4f6; }
.modal-foot button.primary:hover { background: #4338ca; }

/* ── Viewer page ──────────────────────────────────────────────────────── */
/*
   The viewer is also embedded as an <iframe> inside each live cell of
   the wall. In that "embed=1" mode we hide the per-viewer toolbar
   entirely so the chart fills the iframe pixel-for-pixel and matches
   the production embedding.
*/

body.viewer {
  background: #fff;
  margin: 0;
}

.viewer-toolbar {
  position: sticky;
  top: 0;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #4b5563;
  z-index: 10;
}

.viewer-toolbar .badge {
  display: inline-block;
  background: #eef2ff;
  color: #4338ca;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.viewer-toolbar button {
  font-family: inherit;
  font-size: 11px;
  padding: 4px 10px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  color: #111827;
  cursor: pointer;
}
.viewer-toolbar button:hover { background: #f3f4f6; }
.viewer-toolbar button.primary { background: #4f46e5; border-color: #4f46e5; color: #fff; }

.viewer-toolbar .status {
  font-size: 11px;
  color: #6b7280;
}
.viewer-toolbar .status.ok    { color: #047857; }
.viewer-toolbar .status.err   { color: #b91c1c; }
.viewer-toolbar .status.warn  { color: #b45309; }

.viewer-mount {
  width: 100%;
  height: calc(100vh - 50px);
  padding: 12px;
}
.viewer-mount #chart {
  width: 100%;
  height: 100%;
}

/* embed mode — viewer fills its iframe and shows nothing else */
body.viewer.embed { background:#fff; padding:0; }
body.viewer.embed .viewer-toolbar { display:none !important; }
body.viewer.embed .viewer-mount { padding:0; height:100vh; width:100vw; }

/* ── Misc ─────────────────────────────────────────────────────────────── */

.error-list {
  margin: 0;
  padding-left: 18px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 11px;
  color: #b91c1c;
}
.error-list li { margin-bottom: 4px; }
