:root {
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #0f172a;
  background: #e2e8f0;
}

body {
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
}

.controls {
  padding: 24px;
  background: #f8fafc;
  border-right: 1px solid #cbd5f5;
  min-width: 360px;
}

.controls h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

.pattern-section + .pattern-section {
  margin-top: 32px;
}

.pattern-picker {
  margin-bottom: 16px;
}

.pattern-picker label {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.pattern-picker select {
  font-size: 1rem;
  padding: 6px 8px;
  border: 1px solid #cbd5f5;
  border-radius: 4px;
  background: #fff;
}

.pattern-picker select.pattern-picker__native {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.pattern-dropdown {
  position: relative;
  width: 100%;
  margin-top: 4px;
}

.pattern-dropdown__toggle {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #2563eb;
  background: #2563eb;
  padding: 14px 48px 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.pattern-dropdown__toggle::after {
  content: "";
  position: absolute;
  right: 22px;
  width: 12px;
  height: 8px;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%23ffffff' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  transition: transform 0.2s ease;
}

.pattern-dropdown.is-open .pattern-dropdown__toggle::after {
  transform: rotate(180deg);
}

.pattern-dropdown__toggle:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.pattern-dropdown__menu {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  padding: 12px;
  display: none;
  max-height: 360px;
  overflow-y: auto;
  z-index: 20;
}

.pattern-dropdown.is-open .pattern-dropdown__menu {
  display: block;
}

.pattern-dropdown__group + .pattern-dropdown__group {
  border-top: 1px solid rgba(148, 163, 184, 0.25);
  margin-top: 8px;
  padding-top: 12px;
}

.pattern-dropdown__group-title {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #94a3b8;
  margin: 0 0 6px;
}

.pattern-dropdown__option {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  background: transparent;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 500;
  color: #0f172a;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.pattern-dropdown__option:not(:disabled):hover {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.pattern-dropdown__option.is-selected {
  background: #dbeafe;
  border-color: #93c5fd;
}

.pattern-dropdown__option:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.beta-tag {
  font-size: 0.8rem;
  font-weight: 600;
  color: #b45309;
  background: #fef3c7;
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: 8px;
  text-transform: uppercase;
}

.hint {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: #475569;
}

.note {
  margin: 0 0 16px;
  font-size: 0.9rem;
}

.note a {
  color: #0f62fe;
  text-decoration: underline;
}

.pattern-placeholder {
  padding: 24px;
  border: 1px dashed #cbd5f5;
  border-radius: 4px;
  background: #fff;
  font-size: 0.95rem;
  color: #475569;
}

.hof-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hof-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hof-card {
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

.hof-card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: #0f172a;
}

.hof-card h2 + .form-grid,
.hof-card h2 + p {
  margin-top: 0;
}

.hof-card h2 {
  margin-top: 24px;
}

.hof-card h2:first-child {
  margin-top: 0;
}

.hof-fit-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.hof-card-subtitle {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hof-fit-control__select {
  position: relative;
}

.hof-fit-control__select select {
  width: 100%;
  padding: 6px 28px 6px 10px;
  border: 1px solid #cbd5f5;
  border-radius: 4px;
  background: #fff;
  font-size: 0.95rem;
  font-weight: 500;
  color: #0f172a;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
}

.hof-fit-control__select select:focus {
  border-color: #8bb4ff;
  box-shadow: 0 0 0 3px rgba(139, 180, 255, 0.2);
  outline: none;
}

.hof-fit-control__select select:hover {
  border-color: #b6c7f0;
}

.hof-fit-control__select select option {
  padding: 10px 12px;
  font-size: 0.95rem;
  font-weight: 500;
  color: #0f172a;
}

.hofenbitzer-measure-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0 10px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.measure-block {
  padding: 4px 0;
  border-bottom: none;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.measure-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  column-gap: 16px;
  row-gap: 6px;
  margin-bottom: 6px;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 0;
}

.form-label {
  font-size: 14px;
  font-weight: 600;
  color: #2e3440;
  line-height: 1.2;
  min-width: 0;
  box-sizing: border-box;
}

.form-input {
  font-size: 14px;
  height: 32px;
  padding: 6px 8px;
  border: 1px solid #d0d7e2;
  border-radius: 6px;
  background: #fff;
  outline: none;
  box-shadow: none;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus {
  border-color: #8bb4ff;
  box-shadow: 0 0 0 3px rgba(139, 180, 255, 0.25);
}

.form-input[readonly] {
  background: #fff;
}

.form-input.final {
  font-weight: 700;
  background: #f1f5ff;
  border-color: #c7dbff;
}

.measure-row input,
.measure-row .form-input {
  border-radius: 6px;
  height: 32px;
  font-size: 14px;
}


@media (min-width: 600px) {
  .form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(160px, 1fr));
    gap: 12px;
  }
}

@media (max-width: 599px) {
  .form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.form-grid label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
  gap: 4px;
}

.derived-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 24px 0;
  padding: 16px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #f8fbff;
}

.derived-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.derived-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.derived-value {
  font-size: 1.15rem;
  font-weight: 600;
  color: #0f172a;
}

.derived-reset {
  margin-top: 12px;
}

.skirt-hint {
  margin-top: -4px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: #64748b;
}

input:not([type="checkbox"]),
select {
  width: 100%;
  max-width: 100%;
  height: 32px;
  padding: 6px 8px;
  font-size: 14px;
  border: 1px solid #cbd5f5;
  border-radius: 6px;
  background: #fff;
  box-sizing: border-box;
  min-width: 0;
}

input[type="checkbox"] {
  width: auto;
  height: auto;
  padding: 0;
  border: none;
  border-radius: 0;
}

.mini-dropdown {
  position: relative;
  width: 100%;
  margin-top: 4px;
}

.mini-dropdown__native {
  position: absolute !important;
  opacity: 0 !important;
  pointer-events: none !important;
  width: 0;
  height: 0;
}

.mini-dropdown__toggle {
  width: 100%;
  border-radius: 6px;
  border: 1px solid #cbd5f5;
  background-color: #fff;
  background-image: none;
  padding: 10px 36px 10px 10px;
  font-size: 1rem;
  font-weight: 500;
  color: #0f172a;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.mini-dropdown__toggle:hover {
  border-color: #94a3b8;
  background-color: #fff;
}

.mini-dropdown.is-open .mini-dropdown__toggle {
  border-color: #93c5fd;
  background-color: #fff;
}

.mini-dropdown__toggle::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 10px;
  height: 6px;
  margin-top: -3px;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.25 5 4.75 9 1.25' stroke='%2363748b' stroke-width='1.25' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  transition: transform 0.2s ease;
}

.mini-dropdown.is-open .mini-dropdown__toggle::after {
  transform: rotate(180deg);
}

.mini-dropdown__toggle:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.mini-dropdown__menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  display: none;
  z-index: 10;
}

