:root {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #1f2430;
  --border: #2a3142;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5b8def;
  --accent-hover: #7aa3f5;
  --danger: #f07178;
  --radius: 10px;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

html.preview-only-mode #app-shell {
  display: none !important;
}

html.preview-only-mode,
html.preview-only-mode body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

html.preview-only-mode #preview-only {
  display: block !important;
}

body.preview-only-mode {
  overflow: hidden;
  background: #fff;
}

.preview-only {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #fff;
  z-index: 1000;
}

.preview-only[hidden] {
  display: none !important;
}

.preview-only-loading,
.preview-only-error {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 1.5rem;
  font-size: 1rem;
  text-align: center;
}

.preview-only-loading[hidden],
.preview-only-error[hidden],
.preview-only-error.hidden {
  display: none !important;
}

.preview-only-error {
  color: #b00020;
  max-width: 36rem;
  margin-inline: auto;
}

.preview-full {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #fff;
}

.preview-full[hidden] {
  display: none !important;
}

.header {
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 2rem 2rem;
  min-height: calc(100vh - 5rem);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-height: 0;
}

.panel-wide {
  grid-column: 1 / -1;
  min-height: 520px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.badge {
  font-size: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  color: var(--muted);
}

.template-source {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.source-label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}

.path-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.contentserv-url-id {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent-hover);
}

.contentserv-url-id.missing {
  color: var(--muted);
}

.contentserv-fetch {
  padding-bottom: 0.5rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.contentserv-status {
  margin: 0;
  font-size: 0.85rem;
  min-height: 1.25rem;
}

.contentserv-status.loading {
  color: var(--accent-hover);
}

.contentserv-status.ok {
  color: #7fd99a;
}

.contentserv-status.err {
  color: var(--danger);
}

.path-input {
  flex: 1;
  min-width: 12rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.path-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.source-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
  word-break: break-all;
}

.source-meta.hidden {
  display: none;
}

.source-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.editor {
  flex: 1;
  min-height: 240px;
  resize: vertical;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.45;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.editor:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.syntax-help {
  font-size: 0.85rem;
  color: var(--muted);
}

.syntax-help summary {
  cursor: pointer;
  user-select: none;
}

.syntax-help ul {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

.syntax-help code {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent-hover);
}

.mapping-list {
  overflow: auto;
  max-height: 280px;
  min-height: 80px;
}

.mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.mapping-table th,
.mapping-table td {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.mapping-table th {
  color: var(--muted);
  font-weight: 500;
  position: sticky;
  top: 0;
  background: var(--surface);
}

.mapping-table code {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent-hover);
}

.mapping-table .value-cell {
  color: var(--text);
  max-width: 280px;
}

.mapping-table .row-missing {
  background: rgba(240, 113, 120, 0.08);
}

.mapping-table .missing {
  color: var(--danger);
  font-size: 0.8rem;
}

.type-tag {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
}

.empty-state {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.output-tabs {
  display: flex;
  gap: 0.25rem;
}

.tab {
  font: inherit;
  cursor: pointer;
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tab.active {
  color: var(--text);
  background: var(--surface-2);
}

.tab-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tab-panel.hidden {
  display: none;
}

#preview {
  flex: 1;
  width: 100%;
  min-height: 480px;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.source-output {
  flex: 1;
  margin: 0;
  overflow: auto;
  min-height: 300px;
  max-height: 400px;
  padding: 0.75rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.error.hidden {
  display: none;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  .header {
    padding: 1rem;
  }
}
