/* Plate Editor — 37degrees brand-aligned styles.
 * All rules scoped under .pe-root. Dark theme default; .pe-theme-light overrides.
 *
 * Brand tokens: navy-900 #082540 · navy-950 #04141f · navy-700 #133b56
 *   pink-400 #ff7bac · pink-600 #ec1f6a · text #dde4ed · muted #8ba5bd
 */

.pe-root {
  --pe-navy-900: #082540;
  --pe-navy-950: #04141f;
  --pe-navy-700: #133b56;
  --pe-navy-400: #5d83a1;
  --pe-text: #dde4ed;
  --pe-muted: #8ba5bd;
  --pe-accent: #ff7bac;
  --pe-accent-2: #ec1f6a;
  --pe-grid: rgba(141, 165, 189, 0.20);
  --pe-surface: rgba(4, 20, 31, 0.55);
  --pe-radius: 14px;
  --pe-radius-sm: 10px;
  --pe-radius-chip: 999px;
  --pe-mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  --pe-font: "Nunito Sans Variable", "Nunito Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  position: relative;
  font-family: var(--pe-font);
  color: var(--pe-text);
  background: linear-gradient(180deg, var(--pe-navy-900) 0%, var(--pe-navy-950) 100%);
  border: 1px solid var(--pe-navy-700);
  border-radius: var(--pe-radius);
  padding: 24px;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-areas: "header header" "rail stage" "footer footer";
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 16px;
  box-shadow: 0 10px 40px rgba(4, 20, 31, 0.35);
  box-sizing: border-box;
  max-width: 100%;
}
.pe-root *, .pe-root *::before, .pe-root *::after { box-sizing: border-box; }

@media (max-width: 860px) {
  .pe-root { grid-template-columns: 1fr; grid-template-areas: "header" "rail" "stage" "footer"; }
}