.mini-dropdown.is-open .mini-dropdown__menu {
  display: block;
}

.mini-dropdown__option {
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 500;
  color: #0f172a;
  cursor: pointer;
}

.mini-dropdown__option:hover,
.mini-dropdown__option.is-selected {
  background: #eff6ff;
  color: #1d4ed8;
}

.mini-dropdown__option:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.actions {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.actions button,
.actions .link-button {
  width: 100%;
}

.actions.secondary button,
.actions.secondary .link-button {
  width: auto;
}

button,
.link-button {
  width: auto;
  padding: 10px 14px;
  font-size: 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: #0f62fe;
  color: #fff;
  text-align: center;
  text-decoration: none;
}

.toggles {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #1e293b;
}

.toggles.inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 12px;
}

.toggles.inline label {
  flex: 1 1 200px;
}

.draft-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #cbd5f5;
  border-radius: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.draft-panel__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.draft-panel__header h3 {
  margin: 0;
  font-size: 1rem;
}

.draft-panel__header p {
  margin: 0;
  font-size: 0.85rem;
  color: #475569;
}

.draft-panel__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.draft-panel__empty {
  margin: 0;
  font-size: 0.85rem;
  color: #94a3b8;
}

.draft-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.draft-entry.is-active {
  border-color: #94a3fd;
  background: #eef2ff;
}

