/*
  Input 10 — Inline Edit Input — standalone HTML/CSS/JS implementation.
  No build step, no framework, no external dependency: copy index.html,
  this file, and script.js into any project as-is.
*/

:root {
  --input-accent: #39ff14;
  --input-fg: oklch(0.145 0 0);
  --input-border: oklch(0.87 0 0);
  --input-muted: oklch(0.5 0 0);
  --input-strong: oklch(0.6 0.14 155);
  --input-error: oklch(0.58 0.19 20);
}

/* The `[data-inline-edit]` root and `.inline-edit` row both need
   `min-width: 0` so they can shrink below their content's natural size
   inside a narrow flex ancestor (e.g. a `justify-content: space-between`
   row) — otherwise the row overflows its container instead of letting
   the input give up its width, and `.inline-edit` additionally needs
   `max-width: 100%` since it's an ordinary inline-level box, not a flex
   item, so nothing else would ever constrain its width in the first
   place. */
[data-inline-edit] {
  font-family:
    Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  min-width: 0;
}

.inline-edit {
  display: inline-flex;
  max-width: 100%;
  min-width: 0;
  align-items: center;
  gap: 0.375rem;
  animation: inline-edit-fade 150ms ease-out;
}

/* Each face is a flex row in its own right (text+button, or
   input+save+cancel) — without this, the browser lays out an unstyled
   `<span>`'s children using ordinary inline flow, which can wrap onto a
   second line inside a constrained flex ancestor instead of always
   staying on one line. */
.inline-edit__face {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 0.375rem;
}

/* An author-origin `display` rule on the same element always beats the
   UA stylesheet's `[hidden] { display: none }`, regardless of
   specificity — so the hidden face must be re-declared explicitly here,
   or both faces render at once. */
.inline-edit__face[hidden] {
  display: none;
}

@keyframes inline-edit-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.inline-edit__value {
  font-family:
    Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji",
    "Segoe UI Emoji";
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--input-fg);
}

.inline-edit__icon-button {
  display: flex;
  width: 1.75rem;
  height: 1.75rem;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0.375rem;
  background: none;
  color: var(--input-muted);
  opacity: 0.6;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, opacity 150ms ease;
}

.inline-edit:hover .inline-edit__icon-button,
.inline-edit__icon-button:focus-visible {
  opacity: 1;
}

.inline-edit__icon-button:hover {
  background-color: rgba(0, 0, 0, 0.05);
  color: var(--input-fg);
}

.inline-edit__icon-button:focus-visible {
  outline: 2px solid var(--input-accent);
  outline-offset: 1px;
}

.inline-edit__icon-button svg {
  width: 0.875rem;
  height: 0.875rem;
}

.inline-edit__input {
  height: 2.25rem;
  min-width: 0;
  flex: 1 1 auto;
  border-radius: 0.375rem;
  border: 1px solid var(--input-border);
  background-color: #ffffff;
  padding: 0 0.625rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--input-fg);
  outline: none;
}

.inline-edit__input:focus-visible {
  border-color: var(--input-fg);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--input-accent) 40%, transparent);
}

.inline-edit__input[aria-invalid="true"] {
  border-color: var(--input-error);
}

.inline-edit__input[aria-invalid="true"]:focus-visible {
  border-color: var(--input-error);
}

.inline-edit__message {
  margin: 0.375rem 0 0;
  font-size: 0.875rem;
  color: var(--input-error);
}

.inline-edit__save {
  color: var(--input-strong);
}

.inline-edit__cancel:hover {
  color: var(--input-error);
}

@media (prefers-reduced-motion: reduce) {
  .inline-edit {
    animation: none;
  }
}

/*
  Page layout — the canvas this resource is presented on. Adjust or drop it
  when placing the resource inside your own layout.
*/

body {
  margin: 0;
  font-family:
    Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(to bottom, #fafafa, #f4f4f5);
}
.input10-layout {
  display: flex;
  min-height: 20rem;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.input10-layout__panel {
  display: flex;
  width: 100%;
  max-width: 420px;
  flex-direction: column;
  gap: 0.75rem;
  border-radius: 1rem;
  border: 1px solid rgba(0, 0, 0, 0.05);
  background-color: #ffffff;
  padding: 1.5rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 16px 40px -16px rgba(0, 0, 0, 0.14);
}
.input10-layout__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.input10-layout__row + .input10-layout__row {
  border-top: 1px solid #e5e5e5;
  padding-top: 0.75rem;
}
.input10-layout__label {
  font-size: 0.75rem;
  color: #737373;
}
