/* ==========================================================================
   WAT builder chrome. Deliberately namespaced away from the generated site
   styles (which all live under .wat-site) so the canvas renders exactly what
   the export will.
   ========================================================================== */

:root {
  --ui-bg: #0f1420;
  --ui-panel: #161d2c;
  --ui-panel-2: #1d2637;
  --ui-line: #27314408;
  --ui-border: #273144;
  --ui-text: #e6ebf5;
  --ui-muted: #8b98ae;
  --ui-accent: #5b8cff;
  --ui-accent-soft: #5b8cff22;
  --ui-danger: #f2555a;
  --ui-ok: #34d399;
  --ui-warn: #fbbf24;
  --ui-radius: 10px;
  --ui-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --ui-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--ui-font);
  background: var(--ui-bg);
  color: var(--ui-text);
  overflow: hidden;
}

button { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-rows: 56px 1fr 34px;
  height: 100vh;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-border);
}

.topbar__brand { display: flex; align-items: baseline; gap: 8px; flex: none; }
.topbar__mark {
  font-weight: 800;
  letter-spacing: .08em;
  font-size: 1.05rem;
  background: linear-gradient(120deg, #5b8cff, #9d7bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.topbar__sub { font-size: .78rem; color: var(--ui-muted); }

.topbar__steps { display: flex; align-items: center; gap: 2px; }
.wat-steps__sep { color: var(--ui-muted); opacity: .5; }

.wat-step2 {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  color: var(--ui-muted);
  font-size: .87rem;
}
.wat-step2:hover:not(.is-blocked) { background: var(--ui-panel-2); color: var(--ui-text); }
.wat-step2.is-active { background: var(--ui-accent-soft); color: #cfe0ff; }
.wat-step2.is-done { color: var(--ui-text); }
.wat-step2.is-blocked { opacity: .4; cursor: not-allowed; }
.wat-step2__num {
  display: grid;
  place-items: center;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: var(--ui-panel-2);
  font-size: .7rem; font-weight: 700;
}
.wat-step2.is-active .wat-step2__num { background: var(--ui-accent); color: #fff; }
.wat-step2.is-done .wat-step2__num { background: var(--ui-ok); color: #06281c; }

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.wat-group {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--ui-panel-2);
  border-radius: 8px;
}

.wat-saved { font-size: .74rem; color: var(--ui-ok); min-width: 34px; }

.wat-iconbtn {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border: 0; border-radius: 7px;
  background: transparent;
  color: var(--ui-muted);
  cursor: pointer;
}
.wat-iconbtn:hover:not(:disabled) { background: var(--ui-border); color: var(--ui-text); }
.wat-iconbtn.is-active { background: var(--ui-accent); color: #fff; }
.wat-iconbtn:disabled { opacity: .3; cursor: default; }
.wat-iconbtn--danger:hover:not(:disabled) { background: var(--ui-danger); color: #fff; }

.wat-btn2 {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  background: var(--ui-panel-2);
  color: var(--ui-text);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
}
.wat-btn2:hover { border-color: var(--ui-accent); }
.wat-btn2.is-active { background: var(--ui-accent-soft); border-color: var(--ui-accent); }
.wat-btn2--primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #fff; }
.wat-btn2--primary:hover { filter: brightness(1.08); }
.wat-btn2--danger { color: var(--ui-danger); }
.wat-btn2--danger:hover { background: var(--ui-danger); color: #fff; border-color: var(--ui-danger); }

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

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

.panel {
  background: var(--ui-panel);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.panel--left { border-right: 1px solid var(--ui-border); }
.panel--right { border-left: 1px solid var(--ui-border); }

.wat-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 2px;
  padding: 10px 12px 0;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-border);
}
.wat-tab {
  flex: 1;
  padding: 8px 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ui-muted);
  font-size: .84rem;
  cursor: pointer;
}
.wat-tab:hover { color: var(--ui-text); }
.wat-tab.is-active { color: var(--ui-text); border-bottom-color: var(--ui-accent); }

.wat-panel { padding: 14px; display: grid; gap: 12px; align-content: start; }
.wat-panel__head h2 { margin: 0 0 4px; font-size: .98rem; }
.wat-panel__head p { margin: 0; font-size: .78rem; color: var(--ui-muted); line-height: 1.5; }
.wat-panel__actions { display: flex; gap: 8px; margin-top: 6px; }
.wat-panel__actions .wat-btn2 { flex: 1; justify-content: center; }

.wat-grouphead {
  margin: 8px 0 0;
  font-size: .7rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ui-muted);
}

.wat-hint { margin: 4px 0 0; font-size: .76rem; color: var(--ui-muted); line-height: 1.5; }

.wat-search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  background: var(--ui-bg);
  color: var(--ui-text);
  font-size: .85rem;
}
.wat-search:focus { outline: none; border-color: var(--ui-accent); }

/* ---------------------------------------------------------- block palette */

.wat-blocklist { display: grid; gap: 6px; margin-top: 6px; }

.wat-blockcard {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--ui-panel-2);
  cursor: grab;
}
.wat-blockcard:hover { border-color: var(--ui-accent); background: var(--ui-accent-soft); }
.wat-blockcard:active { cursor: grabbing; }
.wat-blockcard__icon {
  display: grid; place-items: center;
  flex: none; width: 32px; height: 32px;
  border-radius: 7px;
  background: var(--ui-bg);
  color: var(--ui-accent);
}
.wat-blockcard__text { display: grid; gap: 2px; min-width: 0; }
.wat-blockcard__text strong { font-size: .84rem; font-weight: 600; }
.wat-blockcard__text em {
  font-style: normal;
  font-size: .72rem;
  color: var(--ui-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* -------------------------------------------------------------- templates */

.wat-templates { display: grid; gap: 10px; }
.wat-template {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  background: var(--ui-panel-2);
  cursor: pointer;
  text-align: left;
}
.wat-template:hover { border-color: var(--ui-accent); }
.wat-template.is-active { border-color: var(--ui-accent); background: var(--ui-accent-soft); }
.wat-template__swatch { flex: none; width: 46px; height: 46px; border-radius: 8px; }
.wat-template__body { display: grid; gap: 3px; }
.wat-template__body strong { font-size: .86rem; }
.wat-template__body em { font-style: normal; font-size: .73rem; color: var(--ui-muted); line-height: 1.4; }

/* ----------------------------------------------------------------- layers */

.wat-layers { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.wat-layer {
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--ui-panel-2);
}
.wat-layer.is-active { border-color: var(--ui-accent); background: var(--ui-accent-soft); }
.wat-layer__main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: .82rem;
  text-align: left;
  min-width: 0;
}
.wat-layer__main svg { color: var(--ui-muted); flex: none; }
.wat-layer__main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wat-layer__tools { display: flex; padding-right: 4px; opacity: 0; }
.wat-layer:hover .wat-layer__tools, .wat-layer.is-active .wat-layer__tools { opacity: 1; }
.wat-layer__tools button {
  display: grid; place-items: center;
  width: 24px; height: 24px;
  border: 0; border-radius: 5px;
  background: none; color: var(--ui-muted); cursor: pointer;
}
.wat-layer__tools button:hover:not(:disabled) { background: var(--ui-border); color: var(--ui-text); }
.wat-layer__tools button:disabled { opacity: .25; cursor: default; }

/* ------------------------------------------------------------------ stage */

.stage {
  overflow: auto;
  padding: 28px;
  background:
    radial-gradient(circle at 1px 1px, #ffffff10 1px, transparent 0) 0 0 / 22px 22px,
    var(--ui-bg);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.stage__frame {
  position: relative;
  width: 100%;
  min-height: 100%;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, .8);
  transition: max-width .22s ease;
  overflow: hidden;
}
.stage__frame.is-drop-target { outline: 2px dashed var(--ui-accent); outline-offset: 3px; }

.wat-preview-frame { display: block; width: 100%; height: calc(100vh - 150px); border: 0; }

/* Editing affordances live only on the canvas, never in the export. */
#wat-canvas-root [data-wat-id] {
  position: relative;
  outline: 1.5px solid transparent;
  outline-offset: -1.5px;
  transition: outline-color .12s ease;
  cursor: grab;
}
#wat-canvas-root [data-wat-id]:hover { outline-color: #5b8cff66; }
#wat-canvas-root [data-wat-id].is-selected { outline-color: var(--ui-accent); }
#wat-canvas-root [data-wat-id].is-dragging { opacity: .4; }
#wat-canvas-root [data-wat-field][contenteditable="true"] {
  outline: 1px dashed #5b8cff88;
  outline-offset: 2px;
  cursor: text;
}
#wat-canvas-root [data-wat-field][contenteditable="true"]:focus {
  outline: 2px solid var(--ui-accent);
}
body.is-dragging #wat-canvas-root [data-wat-id] { pointer-events: auto; }

.wat-nodebar {
  position: absolute;
  right: 10px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 4px 4px 10px;
  background: var(--ui-panel);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 8px 20px -8px rgba(0,0,0,.6);
  transform: translateY(-50%);
  margin-top: 14px;
}
.wat-nodebar[hidden] { display: none; }
.wat-nodebar__label { font-size: .74rem; color: var(--ui-muted); margin-right: 6px; }
.wat-nodebar button {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border: 0; border-radius: 5px;
  background: none; color: var(--ui-muted); cursor: pointer;
}
.wat-nodebar button:hover { background: var(--ui-border); color: var(--ui-text); }
.wat-nodebar button:last-child:hover { background: var(--ui-danger); color: #fff; }

.wat-dropline {
  position: absolute;
  left: 0; right: 0;
  height: 3px;
  background: var(--ui-accent);
  box-shadow: 0 0 0 3px var(--ui-accent-soft);
  border-radius: 3px;
  z-index: 30;
  pointer-events: none;
}
.wat-dropline[hidden] { display: none; }

.wat-empty {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 60vh;
  padding: 40px;
  text-align: center;
  color: #64748b;
}
.wat-empty__icon {
  display: grid; place-items: center;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 2px dashed #cbd5e1;
  color: #94a3b8;
}
.wat-empty h2 { margin: 0; font-size: 1.1rem; color: #334155; }
.wat-empty p { margin: 0; font-size: .88rem; max-width: 32em; }

/* --------------------------------------------------------------- inspector */

.wat-f { display: grid; gap: 6px; }
.wat-f__label { font-size: .78rem; font-weight: 600; color: var(--ui-text); }
.wat-f__label--row { display: flex; justify-content: space-between; align-items: center; }
.wat-f__label--row output { font-weight: 500; color: var(--ui-muted); font-variant-numeric: tabular-nums; }
.wat-f__help { font-style: normal; font-size: .72rem; color: var(--ui-muted); line-height: 1.45; }

.wat-f input[type="text"],
.wat-f input[type="url"],
.wat-f input[type="number"],
.wat-f textarea,
.wat-f select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--ui-border);
  border-radius: 7px;
  background: var(--ui-bg);
  color: var(--ui-text);
  font: inherit;
  font-size: .82rem;
}
.wat-f textarea { resize: vertical; line-height: 1.5; }
.wat-f input:focus, .wat-f textarea:focus, .wat-f select:focus {
  outline: none;
  border-color: var(--ui-accent);
}
.wat-f input[type="range"] { width: 100%; accent-color: var(--ui-accent); }
.wat-f__thumb {
  width: 100%; height: 84px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--ui-border);
}

