/* The Well — field editor (write plane). A right-side slide-over over a dim
 * scrim, above the reading panel. Same vocabulary as css/panel.css: deep-water
 * surfaces, container --hue accents, serif titles, system-sans UI, the --glide
 * / --settle easings. See apps/well/DESIGN.md. */

/* ================================================================== */
/* Overlay + scrim + slide-over                                        */
/* ================================================================== */

.ed-overlay {
  position: fixed;
  inset: 0;
  z-index: 200; /* above panel (40) and peek cards (60) */
}

.ed-scrim {
  position: absolute;
  inset: 0;
  background: rgba(7, 12, 22, 0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--t-local) var(--glide);
}
.ed-overlay.is-shown .ed-scrim {
  opacity: 1;
}

.ed-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(560px, 92vw);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 90%, var(--hue)) 0%, var(--surface) 140px);
  border-left: 1px solid var(--border);
  box-shadow: -40px 0 80px -30px rgba(0, 0, 0, 0.65);
  transform: translateX(24px);
  opacity: 0;
  transition: transform var(--t-local) var(--glide), opacity var(--t-local) var(--glide);
}
.ed-overlay.is-shown .ed-panel {
  transform: none;
  opacity: 1;
}

/* ================================================================== */
/* Header                                                              */
/* ================================================================== */

.ed-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 22px clamp(20px, 3.5vw, 34px) 18px;
  border-bottom: 1px solid var(--border);
}
.ed-head-main {
  flex: 1 1 auto;
  min-width: 0;
}
.ed-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.ed-hue-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hue, var(--text-3));
  box-shadow: 0 0 10px color-mix(in srgb, var(--hue, #8a93a6) 60%, transparent);
  flex: none;
}
.ed-titlerow {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.ed-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  line-height: 1.25;
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}
.ed-close {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 15px;
  cursor: pointer;
  transition: color 120ms var(--glide), border-color 120ms var(--glide), background 120ms var(--glide);
}
.ed-close:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--hue) 45%, var(--border));
  background: color-mix(in srgb, var(--hue) 8%, transparent);
}

/* ================================================================== */
/* Body                                                                */
/* ================================================================== */

.ed-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px clamp(20px, 3.5vw, 34px) 32px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.ed-body::-webkit-scrollbar {
  width: 10px;
}
.ed-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

.ed-hint {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-3);
  margin-bottom: 20px;
}
.ed-loading {
  color: var(--text-2);
  font-size: 14px;
  padding: 24px 0;
}

/* banners (lock / warn) */
.ed-banner {
  padding: 14px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.55;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  color: var(--text-2);
}
.ed-banner--lock {
  background: color-mix(in srgb, var(--vision) 9%, transparent);
  border-color: color-mix(in srgb, var(--vision) 30%, transparent);
  color: var(--text);
}
.ed-banner--warn {
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  border-color: color-mix(in srgb, var(--warn) 32%, transparent);
  color: var(--text);
}

/* ================================================================== */
/* Field blocks                                                        */
/* ================================================================== */

.ed-field,
.ed-connections {
  margin: 0 0 22px;
}
.ed-field-label,
.ed-pill-label {
  display: block;
  margin-bottom: 8px;
  color: var(--hue);
  opacity: 0.85;
}

/* text inputs + textareas */
.ed-input,
.ed-textarea,
.ed-select {
  width: 100%;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  transition: border-color 120ms var(--glide), box-shadow 120ms var(--glide);
}
.ed-textarea {
  resize: vertical;
  line-height: 1.55;
}
.ed-mono {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}
.ed-input:focus,
.ed-textarea:focus,
.ed-select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--hue) 60%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hue) 18%, transparent);
}
.ed-input:disabled,
.ed-textarea:disabled,
.ed-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.ed-input::placeholder,
.ed-textarea::placeholder {
  color: var(--text-3);
}

/* enum pills */
.ed-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 24px;
}
.ed-pill {
  flex: 1 1 160px;
  min-width: 140px;
}
.ed-select {
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}
.ed-select option {
  background: var(--surface);
  color: var(--text);
}

