:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #15202b;
  --muted: #64748b;
  --line: #d9e0e7;
  --soft: #f7f9fb;
  --accent: #2f7dff;
  --accent-strong: #155bd5;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success: #0f7b45;
  --shadow: 0 18px 45px rgba(23, 31, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(120deg, rgba(47, 125, 255, 0.08), transparent 34%),
    linear-gradient(180deg, #f8fafc, var(--bg));
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
}

.topbar h1,
.preview-toolbar h2,
.section-heading h2,
.import-help h2,
.library-header h2,
.record-card h3 {
  margin: 0;
  color: var(--ink);
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 1.55rem;
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tab-nav,
.topbar-actions,
.toolbar-actions,
.split-fields,
.button-row,
.record-actions,
.record-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tab-nav,
.segmented-control {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 4px;
}

.tab-button,
.segment {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  font-size: 0.84rem;
  font-weight: 800;
}

.tab-button.active,
.segment.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(23, 31, 45, 0.08);
}

.button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.button {
  padding: 9px 16px;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-align: center;
  white-space: normal;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(47, 125, 255, 0.22);
}

.button.ghost {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.button.publish {
  background: #111827;
  color: #ffffff;
}

.button.danger {
  background: var(--danger-soft);
  border-color: rgba(180, 35, 24, 0.18);
  color: var(--danger);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

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

.panel,
.preview-panel,
.record-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls-panel {
  overflow: auto;
  max-height: calc(100vh - 104px);
}

.form-grid {
  display: grid;
  gap: 0;
}

.field-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.field-section:last-child {
  border-bottom: 0;
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading h2 {
  font-size: 0.95rem;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

label:last-child {
  margin-bottom: 0;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 40px;
  padding: 0 11px;
}

textarea {
  min-height: 96px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 125, 255, 0.14);
}

input[type="color"] {
  padding: 4px;
}

.hidden {
  display: none;
}

.split-fields {
  align-items: end;
}

.split-fields label:first-child {
  flex: 1 1 auto;
}

.split-fields label:last-child {
  width: 128px;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: calc(100vh - 104px);
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.preview-toolbar h2 {
  font-size: 1rem;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  padding: 0;
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-row {
  min-height: 34px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: var(--soft);
  font-size: 0.84rem;
  font-weight: 650;
}

.status-row.success {
  color: var(--success);
}

.status-row.error {
  color: var(--danger);
}

.browser-frame {
  display: grid;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.42) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.42) 25%, transparent 25%),
    #cbd5e1;
  background-position: 0 0, 0 12px;
  background-size: 24px 24px;
}

iframe {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 640px;
  border: 0;
  background: #ffffff;
}

.browser-frame.mobile-frame {
  place-items: start center;
  padding: 24px;
}

.browser-frame.mobile-frame iframe {
  width: 390px;
  max-width: 100%;
  min-height: 760px;
  height: 760px;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
}

.import-panel,
.library-panel {
  padding: 18px;
}

.import-grid {
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(280px, 1fr);
  gap: 18px;
}

.import-card,
.import-help {
  padding: 18px;
}

.import-help {
  align-self: start;
}

.import-help p {
  color: var(--muted);
  line-height: 1.7;
}

.divider {
  height: 1px;
  margin: 18px 0;
  background: var(--line);
}

.button-row {
  justify-content: flex-end;
  margin-top: 16px;
}

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.library-header h2 {
  font-size: 1.45rem;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}

.record-card {
  padding: 16px;
}

.record-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.record-card h3 {
  font-size: 1.08rem;
}

.record-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.record-fields label {
  margin-bottom: 0;
}

.full-span {
  grid-column: 1 / -1;
}

.record-meta {
  justify-content: space-between;
  margin: 14px 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.record-actions {
  justify-content: flex-end;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-weight: 750;
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .tab-nav,
  .topbar-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 980px) {
  .workspace,
  .import-grid {
    grid-template-columns: 1fr;
  }

  .controls-panel,
  .preview-panel {
    max-height: none;
    min-height: auto;
  }

  iframe {
    min-height: 720px;
  }
}

@media (max-width: 700px) {
  .topbar,
  .preview-toolbar,
  .toolbar-actions,
  .library-header,
  .record-card-header,
  .record-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: flex;
  }

  .tab-nav,
  .topbar-actions,
  .toolbar-actions,
  .button-row,
  .record-actions {
    width: 100%;
  }

  .tab-nav {
    overflow-x: auto;
  }

  .button,
  .button.publish {
    flex: 1 1 auto;
  }

  .workspace,
  .import-panel,
  .library-panel {
    padding: 10px;
  }

  .split-fields {
    align-items: stretch;
    flex-direction: column;
  }

  .split-fields label:last-child {
    width: 100%;
  }

  .library-grid,
  .record-fields {
    grid-template-columns: 1fr;
  }
}
