:root {
  --navy: #011749;
  --blue: #0d21a0;
  --blue-soft: #e8eefb;
  --slate: #334155;
  --muted: #64748b;
  --line: #d8e0ec;
  --panel: #f7f9fc;
  --white: #ffffff;
  --danger: #b42318;
  --ok: #16794a;
  --warning: #9a6700;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: #172033;
  background: #eef2f8;
  font-family: "Segoe UI", "Liberation Sans", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

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

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 76px;
  padding: 12px 20px;
  color: var(--white);
  background: linear-gradient(110deg, #011749 0%, #08276e 55%, #0d21a0 100%);
  box-shadow: 0 4px 18px rgba(1, 23, 73, 0.28);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--navy);
  background: #f4d35e;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin: 3px 0 0;
  font-size: 12px;
  color: #c9d7f4;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.status {
  min-width: 90px;
  font-size: 12px;
  color: #dbe6ff;
}

.status.ok {
  color: #9ff0c5;
}

.status.error {
  color: #ffb4ab;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #dbe6ff;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
  transition: background 0.15s ease, transform 0.15s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.17);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  border-color: #f4d35e;
  color: #14224a;
  background: #f4d35e;
  font-weight: 700;
}

.btn.primary:hover {
  background: #ffe382;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: #ffd5d0;
  border-color: rgba(255, 180, 171, 0.45);
}

.btn.small {
  padding: 5px 9px;
  font-size: 12px;
}

.btn.disabled,
.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  pointer-events: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(420px, 1fr) 420px;
  gap: 12px;
  height: calc(100vh - 76px);
  padding: 12px;
}

.slides-pane,
.preview-pane,
.inspector-pane {
  min-height: 0;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.slides-pane,
.inspector-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.pane-header h2,
.preview-toolbar h2 {
  margin: 0;
  font-size: 14px;
  color: var(--navy);
}

.muted {
  font-size: 12px;
  color: var(--muted);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.button-row .btn {
  color: var(--navy);
  border-color: var(--line);
  background: var(--white);
}

.button-row .btn:hover {
  background: var(--blue-soft);
}

.button-row .btn.danger {
  color: var(--danger);
  border-color: #f1c4bf;
}

.slide-list {
  flex: 1;
  margin: 0;
  padding: 10px;
  overflow-y: auto;
  list-style: none;
}

.slide-item {
  margin-bottom: 8px;
}

.slide-select {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  width: 100%;
  padding: 7px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  color: inherit;
  background: transparent;
}

.slide-select:hover {
  background: #f3f6fc;
}

.slide-item.active .slide-select {
  border-color: #aebff0;
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 1px rgba(13, 33, 160, 0.1);
}

.slide-thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
  color: var(--muted);
  background: #fbfcfe;
  font-weight: 700;
}

.slide-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.slide-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.slide-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--blue);
}

.slide-title {
  overflow: hidden;
  font-size: 12px;
  line-height: 1.3;
  color: var(--slate);
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-stage {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 220px;
  padding: 22px;
  overflow: auto;
  background:
    linear-gradient(45deg, #f1f4f9 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(-45deg, #f1f4f9 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(45deg, transparent 75%, #f1f4f9 75%) 0 0 / 18px 18px,
    linear-gradient(-45deg, transparent 75%, #f1f4f9 75%) 0 0 / 18px 18px,
    #fbfcfe;
}

#slide-preview {
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  background: var(--white);
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.24);
}

.preview-empty {
  max-width: 340px;
  padding: 18px;
  text-align: center;
  line-height: 1.5;
  color: var(--muted);
  border: 1px dashed #b8c6dc;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.preview-stale {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  font-size: 12px;
  color: #6b4c00;
  text-align: center;
  border: 1px solid #f0d48a;
  border-radius: 999px;
  background: #fff6d6;
  box-shadow: 0 4px 14px rgba(107, 76, 0, 0.12);
}

.preview-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfe;
}

.warning {
  color: var(--warning);
  font-size: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: #f7f9fc;
}

.tab {
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 600;
}

.tab:hover {
  color: var(--navy);
  background: #eef2f9;
}