/* list-kind editor */
.ed-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ed-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ed-list-item .ed-input {
  flex: 1 1 auto;
}

/* options editor */
.ed-opts {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ed-opt {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface-2) 45%, transparent);
}
.ed-opt-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.ed-opt-top .ed-opt-name {
  flex: 1 1 auto;
  font-weight: 600;
}

/* row controls (up / down / delete) */
.ed-rowbtns {
  display: inline-flex;
  gap: 4px;
  flex: none;
}
.ed-iconbtn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: color 120ms var(--glide), border-color 120ms var(--glide), background 120ms var(--glide);
}
.ed-iconbtn:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--hue) 40%, var(--border));
  background: color-mix(in srgb, var(--hue) 8%, transparent);
}
.ed-iconbtn.ed-del:hover {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 40%, var(--border));
  background: color-mix(in srgb, var(--warn) 9%, transparent);
}
.ed-iconbtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ed-addbtn {
  margin-top: 10px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px dashed color-mix(in srgb, var(--hue) 40%, var(--border));
  background: transparent;
  color: var(--hue);
  font-family: var(--sans);
  font-size: 12.5px;
  cursor: pointer;
  transition: background 120ms var(--glide), border-color 120ms var(--glide);
}
.ed-addbtn:hover {
  background: color-mix(in srgb, var(--hue) 10%, transparent);
  border-style: solid;
}

/* bool toggle */
.ed-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.ed-checkbox {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.ed-toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 160ms var(--glide), border-color 160ms var(--glide);
  flex: none;
}
.ed-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform 160ms var(--settle), background 160ms var(--glide);
}
.ed-checkbox:checked + .ed-toggle-track {
  background: color-mix(in srgb, var(--hue) 30%, transparent);
  border-color: color-mix(in srgb, var(--hue) 50%, var(--border));
}
.ed-checkbox:checked + .ed-toggle-track .ed-toggle-thumb {
  transform: translateX(18px);
  background: var(--hue);
}
.ed-checkbox:focus-visible + .ed-toggle-track {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hue) 22%, transparent);
}
.ed-checkbox:disabled + .ed-toggle-track {
  opacity: 0.5;
  cursor: not-allowed;
}
.ed-toggle-text {
  font-size: 13px;
  color: var(--text-2);
}

.ed-date {
  width: auto;
  min-width: 170px;
  color-scheme: dark;
}

.ed-json-note {
  margin-top: 6px;
  color: var(--text-3);
}

/* ================================================================== */
/* Connections editor                                                  */
/* ================================================================== */

.ed-connections {
  margin-top: 30px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.ed-conn-group {
  margin-bottom: 12px;
}
.ed-conn-verb {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 6px;
}
.ed-conn-item {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 5px 9px;
  margin: 0 6px 6px 0;
  border-radius: 8px;
  background: color-mix(in srgb, var(--hue) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--hue) 18%, transparent);
  max-width: 100%;
}
.ed-conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hue);
  flex: none;
}
.ed-conn-title {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}
.ed-conn-empty {
  color: var(--text-3);
  font-size: 13px;
}

/* remove affordance on a real links-table connection */
.ed-conn-remove {
  flex: none;
  margin-left: 2px;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.55;
  transition: color 120ms var(--glide), background 120ms var(--glide), opacity 120ms var(--glide);
}
.ed-conn-remove:hover {
  opacity: 1;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
}
.ed-conn-remove:disabled {
  opacity: 0.3;
  cursor: default;
}

