:root {
  color-scheme: light dark;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.4;
  font-weight: 400;
  --surface: rgba(255,255,255,0.8);
  --border: rgba(0,0,0,0.15);
  --accent: #2563eb;
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, rgba(37,99,235,.12), transparent 45%), #0f172a;
  color: #0f172a;
}

body.dark {
  background: #0f172a;
  color: #e2e8f0;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 15px 50px rgba(15,23,42,0.15);
}

.page-header h1 {
  margin: 0 0 0.25rem;
}

.page-header p {
  margin: 0;
  max-width: 45ch;
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 0.75rem;
}

button {
  border: none;
  border-radius: 0.6rem;
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

button.outline {
  background: transparent;
  border: 1px dashed var(--border);
  color: inherit;
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button.icon {
  padding: 0.3rem 0.55rem;
  line-height: 1;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.rows {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.row {
  background: rgba(255,255,255,0.95);
  border-radius: 1rem;
  border: 1px solid var(--border);
  padding: 1rem;
  box-shadow: 0 20px 40px rgba(15,23,42,0.1);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.row-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.row-heading h2 {
  margin: 0 0 0.25rem;
}

.row-note {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(15,23,42,0.7);
}

.button-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(110px, 1fr));
  gap: 0.75rem;
}

.button-card {
  border: 2px dashed rgba(15,23,42,0.2);
  background: rgba(248,250,252,0.95);
  border-radius: 1rem;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.button-card[data-empty="true"] {
  opacity: 0.8;
}

.button-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}

.button-card.warning {
  border-color: rgba(220,38,38,0.5);
}

.button-card.dragging {
  opacity: 0.4;
}

.card-head {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.drag-handle {
  border-radius: 0.75rem;
  border: 1px dashed rgba(15,23,42,0.2);
  background: transparent;
  min-width: 2.5rem;
  font-size: 1.2rem;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drag-handle:active {
  cursor: grabbing;
}

.card-summary {
  flex: 1;
  text-align: left;
  border-radius: 0.75rem;
  background: #fff;
  border: 1px solid rgba(15,23,42,0.1);
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.card-title {
  font-weight: 600;
  font-size: 1rem;
}

.card-meta {
  font-size: 0.85rem;
  color: rgba(15,23,42,0.6);
}

.card-head-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.card-head-actions .ghost {
  padding: 0.35rem 0.5rem;
  background: rgba(37,99,235,0.08);
}

.ghost {
  background: transparent;
  border: 1px dashed rgba(15,23,42,0.2);
  color: inherit;
}

.text {
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
}

.text.danger {
  color: var(--danger);
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(37,99,235,0.1);
  font-size: 0.8rem;
}

.badge.danger {
  background: rgba(220,38,38,0.15);
  color: var(--danger);
}

.child-strip {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-left: 1.5rem;
  border-left: 2px dashed rgba(15,23,42,0.15);
}

.child-strip:empty {
  min-height: 1.5rem;
}

.slot-placeholder {
  border: 2px dashed rgba(15,23,42,0.1);
  border-radius: 0.9rem;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: rgba(15,23,42,0.5);
}

.drag-preview {
  position: fixed;
  pointer-events: none;
  opacity: 0.85;
  width: 220px;
  transform: translate(-9999px, -9999px);
  z-index: 9999;
}

.row-overflow {
  border-color: rgba(220,38,38,0.5);
  box-shadow: 0 0 0 2px rgba(220,38,38,0.2);
}

.row-overflow .row-note {
  color: var(--danger);
  font-weight: 600;
}

.row-overflow .button-strip {
  background: rgba(220,38,38,0.04);
  border-radius: 0.75rem;
  padding: 0.5rem;
}

.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
}

.workspace-secondary {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.parking-panel,
.drafts-panel {
  background: rgba(255,255,255,0.95);
  border-radius: 1rem;
  border: 1px solid var(--border);
  padding: 1rem;
  box-shadow: 0 15px 40px rgba(15,23,42,0.08);
}

.parking-panel header,
.drafts-panel > div:first-child {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
}

.parking-panel header h2,
.drafts-panel h2 {
  margin: 0 0 0.3rem;
}

.parking-strip {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
}

.draft-controls {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.draft-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.draft-buttons button {
  flex: 1 1 150px;
}

.editor-panel {
  margin-top: 2rem;
  background: rgba(255,255,255,0.95);
  border-radius: 1rem;
  border: 1px solid var(--border);
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(15,23,42,0.1);
}

.editor-empty {
  margin: 0;
  color: rgba(15,23,42,0.6);
}

#editor-form h3 {
  margin-top: 0;
}

.editor-fieldset {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 1rem;
}

fieldset legend {
  padding: 0 0.4rem;
  font-weight: 600;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
  gap: 0.35rem;
}

label + label {
  margin-top: 0.85rem;
}

input,
textarea,
select {
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  font-size: 1rem;
  font-family: inherit;
}

.editor-json {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.editor-children {
  margin-top: 1.5rem;
  border: 1px dashed rgba(15,23,42,0.2);
  border-radius: 0.9rem;
  padding: 1rem;
  background: rgba(248,250,252,0.7);
}

.editor-children header {
  margin-bottom: 0.75rem;
}

.editor-children h4 {
  margin: 0;
}

.editor-children p {
  margin: 0.1rem 0 0;
  color: rgba(15,23,42,0.7);
}

#child-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#child-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-radius: 0.65rem;
  background: #fff;
  border: 1px solid rgba(15,23,42,0.15);
  font-size: 0.9rem;
}

.editor-children-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.status-panel {
  margin-top: 1.5rem;
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  background: rgba(15,23,42,0.08);
  min-height: 2.5rem;
}

.status-panel.error {
  background: rgba(220,38,38,0.15);
  color: #991b1b;
}

@media (max-width: 640px) {
  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .header-actions button,
  .draft-buttons button,
  .editor-actions button,
  .parking-panel header button {
    width: 100%;
  }

  .card-head {
    flex-direction: column;
  }

  .child-strip {
    padding-left: 1rem;
  }
}

@media (max-width: 900px) {
  .button-strip {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}