.wat-f--toggle {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  background: var(--ui-panel-2);
  border-radius: 7px;
  cursor: pointer;
}
.wat-f--toggle input { accent-color: var(--ui-accent); width: 15px; height: 15px; }

.wat-f--color { grid-template-columns: 1fr auto; align-items: center; }
.wat-f__colorwrap { display: flex; gap: 6px; align-items: center; }
.wat-f__colorwrap input[type="color"] {
  width: 30px; height: 30px;
  padding: 0;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.wat-f__hex {
  width: 84px;
  padding: 6px 8px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: var(--ui-bg);
  color: var(--ui-muted);
  font-family: var(--ui-mono);
  font-size: .72rem;
}

.wat-placeholder {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 48px 20px;
  text-align: center;
  color: var(--ui-muted);
}
.wat-placeholder p { margin: 0; font-size: .82rem; line-height: 1.5; }

/* ------------------------------------------------------------ list fields */

.wat-list { display: grid; gap: 6px; }
.wat-list__head { display: flex; align-items: center; justify-content: space-between; }

.wat-item { border: 1px solid var(--ui-border); border-radius: 8px; overflow: hidden; }
.wat-item.is-open { border-color: var(--ui-accent); }
.wat-item__head { display: flex; align-items: center; background: var(--ui-panel-2); }
.wat-item__toggle {
  flex: 1;
  padding: 8px 10px;
  border: 0;
  background: none;
  color: var(--ui-text);
  font-size: .79rem;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wat-item__head .wat-iconbtn { width: 24px; height: 24px; }
.wat-item__body { display: grid; gap: 10px; padding: 12px 10px; background: var(--ui-bg); }

/* ------------------------------------------------------------- status bar */

.statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--ui-panel);
  border-top: 1px solid var(--ui-border);
  position: relative;
}