/* ---- Light theme ---------------------------------------------------- */
.pe-root.pe-theme-light {
  --pe-text: #082540;
  --pe-muted: #5d83a1;
  --pe-navy-700: #dde4ed;
  --pe-grid: rgba(8, 37, 64, 0.12);
  --pe-surface: #f7f9fc;
  background: linear-gradient(180deg, #ffffff 0%, #f1f4f8 100%);
  border-color: #dde4ed;
  box-shadow: 0 6px 24px rgba(8, 37, 64, 0.08);
}
.pe-root.pe-theme-light .pe-card,
.pe-root.pe-theme-light .pe-subcard,
.pe-root.pe-theme-light .pe-stage,
.pe-root.pe-theme-light .pe-fit-card,
.pe-root.pe-theme-light .pe-text,
.pe-root.pe-theme-light .pe-textarea,
.pe-root.pe-theme-light .pe-select { background: #ffffff; border-color: #dde4ed; color: var(--pe-text); }
.pe-root.pe-theme-light .pe-segmented,
.pe-root.pe-theme-light .pe-type-btn { background: #f1f4f8; border-color: #dde4ed; }
.pe-root.pe-theme-light .pe-corner,
.pe-root.pe-theme-light .pe-colhead,
.pe-root.pe-theme-light .pe-rowhead { color: var(--pe-muted); }
.pe-root.pe-theme-light .pe-well { border-color: #dde4ed; }

/* ---- Areas ---------------------------------------------------------- */
.pe-header { grid-area: header; display: flex; flex-direction: column; gap: 4px; }
.pe-rail { grid-area: rail; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.pe-stage { grid-area: stage; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.pe-footer { grid-area: footer; }

.pe-eyebrow { font-size: 11px; letter-spacing: 3px; font-weight: 800; color: var(--pe-accent); }
.pe-title { font-size: 22px; font-weight: 800; line-height: 1.2; }
.pe-subtitle { font-size: 14px; color: var(--pe-muted); line-height: 1.45; }

/* ---- Cards ---------------------------------------------------------- */
.pe-card {
  background: rgba(8, 37, 64, 0.4);
  border: 1px solid var(--pe-navy-700);
  border-radius: var(--pe-radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.pe-subcard {
  background: rgba(4, 20, 31, 0.35);
  border: 1px solid var(--pe-navy-700);
  border-radius: var(--pe-radius-sm);
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.pe-subcard-title, .pe-label { font-size: 10px; letter-spacing: 1.6px; font-weight: 800; color: var(--pe-muted); text-transform: uppercase; }

/* ---- Fields / inputs ------------------------------------------------ */
.pe-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1 1 auto; }
.pe-inline { display: flex; gap: 10px; align-items: flex-end; }
.pe-text, .pe-select {
  width: 100%; font-family: inherit; font-size: 13px; font-weight: 600; color: var(--pe-text);
  background: var(--pe-surface); border: 1px solid var(--pe-navy-700); border-radius: 8px;
  padding: 8px 10px; outline: none;
}
.pe-text-sm { font-family: var(--pe-mono); }
.pe-select { appearance: none; cursor: pointer; padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path fill='%238ba5bd' d='M6 8.5 1.5 4h9z'/></svg>");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 11px 11px; }
.pe-select-sm { font-size: 12px; }
.pe-text:focus, .pe-select:focus, .pe-textarea:focus { border-color: var(--pe-accent); box-shadow: 0 0 0 3px rgba(255, 123, 172, 0.18); }
.pe-text::placeholder, .pe-textarea::placeholder { color: var(--pe-muted); opacity: 0.7; }
.pe-textarea {
  width: 100%; font-family: var(--pe-mono); font-size: 12px; line-height: 1.5; color: var(--pe-text);
  background: var(--pe-surface); border: 1px solid var(--pe-navy-700); border-radius: 8px; padding: 10px; resize: vertical; outline: none;
}

/* ---- Palette -------------------------------------------------------- */
.pe-palette { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.pe-type-btn {
  display: flex; align-items: center; gap: 8px; font-family: inherit; font-size: 12px; font-weight: 700;
  color: var(--pe-text); background: var(--pe-surface); border: 1px solid var(--pe-navy-700);
  border-radius: 8px; padding: 7px 9px; cursor: pointer; text-align: left;
  transition: border-color 120ms ease, background 120ms ease;
}
.pe-type-btn:hover { border-color: var(--pe-navy-400); }
.pe-type-btn[aria-checked="true"] { border-color: var(--pe-accent); box-shadow: 0 0 0 2px rgba(255, 123, 172, 0.25); }
.pe-swatch { width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.15); }
.pe-attrs { display: flex; flex-direction: column; gap: 10px; }

/* ---- Buttons -------------------------------------------------------- */
.pe-btn-row, .pe-export-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pe-secondary {
  font-family: inherit; font-size: 13px; font-weight: 700; color: var(--pe-text);
  background: rgba(141, 165, 189, 0.10); border: 1px solid var(--pe-navy-700); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.pe-secondary:hover { background: rgba(255, 123, 172, 0.12); border-color: var(--pe-accent); color: var(--pe-accent); }
.pe-small { font-size: 12px; padding: 6px 10px; }
.pe-link { font-family: inherit; font-size: 13px; font-weight: 700; color: var(--pe-accent); background: transparent; border: none; border-bottom: 1px dashed var(--pe-accent); padding: 0 0 1px; cursor: pointer; align-self: flex-start; }
.pe-link:hover { color: var(--pe-accent-2); border-bottom-color: var(--pe-accent-2); }

/* ---- Segmented ------------------------------------------------------ */
.pe-segmented { display: inline-flex; background: var(--pe-surface); border: 1px solid var(--pe-navy-700); border-radius: var(--pe-radius-chip); padding: 3px; gap: 2px; }
.pe-segmented-btn { font-family: inherit; font-size: 12px; font-weight: 700; color: var(--pe-muted); background: transparent; border: 1px solid transparent; border-radius: var(--pe-radius-chip); padding: 6px 14px; cursor: pointer; }
.pe-segmented-btn:hover { color: var(--pe-text); }
.pe-segmented-btn[aria-checked="true"] { background: rgba(255, 123, 172, 0.14); border-color: var(--pe-accent); color: var(--pe-accent); }

/* ---- Stage head + legend ------------------------------------------- */
.pe-stage-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.pe-legend { display: flex; flex-wrap: wrap; gap: 10px; }
.pe-legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--pe-muted); }
.pe-legend-swatch { width: 11px; height: 11px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.15); }

/* ---- Plate ---------------------------------------------------------- */
.pe-stage { background: rgba(8, 37, 64, 0.4); border: 1px solid var(--pe-navy-700); border-radius: var(--pe-radius); padding: 16px; }
.pe-plate-scroll { overflow: auto; max-width: 100%; }
.pe-plate { display: grid; gap: 4px; align-items: center; justify-items: center; width: 100%; }
.pe-plate.pe-dense { gap: 2px; min-width: 640px; }
.pe-corner { width: 22px; height: 18px; }
.pe-colhead, .pe-rowhead { font-size: 11px; font-weight: 700; color: var(--pe-muted); font-variant-numeric: tabular-nums; cursor: default; user-select: none; }
.pe-colhead { padding-bottom: 2px; }
.pe-rowhead { padding-right: 4px; justify-self: end; }
.pe-well {
  width: 100%; aspect-ratio: 1 / 1; max-width: 46px;
  border: 1px solid var(--pe-navy-700); border-radius: 50%;
  background: transparent; cursor: pointer; padding: 0;
  font-family: var(--pe-mono); font-size: 9px; font-weight: 700; color: #04141f;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  transition: transform 80ms ease, box-shadow 80ms ease;
  touch-action: none;
}
.pe-well:hover { box-shadow: 0 0 0 2px var(--pe-accent); z-index: 2; }
.pe-well-filled { border-color: rgba(0,0,0,0.18); }
.pe-plate.pe-dense .pe-well { max-width: 18px; border-radius: 3px; font-size: 0; }

/* ---- Heatbar -------------------------------------------------------- */
.pe-heatbar { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--pe-muted); font-variant-numeric: tabular-nums; }
.pe-heatbar[hidden] { display: none; }
.pe-heatbar-grad { flex: 1 1 auto; height: 12px; border-radius: 6px; border: 1px solid var(--pe-navy-700); }

/* ---- Tooltip -------------------------------------------------------- */
.pe-tooltip {
  position: absolute; z-index: 99995; pointer-events: none;
  background: #04141f; color: #dde4ed; border: 1px solid var(--pe-accent);
  border-radius: 8px; padding: 7px 10px; font-size: 11.5px; line-height: 1.4; max-width: 220px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.pe-tooltip[hidden] { display: none; }
.pe-tooltip strong { color: var(--pe-accent); }

/* ---- Analysis ------------------------------------------------------- */
.pe-analysis { border-top: 1px dashed var(--pe-navy-700); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.pe-analysis-title { font-size: 11px; letter-spacing: 2px; font-weight: 800; color: var(--pe-accent); text-transform: uppercase; }
.pe-analysis-body { display: flex; flex-direction: column; gap: 14px; }
.pe-muted { font-size: 13px; color: var(--pe-muted); line-height: 1.5; }
.pe-fit-card { background: rgba(4, 20, 31, 0.45); border: 1px solid var(--pe-navy-700); border-radius: var(--pe-radius-sm); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.pe-fit-name { font-size: 14px; font-weight: 800; color: var(--pe-text); }
.pe-fit-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.pe-fit-stat { background: var(--pe-surface); border: 1px solid var(--pe-navy-700); border-radius: 8px; padding: 8px 10px; }
.pe-fit-stat-label { font-size: 9px; letter-spacing: 1px; font-weight: 800; color: var(--pe-muted); text-transform: uppercase; }
.pe-fit-stat-value { font-size: 15px; font-weight: 800; color: var(--pe-text); font-variant-numeric: tabular-nums; }
.pe-dose-chart { width: 100%; height: auto; display: block; background: var(--pe-surface); border-radius: 8px; border: 1px solid var(--pe-navy-700); }

/* ---- Status --------------------------------------------------------- */
.pe-status { font-size: 13px; line-height: 1.4; }
.pe-status:empty { display: none; }
.pe-status-info { color: var(--pe-text); padding: 9px 12px; background: rgba(141, 165, 189, 0.10); border: 1px solid var(--pe-navy-700); border-radius: 8px; }
.pe-status-ok { color: var(--pe-text); padding: 9px 12px; background: rgba(52, 211, 153, 0.10); border: 1px solid rgba(52, 211, 153, 0.35); border-radius: 8px; }
.pe-status-error { color: #ffffff; padding: 9px 12px; background: rgba(236, 31, 106, 0.18); border: 1px solid var(--pe-accent-2); border-radius: 8px; }
.pe-root.pe-theme-light .pe-status-ok { color: #0a5; }
.pe-root.pe-theme-light .pe-status-error { color: var(--pe-accent-2); }

/* ---- Footer / fatal ------------------------------------------------- */
.pe-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--pe-muted); }
.pe-footer a { color: var(--pe-text); text-decoration: none; font-weight: 700; }
.pe-footer a:hover { color: var(--pe-accent); }
.pe-footer-sep { opacity: 0.5; }
.pe-footer-brand { color: #ff7bac !important; font-weight: 700; }
.pe-footer-brand:hover { color: #ec1f6a !important; text-decoration: underline; }
.pe-fatal { font-family: var(--pe-font, system-ui, sans-serif); padding: 16px; border-radius: 10px; background: rgba(236, 31, 106, 0.12); border: 1px solid #ec1f6a; color: #ffffff; }

/* ---- Responsive ----------------------------------------------------- */
@media (max-width: 640px) {
  .pe-root { padding: 18px; }
  .pe-title { font-size: 19px; }
  .pe-palette { grid-template-columns: 1fr; }
}

/* ===================================================================
   Expand / fullscreen (in-page overlay; no Fullscreen API)
   =================================================================== */
.pe-expand-icon {
  position: absolute; top: 14px; right: 14px; z-index: 50;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 123, 172, 0.10); color: #ec1f6a; border: 1px solid rgba(255, 123, 172, 0.30);
  border-radius: 10px; cursor: pointer; padding: 0; font-family: inherit;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}
.pe-expand-icon:hover { background: rgba(255, 123, 172, 0.22); border-color: rgba(255, 123, 172, 0.55); transform: scale(1.05); }
.pe-expand-icon-label { display: none; }
.pe-brand-mark { display: none; }

html.pe-html-locked, body.pe-body-locked { overflow: hidden !important; height: 100vh !important; }

.pe-root.pe-is-expanded {
  position: fixed; inset: 0; z-index: 99990; margin: 0; border: none; border-radius: 0; box-shadow: none;
  background: #ffffff; color: #082540;
  --pe-text: #082540; --pe-muted: #5d83a1; --pe-navy-700: #dde4ed; --pe-grid: rgba(8,37,64,0.12); --pe-surface: #f7f9fc;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "brand stage" "rail stage" "footer footer";
  gap: 0; padding: 0; height: 100vh; overflow: hidden;
}
.pe-root.pe-is-expanded .pe-header { display: none; }
.pe-root.pe-is-expanded .pe-rail { grid-area: rail; overflow-y: auto; padding: 18px; border-right: 1px solid #dde4ed; background: #f1f4f8; min-height: 0; }
.pe-root.pe-is-expanded .pe-stage { grid-area: stage; overflow-y: auto; min-height: 0; background: #ffffff; border: none; border-radius: 0; padding: 18px; }
.pe-root.pe-is-expanded .pe-card, .pe-root.pe-is-expanded .pe-subcard, .pe-root.pe-is-expanded .pe-fit-card,
.pe-root.pe-is-expanded .pe-text, .pe-root.pe-is-expanded .pe-textarea, .pe-root.pe-is-expanded .pe-select { background: #ffffff; border-color: #dde4ed; color: #082540; }
.pe-root.pe-is-expanded .pe-expand-icon { position: fixed; top: 18px; right: 22px; z-index: 99991; width: auto; gap: 8px; padding: 0 14px; font-weight: 800; font-size: 13px; background: rgba(236, 31, 106, 0.08); border-color: rgba(236, 31, 106, 0.35); }
.pe-root.pe-is-expanded .pe-expand-icon-label { display: inline-block; }
.pe-root.pe-is-expanded .pe-brand-mark {
  grid-area: brand; display: flex; align-items: center; gap: 10px; text-decoration: none;
  color: #ffffff; background: #082540; font-family: var(--pe-font); font-weight: 800; font-size: 15px; line-height: 1;
  padding: 14px 20px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.pe-root.pe-is-expanded .pe-brand-mark svg { height: 28px; width: 28px; display: block; flex-shrink: 0; }
.pe-root.pe-is-expanded .pe-brand-mark .pe-brand-sep { color: #ff7bac; margin: 0 2px; }
.pe-root.pe-is-expanded .pe-brand-mark .pe-tool-name { color: #ff7bac; letter-spacing: 0.4px; }
.pe-root.pe-is-expanded .pe-brand-mark:hover { background: #04141f; }
.pe-root.pe-is-expanded .pe-footer { grid-area: footer; background: #082540; padding: 12px 24px; justify-content: center; margin: 0; }
.pe-root.pe-is-expanded .pe-footer, .pe-root.pe-is-expanded .pe-footer span { color: #ffffff; }
.pe-root.pe-is-expanded .pe-footer a { color: #ff7bac; }
.pe-root.pe-is-expanded .pe-footer-sep { color: #ff7bac; opacity: 0.6; }

@media (max-width: 960px) {
  .pe-root.pe-is-expanded { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0,1fr) auto; grid-template-areas: "brand" "rail" "stage" "footer"; }
  .pe-root.pe-is-expanded .pe-rail { border-right: none; border-bottom: 1px solid #e4ecf2; max-height: 40vh; }
  .pe-root.pe-is-expanded .pe-brand-mark .pe-brand-sep, .pe-root.pe-is-expanded .pe-brand-mark .pe-tool-name { display: none; }
}