.draft-entry__swatch {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.2);
  flex-shrink: 0;
}

.draft-entry__select {
  flex: 1;
  text-align: left;
  background: transparent;
  border: none;
  font-weight: 600;
  color: #0f172a;
  cursor: default;
}

.draft-entry__meta {
  font-size: 0.8rem;
  color: #64748b;
}

.draft-entry__toggle {
  border: 1px solid #cbd5f5;
  background: #0f62fe;
  color: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.layer-modal[hidden] {
  display: none;
}

.layer-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
}

.layer-modal__panel {
  background: #fff;
  border-radius: 16px;
  border: 1px solid #cbd5f5;
  width: min(480px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
  gap: 12px;
}

.layer-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.layer-modal__header h2 {
  margin: 0;
}

.layer-modal__hint {
  margin: 0;
  font-size: 0.9rem;
  color: #475569;
}

.layer-modal__close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
  color: #475569;
}

.layer-modal__footer {
  display: flex;
  justify-content: flex-end;
}

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 4px;
}

.layer-list__empty {
  margin: 0;
  font-size: 0.85rem;
  color: #94a3b8;
}

.layer-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.layer-list__item.is-disabled {
  opacity: 0.5;
}

.layer-list__toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #0f172a;
  flex: 1;
}

.layer-list__actions {
  display: flex;
  gap: 6px;
}

.layer-list__button {
  flex: 0 0 auto;
  padding: 6px 10px;
  font-size: 0.8rem;
  background: #e2e8f0;
  color: #0f172a;
  border: 1px solid #cbd5f5;
  border-radius: 4px;
  cursor: pointer;
}

.layer-list__button:hover {
  background: #dbeafe;
}

.preview-pane {
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#preview {
  position: relative;
  width: 100%;
  min-height: 400px;
  height: 100%;
  background: #fff;
  border: 1px solid #cbd5f5;
  overflow: hidden;
  touch-action: none;
}

#previewViewport {
  position: relative;
  display: grid;
  place-items: start center;
  width: 100%;
  height: 100%;
  min-height: inherit;
  background: transparent;
  transform-origin: 0 0;
  transform: translate(0px, 0px) scale(1);
  will-change: transform;
}

.preview-message {
  margin: 0;
  padding: 24px;
  color: #475569;
  font-style: italic;
  text-align: center;
  grid-area: 1 / 1 / 2 / 2;
  align-self: center;
}

#previewViewport .preview-message {
  grid-area: 1 / 1 / 2 / 2;
}

.preview-draft {
  grid-area: 1 / 1 / 2 / 2;
  width: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  pointer-events: none;
}

.preview-draft svg {
  width: auto;
  height: auto;
  max-width: none;
  background: transparent !important;
}

#previewViewport svg {
  width: auto;
  height: auto;
  max-width: none;
}

svg {
  max-width: 100%;
  height: auto;
  background: #fff;
}

svg [data-layer-user-hidden="true"] {
  display: none !important;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .controls {
    min-width: auto;
  }

  .measure-row {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 640px) {
  .measure-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .key-lengths {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 640px) {
  .key-lengths {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .layer-modal {
    padding: 24px 12px;
  }

  .layer-modal__panel {
    width: 100%;
  }
}
.hof-fit-control__select select option {
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: radial-gradient(circle at top, #f5f8ff, #eef2ff);
  font-size: 0.95rem;
  font-weight: 500;
  color: #0f172a;
  margin: 4px;
}

.hof-fit-control__select select option:checked {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  border-color: #93c5fd;
}
.preview-draft svg {
  width: 100%;
  height: auto;
  background: transparent !important;
}