.wat-status__toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: .75rem;
  cursor: pointer;
}
.wat-status__toggle.is-ok { color: var(--ui-ok); }
.wat-status__toggle.is-warn { color: var(--ui-warn); }
.wat-status__toggle.is-error { color: var(--ui-danger); }
.wat-status__toggle:hover { background: var(--ui-panel-2); }

.wat-status__list {
  position: absolute;
  bottom: 100%;
  left: 10px;
  right: 10px;
  max-width: 640px;
  margin: 0 0 8px;
  padding: 10px 12px;
  list-style: none;
  display: grid;
  gap: 7px;
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  border-radius: 9px;
  box-shadow: 0 16px 40px -18px rgba(0,0,0,.8);
}
.wat-status__list li { display: flex; gap: 9px; align-items: flex-start; font-size: .78rem; color: var(--ui-muted); }
.wat-status__dot { flex: none; width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; }
.wat-status__list li.is-error .wat-status__dot { background: var(--ui-danger); }
.wat-status__list li.is-warn .wat-status__dot { background: var(--ui-warn); }
.wat-status__list li.is-info .wat-status__dot { background: var(--ui-accent); }

/* ------------------------------------------------------------ export modal */

.wat-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 32px;
  background: rgba(6, 10, 18, .78);
  backdrop-filter: blur(3px);
}

