/* ---- Page rules that lived in app-ui.css; they sit first so this file's own rules still follow them. ---- */
/* Watch editor: product typography outside the canvas, purpose-built density inside. */
body[data-wd-page="layout"] .topbar { min-height: 82px; padding: 12px var(--wd-page-gutter); }
body[data-wd-page="layout"] .tool-heading { min-width: 190px; }
body[data-wd-page="layout"] .tool-heading .v5-eyebrow { margin-bottom: .25rem; font-size: .61rem; }
body[data-wd-page="layout"] .tool-heading h1 { margin: 0; color: var(--wd-text); font-size: 1.18rem; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
body[data-wd-page="layout"] .topbar .tabs { padding: .25rem; border: 1px solid var(--wd-border-control); border-radius: var(--wd-radius-pill); background: var(--wd-surface); }
body[data-wd-page="layout"] .topbar .tab { border: 1px solid transparent; border-radius: var(--wd-radius-pill); background: transparent; color: var(--wd-muted); font: 500 .875rem var(--wd-font); line-height: 1; }
body[data-wd-page="layout"] .topbar .tab.active { border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .13); color: #f87171; box-shadow: none; }
body[data-wd-page="layout"] .section h2 { color: var(--wd-muted); font-size: .67rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
/* Tool pages keep their density but inherit color and control polish. */
body[data-wd-page="layout"] .topbar { background: rgba(11, 14, 19, .96); }
/* Action buttons are pills like everywhere else; list rows stay cards; fields match the portal. */
body[data-wd-page="layout"] button:not(.page-toggle, .racing-slot) { border-radius: var(--wd-radius-pill); }
/* A racing slot is the panel's own rectangle, drawn as a hit area: square, like every ENGO box. */
body[data-wd-page="layout"] .racing-slot { min-height: 0; padding: 0; border-radius: 0; }
body[data-wd-page="layout"] :is(.list-button, .page-add-options button) { border-radius: var(--wd-radius-control); }
body[data-wd-page="layout"] :is(input:not(.wd-switch), select) { border-radius: var(--wd-radius-control); }
body[data-wd-page="layout"] button:focus-visible,
body[data-wd-page="layout"] input:focus-visible,
body[data-wd-page="layout"] select:focus-visible { border-color: var(--wd-blue); }

@font-face {
  font-family: "EngoNumbers";
  src: url("/JetBrainsMono-ExtraBold.ttf") format("truetype");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "EngoText";
  src: url("/ChakraPetch-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "EngoText";
  src: url("/ChakraPetch-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: var(--wd-bg);
  --panel: var(--wd-surface);
  --panel-2: var(--wd-surface-raised);
  --line: var(--wd-border);
  --text: var(--wd-text);
  --muted: var(--wd-muted);
  --red: var(--wd-red);
  --teal: #1abc9c;
  --amber: var(--wd-caution);
  --blue: var(--wd-blue);
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

button, input, select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  font-size: .8125rem;
  font-weight: 500;
  cursor: pointer;
}

button:hover { border-color: var(--red); }
button.primary { background: var(--red); border-color: var(--red); }
button.small { min-height: 30px; padding: 0 9px; font-size: 13px; }
button.danger { color: #fecaca; border-color: #7f1d1d; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

input:not(.wd-switch), select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  background: #111318;
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
}

input[type="checkbox"]:not(.wd-switch) {
  width: 18px;
  min-height: 18px;
}

input[type="color"] {
  padding: 2px;
  height: 36px;
}

input:disabled:not(.wd-switch), select:disabled {
  color: #737b88;
  background: #17191e;
  border-color: #292d35;
  cursor: not-allowed;
  opacity: .72;
}

.app {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #0d0f12;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: 0;
}

.tabs, .actions, .cloud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cloud-actions {
  margin-left: 10px;
}

.tab {
  border-radius: 6px;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
  line-height: 1;
}

.tab.active {
  color: var(--text);
  border-color: var(--red);
  background: #2a171a;
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(360px, 1fr) 320px;
  min-height: 0;
}

.sidebar, .inspector {
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px;
}

.inspector {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,0.035) 1px, transparent 1px),
    #121419;
  background-size: 32px 32px;
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(16, 17, 19, 0.94);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.canvas-wrap {
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 28px;
}

.device-shell {
  background: #060708;
  box-shadow: 0 18px 50px var(--shadow);
  position: relative;
  flex: 0 0 auto;
}

.device-shell.round {
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 14px #050607, 0 18px 50px var(--shadow);
}

.device-shell.square {
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 0 0 14px #050607, 0 18px 50px var(--shadow);
}

.device-shell.engo {
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 0 12px #050607, 0 18px 50px var(--shadow);
}

.canvas {
  position: relative;
  background: #000;
  overflow: hidden;
  transform-origin: top left;
  backface-visibility: hidden;
}

.device-shell.round .canvas {
  border-radius: 50%;
  clip-path: circle(50% at 50% 50%);
}

.device-shell.square .canvas {
  border-radius: 28px;
}

.device-shell.engo .canvas {
  border-radius: 10px;
}

.safe-area {
  position: absolute;
  border: 1px dashed rgba(255,255,255,0.28);
  pointer-events: none;
}

.item {
  position: absolute;
  border: 1px solid rgba(255,255,255,0.32);
  background: rgba(32, 35, 42, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  user-select: none;
  touch-action: none;
  cursor: move;
  overflow: hidden;
}

.item.selected {
  border: 2px solid var(--red);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.28);
  z-index: 20;
}

.item .label {
  width: 100%;
  padding: 2px 4px;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gauge-helper {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.55);
  transform: translate(-50%, -50%);
  cursor: grab;
  z-index: 30;
  pointer-events: auto;
}

.gauge-helper.end {
  background: var(--teal);
}

.gauge-helper.width {
  width: 14px;
  height: 14px;
  background: var(--amber);
  cursor: ns-resize;
}

.item.engo-field {
  justify-content: flex-start;
  background: transparent;
  border-color: transparent;
  /* The panel draws letters in Chakra Petch; a value overrides to the
     numbers face below. */
  font-family: "EngoText", "Chakra Petch", "Arial Narrow", sans-serif;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

.item.engo-field.selected {
  border-color: var(--red);
  background: rgba(220, 38, 38, 0.08);
}

.engo-value {
  position: relative;
  width: 100%;
  height: 100%;
  white-space: nowrap;
  line-height: 1;
}

.engo-number {
  font-family: "EngoNumbers", "JetBrains Mono", monospace;
  font-weight: 800;
}

.engo-number {
  position: absolute;
  display: block;
  line-height: 1;
  overflow: hidden;
  text-align: right;
}

.engo-banner {
  background: #222;
  border: 1px solid #fff;
  outline: 1px solid #888;
  outline-offset: -3px;
  box-sizing: border-box;
}

.engo-banner-text {
  display: block;
  width: 100%;
  text-align: center;
  font-family: "EngoText", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: 26px;
}

.engo-varia-count {
  justify-content: center;
  text-align: center;
}

.engo-ghost {
  visibility: hidden;
}

.engo-nav-icon {
  position: absolute;
  object-fit: contain;
  image-rendering: pixelated;
  filter: grayscale(1);
  opacity: 0.95;
  transform: scale(-1, -1);
  mix-blend-mode: screen;
  pointer-events: none;
}

.engo-varia-icon {
  position: absolute;
  left: 12px;
  top: 38px;
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: grayscale(1);
  opacity: 0.95;
  transform: scale(-1, -1);
  mix-blend-mode: screen;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.55);
  touch-action: none;
  pointer-events: auto;
  z-index: 35;
}

.resize-handle.nw {
  left: -7px;
  top: -7px;
  cursor: nwse-resize;
}

.resize-handle.ne {
  right: -7px;
  top: -7px;
  cursor: nesw-resize;
}

.resize-handle.sw {
  left: -7px;
  bottom: -7px;
  cursor: nesw-resize;
}

.resize-handle.se {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
}

.gauge {
  border-radius: 50%;
  border: 10px solid var(--teal);
  background: radial-gradient(circle at center, #111 54%, transparent 55%);
}

.bar {
  justify-content: flex-start;
  padding: 4px;
}

.bar-fill {
  height: 100%;
  width: 65%;
  background: var(--teal);
  border-radius: 4px;
}

.section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}

.section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.section h2 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.stack { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row.compact > * { flex: 0 0 auto; }
/* On/off settings: label left, the shared .wd-switch right (as on the Account page). */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 10px; }
.switch-row label { color: var(--text); font-size: 13px; }
.wd-switch:disabled { opacity: .45; cursor: not-allowed; }

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 9px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
}

.list {
  display: grid;
  gap: 6px;
}

.list-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  min-height: 36px;
}

.page-list-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}
.page-list-row .list-button {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  overflow: hidden;
}
.page-name-wrap {
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: hidden;
}
.page-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.native-page-badge {
  flex: 0 0 auto;
  margin-left: 6px;
  padding: 2px 5px;
  color: #c3cad5;
  background: #2b3039;
  border: 1px solid #454c59;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .05em;
  line-height: 1.2;
  text-transform: uppercase;
}
/* On/off as a switch (board v5, no circles): the same crimson track as .wd-switch, drawn on a
   button so it keeps its click handler; aria-checked carries the state. */
