/* GraphPaper — generator widget + print stylesheet.
   Theme colors come from site.config.json (--primary blue / --accent teal).
   Print strategy: the paper is an inline <svg> whose viewBox is in mm; the
   injected #gp-print-css pins .gp-print svg to physical mm so a 5 mm grid
   prints as exactly 5 mm (requires "Actual size" in the print dialog). */

.gp {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.25rem;
  margin: 1.4rem 0 2rem;
}

/* ---- controls ---- */

.gp-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.7rem;
}
/* never give a possibly-[hidden] element a bare display rule (P015) */
.gp-fields label:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  min-width: 0;
}
.gp-fields select,
.gp-fields input[type='number'],
.gp-fields input[type='text'] {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  min-height: 44px;
  width: 100%;
}
.gp-fields select:focus,
.gp-fields input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
.gp-fields label.gp-check:not([hidden]) {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.86rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  padding-top: 1.2rem;
}
.gp-check input {
  accent-color: var(--primary);
  width: 1.05rem;
  height: 1.05rem;
  flex: none;
}
.gp-unit {
  color: var(--text-dim);
  font-weight: 500;
  text-transform: none;
}

/* ---- status + stage ---- */

.gp-status {
  margin: 0.95rem 0 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--accent);
  min-height: 1.3em;
}
[data-state='error'] .gp-status {
  color: #b45309;
}

.gp-stage {
  margin-top: 0.8rem;
  display: flex;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background:
    repeating-conic-gradient(var(--surface-2) 0% 25%, var(--bg) 0% 50%) 0 0 / 18px
    18px;
  padding: 0.9rem;
}
.gp-svg {
  display: block;
  width: 100%;
  max-width: 34rem;
  height: auto;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.14);
}

.gp-note {
  margin: 0.8rem 0 0;
  font-size: 0.86rem;
  color: #92400e;
  border: 1px solid color-mix(in srgb, #d97706 45%, var(--border));
  background: color-mix(in srgb, #d97706 8%, var(--bg));
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.8rem;
}

/* ---- actions ---- */

.gp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.9rem;
}
.gp-actions button {
  font: inherit;
  font-size: 0.94rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.15rem;
  cursor: pointer;
}
.gp-actions button:hover {
  filter: brightness(1.08);
}
.gp-actions button[name='svg'] {
  color: var(--primary);
  background: var(--bg);
  border: 1.5px solid var(--primary);
}

/* small content helpers */
.privnote {
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  font-size: 0.92rem;
}
.formula {
  font-family: var(--mono);
  font-size: 0.95rem;
  background: var(--surface-2);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.prose table.fmt td:first-child,
.prose table.fmt th:first-child {
  min-width: 7rem;
}

/* ---- print ----
   Only the paper area prints, at true physical size. The @page size and the
   svg's mm dimensions are injected per-render into #gp-print-css; the rules
   below are the static half: hide every body-level element except the
   .gp-print clone holder, and give the paper real millimetres (default A4 —
   overridden by the injected rule the moment the generator runs). */

.gp-print {
  display: none;
}

@media print {
  @page {
    margin: 0mm;
  }
  body > *:not(.gp-print) {
    display: none !important;
  }
  .gp-print {
    display: block !important;
  }
  .gp-print svg {
    display: block;
    width: 210mm;
    height: 297mm;
    max-width: none;
  }
}

@media (max-width: 560px) {
  .gp {
    padding: 0.9rem;
  }
  .gp-stage {
    padding: 0.5rem;
  }
  .gp-actions button {
    flex: 1 1 auto;
    text-align: center;
  }
}