.wat-modal {
  width: min(1000px, 100%);
  max-height: 88vh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background: var(--ui-panel);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  overflow: hidden;
}
.wat-modal__head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--ui-border);
}
.wat-modal__head h2 { margin: 0 0 4px; font-size: 1.05rem; }
.wat-modal__head p { margin: 0; font-size: .8rem; color: var(--ui-muted); }
.wat-modal__head .wat-iconbtn { margin-left: auto; }
.wat-modal__tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--ui-border); }
.wat-modal__tabs .wat-tab { flex: none; padding: 10px 14px; font-family: var(--ui-mono); font-size: .78rem; }
.wat-modal__meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 20px;
  font-size: .75rem;
  color: var(--ui-muted);
  background: var(--ui-panel-2);
}
.wat-modal__size { font-family: var(--ui-mono); }
.wat-modal__foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--ui-border);
}

.wat-code {
  margin: 0;
  padding: 18px 20px;
  overflow: auto;
  background: #0b1018;
  font-family: var(--ui-mono);
  font-size: .76rem;
  line-height: 1.65;
  tab-size: 2;
}
.wat-code code { color: #c8d3e6; white-space: pre; }
.tok-t { color: #7dd3fc; }
.tok-a { color: #c4b5fd; }
.tok-s { color: #86efac; }
.tok-k { color: #f0abfc; }
.tok-c { color: #64748b; font-style: italic; }

/* ----------------------------------------------------------------- toasts */

.wat-toasts {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
}
.wat-toast {
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  font-size: .82rem;
  box-shadow: 0 12px 30px -12px rgba(0,0,0,.8);
  animation: watRise .22s ease;
}
.wat-toast--warn { border-color: var(--ui-warn); color: var(--ui-warn); }
.wat-toast--ok { border-color: var(--ui-ok); color: var(--ui-ok); }
.wat-toast.is-leaving { opacity: 0; transition: opacity .3s ease; }

@keyframes watRise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------- narrower */

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 240px minmax(0, 1fr) 280px; }
  .topbar__sub { display: none; }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .panel { display: none; }
}