.page-toggle {
  position: relative;
  flex: 0 0 46px;
  align-self: center;
  width: 46px;
  min-width: 46px;
  height: 26px;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--wd-border-control);
  border-radius: 6px;
  background: var(--wd-surface-raised);
}
.page-toggle::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: var(--wd-muted);
  transition: transform .18s ease, background-color .18s ease;
}
.page-toggle.page-on {
  border-color: var(--wd-red);
  background: var(--wd-red);
}
.page-toggle.page-on::before {
  transform: translateX(20px);
  background: #fff;
}
.page-delete {
  flex: 0 0 36px;
  min-width: 36px;
  padding: 0;
  color: #fecaca;
  border-color: #7f1d1d;
  font-size: 15px;
}

.list-button.active {
  border-color: var(--red);
  background: #2a171a;
}
.list-button[draggable="true"] { cursor: grab; }
.list-button.dragging { opacity: .45; cursor: grabbing; }
.list-button.drop-before { box-shadow: 0 -3px 0 var(--blue); }
.list-button.drop-after { box-shadow: 0 3px 0 var(--blue); }
.page-drag-handle {
  color: var(--muted);
  display: inline-block;
  margin: -8px 3px -8px -8px;
  padding: 8px;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.badge {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
}
.badge.page-on {
  color: #9ff3c5;
  border-color: #237a4b;
  background: rgba(35, 122, 75, .2);
}
.badge.page-off {
  color: #ffb4ac;
  border-color: #8f332d;
  background: rgba(143, 51, 45, .18);
}
.page-section-label {
  margin: 4px 2px 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.page-section-label.inactive {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.page-add-group {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.page-add-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.page-add-options {
  display: grid;
  gap: 6px;
}
.page-add-options button {
  width: 100%;
  min-height: 34px;
  text-align: left;
}
.page-add-options button strong { font-weight: inherit; }
.page-add-options button span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
  margin-top: 2px;
}
.page-add-hint {
  margin: 7px 1px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status {
  color: var(--muted);
  font-size: 13px;
  min-height: 20px;
}

.hidden { display: none !important; }

.publish-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.publish-modal {
  background: var(--wd-surface, #14161c);
  border: 1px solid var(--wd-border, #2a2f3a);
  border-radius: 14px;
  padding: 20px;
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.publish-modal h2 { margin: 0 0 4px; font-size: 18px; }
.publish-modal label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; opacity: .7; }
.publish-warning {
  font-size: 12px;
  line-height: 1.4;
  margin: 4px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 176, 32, .12);
  border: 1px solid rgba(255, 176, 32, .35);
}
.publish-error {
  font-size: 13px;
  margin: 4px 0 0;
  color: #ff6b6b;
}
.publish-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.publish-mine { margin-top: 14px; border-top: 1px solid var(--wd-border, #2a2f3a); padding-top: 12px; }
.publish-mine:empty { display: none; }
.publish-mine h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; opacity: .7; margin: 0 0 8px; }
.publish-mine__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
}
.publish-mine__meta { opacity: .6; font-size: 12px; }

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 240px minmax(320px, 1fr);
  }
  .inspector {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar, .inspector {
    border-left: 0;
    border-right: 0;
  }
  .main {
    min-height: 560px;
  }
}