.tab.active {
  color: var(--navy);
  border-color: #cbd7ec;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.inspector-body {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.inspector-block,
.editor-group,
.paragraph-card,
.template-card,
.asset-card {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfe;
}

.inspector-block,
.editor-group {
  margin-bottom: 12px;
  padding: 12px;
}

.block-head,
.paragraph-head,
.run-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.block-head h3,
.paragraph-head strong,
.editor-group h3 {
  margin: 0;
  font-size: 13px;
  color: var(--navy);
}

.shape-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.shape-item {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
  width: 100%;
  padding: 8px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: inherit;
  background: var(--white);
}

.shape-item:hover {
  border-color: #b6c5e6;
  background: #f5f8ff;
}

.shape-item.active {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
  background: var(--blue-soft);
}

.shape-kind {
  align-self: start;
  padding: 2px 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--blue);
  border-radius: 4px;
  background: #e6ecfd;
}

.shape-copy {
  min-width: 0;
}

.shape-name {
  display: block;
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shape-text {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  font-size: 11px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--slate);
}

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

input[type="text"],
input[type="number"],
input[type="color"],
select,
textarea {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: #172033;
  background: var(--white);
}

input[type="color"] {
  height: 34px;
  padding: 3px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(13, 33, 160, 0.18);
  border-color: var(--blue);
}

.paragraph-card {
  margin-top: 9px;
  padding: 9px;
  background: var(--white);
}

.paragraph-head {
  margin-bottom: 7px;
  font-size: 12px;
}

.paragraph-head select {
  width: auto;
  min-width: 110px;
}

.run-row {
  margin-top: 7px;
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  background: #fbfcfe;
}

.run-row textarea {
  min-height: 42px;
}

.run-format {
  display: grid;
  grid-template-columns: 1fr 68px repeat(3, auto) 40px auto;
  align-items: end;
  gap: 6px;
  margin-top: 6px;
}

.run-format label {
  justify-content: flex-end;
  padding-bottom: 8px;
}

.run-format .check-inline {
  flex-direction: row;
  align-items: center;
  gap: 3px;
  padding-bottom: 6px;
  font-size: 12px;
}

.mini {
  padding: 3px 7px;
  font-size: 11px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  color: var(--slate);
  background: var(--white);
}

.mini:hover {
  background: #eef2f9;
}

.mini.danger {
  color: var(--danger);
  border-color: #f1c4bf;
}

.break-row,
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
  padding: 7px 8px;
  font-size: 11px;
  color: var(--muted);
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
}

.table-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.table-row {
  display: grid;
  gap: 5px;
}

.table-row textarea {
  min-height: 34px;
  font-size: 11px;
}

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

.asset-card {
  padding: 8px;
}

.asset-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--white);
}

.asset-card code {
  display: block;
  overflow: hidden;
  font-size: 10px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-card {
  padding: 12px;
}

.template-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--navy);
}

.template-card p {
  margin: 0 0 10px;
  line-height: 1.45;
  color: var(--muted);
  font-size: 12px;
}

.drop-note {
  padding: 12px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
}

.json-editor {
  width: 100%;
  min-height: 420px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  max-width: min(480px, calc(100vw - 36px));
  padding: 11px 14px;
  color: var(--white);
  border-radius: 8px;
  background: #1f2937;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.28);
}

.toast.error {
  background: #7f1d1d;
}

.toast.ok {
  background: #166534;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--white);
  background: rgba(1, 23, 73, 0.72);
  backdrop-filter: blur(2px);
}

.overlay p {
  margin: 0;
  font-size: 14px;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #f4d35e;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 210px minmax(300px, 1fr) 360px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .app-shell {
    height: auto;
    min-height: calc(100vh - 118px);
  }

  .preview-pane {
    min-height: 460px;
  }
}

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

  .slides-pane {
    max-height: 260px;
  }

  .slide-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .preview-pane {
    min-height: 360px;
  }

  .run-format {
    grid-template-columns: 1fr 72px;
  }

  .field-grid,
  .field-grid.three {
    grid-template-columns: 1fr;
  }
}