.ed-conn-add {
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-2) 45%, transparent);
  border: 1px solid var(--border);
}
.ed-conn-add-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.ed-conn-add-row .ed-linkrel {
  flex: 1 1 160px;
}
.ed-conn-add-row .ed-linksearch {
  flex: 2 1 200px;
}
.ed-linkresults {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}
.ed-linkresult {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--glide);
}
.ed-linkresult:hover {
  background: color-mix(in srgb, var(--hue) 12%, transparent);
}
.ed-linkresult--empty {
  color: var(--text-3);
  font-size: 12.5px;
  cursor: default;
}
.ed-linkresult-title {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-linkselected {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.ed-linkselected-label {
  color: var(--text-3);
}
.ed-conn-add-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}
.ed-link-msg {
  flex: 1 1 auto;
  min-width: 0;
}

/* ================================================================== */
/* Create flow — type picker + required lead controls                  */
/* ================================================================== */

.ed-typegrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 4px;
}
.ed-typecard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 13px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 45%, transparent);
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms var(--glide), background 120ms var(--glide), transform 120ms var(--settle);
}
.ed-typecard:hover {
  border-color: color-mix(in srgb, var(--hue) 50%, var(--border));
  background: color-mix(in srgb, var(--hue) 9%, transparent);
  transform: translateY(-1px);
}
.ed-typecard-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.ed-typecard-cont {
  color: var(--hue);
  opacity: 0.8;
}

/* "required" tag on a create field label */
.ed-req {
  margin-left: 6px;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--text-3);
  opacity: 0.8;
}

/* ================================================================== */
/* Footer                                                              */
/* ================================================================== */

.ed-foot {
  flex: none;
  border-top: 1px solid var(--border);
  padding: 14px clamp(20px, 3.5vw, 34px) 16px;
  background: color-mix(in srgb, var(--surface) 88%, var(--bg-deep));
}
.ed-foot-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ed-foot-row--single {
  justify-content: flex-end;
}
.ed-foot-row .ed-reason {
  flex: 1 1 auto;
}
.ed-foot-btns {
  display: inline-flex;
  gap: 8px;
  flex: none;
}
.ed-foot-msg {
  margin-bottom: 10px;
}
.ed-foot-msg:empty {
  margin-bottom: 0;
}

/* buttons */
.ed-btn {
  font-family: var(--sans);
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 120ms var(--glide), border-color 120ms var(--glide), color 120ms var(--glide), opacity 120ms var(--glide);
}
.ed-btn-sm {
  padding: 7px 13px;
  font-size: 12.5px;
}
.ed-btn-ghost {
  background: transparent;
  color: var(--text-2);
}
.ed-btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-3);
}
.ed-btn-primary {
  background: color-mix(in srgb, var(--hue) 20%, transparent);
  border-color: color-mix(in srgb, var(--hue) 45%, transparent);
  color: var(--hue);
  font-weight: 600;
}
.ed-btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--hue) 30%, transparent);
  border-color: color-mix(in srgb, var(--hue) 60%, transparent);
}
.ed-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* inline error */
.ed-error {
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 32%, transparent);
  overflow-wrap: anywhere;
}

/* ================================================================== */
/* Token step                                                          */
/* ================================================================== */

.ed-token {
  padding: 8px 0;
}
.ed-token-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}
.ed-token-note {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-2);
  margin: 0 0 16px;
}
.ed-token-input {
  margin-bottom: 12px;
}

/* ================================================================== */
/* Toast                                                               */
/* ================================================================== */

.ed-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  z-index: 210;
  max-width: min(440px, 90vw);
  padding: 12px 18px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.6);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  transition: opacity 240ms var(--glide), transform 240ms var(--settle);
}
.ed-toast.is-vis {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 620px) {
  .ed-foot-row {
    flex-wrap: wrap;
  }
  .ed-foot-btns {
    width: 100%;
    justify-content: flex-end;
  }
}

/* ---- files (upload / replace) ------------------------------------- */

.ed-file-current {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--hue, var(--files)) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--hue, var(--files)) 22%, var(--border));
}
.ed-file-current-name {
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
}
.ed-file-current-meta { margin-top: 3px; }

.ed-file-field .ed-file-input {
  display: block;
  width: 100%;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-2);
}
.ed-file-field .ed-file-input::file-selector-button {
  margin-right: 12px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--hue, var(--files)) 40%, var(--border));
  background: color-mix(in srgb, var(--hue, var(--files)) 10%, transparent);
  color: var(--hue, var(--files));
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-micro) var(--glide);
}
.ed-file-field .ed-file-input::file-selector-button:hover {
  background: color-mix(in srgb, var(--hue, var(--files)) 18%, transparent);
}
.ed-file-pick {
  margin-top: 8px;
  color: var(--text-2);
  word-break: break-word;
}
