/* xsvg page styles — built entirely on lib's design tokens (tokens.css)
   so the page is native to the Develop design system and follows light/dark
   automatically. No hardcoded colors; every surface/text/border references a
   token. The shared header/footer carry their own sealed styles. */

* {
  box-sizing: border-box;
}

/* The HTML `hidden` attribute must win over the display rules below — without
   this, `.state-card`/`.workspace { display: grid }` (specificity 0,1,0)
   override the UA `[hidden] { display: none }` rule, so the loading card +
   login gate + tool would all render at once (especially in the logged-out
   state). app.js toggles `.hidden` on #loading/#gate/#tool, so this is what
   actually hides them. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.page {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.page-head {
  margin-bottom: 24px;
}

.page-head h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.lede {
  margin: 0;
  max-width: 60ch;
  color: var(--muted-foreground);
  font-size: 15px;
}

.muted {
  color: var(--muted-foreground);
}

/* ---- cards / shared surfaces ---- */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--card-foreground);
}

/* ---- loading / login-gate state ---- */

.state-card {
  display: grid;
  gap: 12px;
  justify-items: start;
  max-width: 460px;
  margin: 40px auto;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--card-foreground);
}

.state-card h2 {
  margin: 0;
  font-size: 20px;
}

.state-card p {
  margin: 0;
  font-size: 14px;
}

/* ---- buttons ---- */

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 140ms ease, background 140ms ease;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-primary:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-color: var(--border);
}

.btn-secondary:hover {
  opacity: 0.9;
}

.download-button.is-disabled {
  pointer-events: none;
  opacity: 0.45;
}

/* ---- workspace layout ---- */

.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

.controls {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.field {
  display: grid;
  gap: 7px;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--foreground);
}

select,
input[type='text'],
input[type='number'] {
  width: 100%;
  min-height: 40px;
  /* `button, input, select { font: inherit }` above makes these inherit the
     body's 16px; the buttons override via .btn (14px) but the controls had no
     override, so the <select> rendered 16px — visibly larger than the 13–14px
     labels/buttons around it. Pin the form-control font to the 14px scale. */
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: var(--background);
  color: var(--foreground);
}

select:focus-visible,
input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* ---- dropzone ---- */

.dropzone {
  position: relative;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--muted);
  transition: border-color 140ms ease, background 140ms ease;
}

.dropzone.is-dragging {
  border-color: var(--ring);
}

.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone__body {
  display: flex;
  min-height: 128px;
  align-items: center;
  gap: 14px;
  padding: 20px;
}

.dropzone__body strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.dropzone__body span {
  display: block;
  color: var(--muted-foreground);
  font-size: 13px;
}

.dropzone__icon {
  display: grid;
  width: 44px;
  height: 44px;
  flex: none;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-foreground);
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

/* ---- checkbox rows ---- */

.checkbox-field {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--background);
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.checkbox-field span {
  font-size: 13px;
  font-weight: 600;
}

/* ---- preview panel ---- */

.preview-panel {
  padding: 20px;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.preview-header h2 {
  margin: 0;
  font-size: 18px;
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

figure {
  min-width: 0;
  margin: 0;
}

figcaption {
  margin-bottom: 8px;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 600;
}

.canvas-box {
  display: grid;
  min-height: 300px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* checkerboard so transparency reads clearly, drawn from tokens */
  background-color: var(--card);
  background-image:
    linear-gradient(45deg, var(--muted) 25%, transparent 25%),
    linear-gradient(-45deg, var(--muted) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--muted) 75%),
    linear-gradient(-45deg, transparent 75%, var(--muted) 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.canvas-box span {
  color: var(--muted-foreground);
  font-size: 13px;
}

.canvas-box img,
.canvas-box object {
  display: block;
  max-width: 100%;
  max-height: 300px;
}

/* ---- metrics ---- */

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.metrics div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--background);
}

.metrics span {
  display: block;
  color: var(--muted-foreground);
  font-size: 12px;
}

.metrics strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- status log ---- */

.status-log {
  min-height: 72px;
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--muted);
  color: var(--foreground);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.status-log.is-error {
  border-color: var(--destructive);
  color: var(--destructive);
}

/* ---- responsive ---- */

@media (max-width: 900px) {
  .workspace,
  .preview-grid,
  .metrics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .page {
    width: calc(100vw - 20px);
    padding: 18px 0 40px;
  }

  .page-head h1 {
    font-size: 24px;
  }

  .canvas-box {
    min-height: 220px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
