:root {
  --bg: #0b0f14;
  --surface: #131922;
  --surface-2: #1a212c;
  --border: #232b36;
  --border-hover: #3a4656;
  --text-primary: #eef2f6;
  --text-secondary: #9aa7b5;
  --text-muted: #5c6673;
  --accent: #4da3ff;
  --danger: #ff6b6b;
  --success: #4dd48a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Instrument Sans', sans-serif;
}

h1, h2, h3, h4 {
  font-family: 'Schibsted Grotesk', sans-serif;
  font-weight: 600;
  margin: 0;
}

a { color: var(--accent); }

/* ---- login overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay[hidden] { display: none; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { font-size: 22px; text-align: center; }
.login-card .subtitle { margin: 0 0 6px; text-align: center; color: var(--text-muted); font-size: 14px; }

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---- shared form controls ---- */
input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color 0.15s ease;
}
button:hover { border-color: var(--border-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  color: #061018;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }

.link-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 4px 8px;
}
.link-btn:hover { color: var(--text-primary); border-color: transparent; }

.error-text { color: var(--danger); font-size: 13px; margin: 0; }
.success-text { color: var(--success); font-size: 13px; margin: 0; }

/* ---- app shell ---- */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.brand {
  font-family: 'Schibsted Grotesk', sans-serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
}

/* ---- documents table ---- */
.doc-row, .doc-header-row {
  display: grid;
  grid-template-columns: 0.8fr 1.6fr 0.9fr 0.8fr 1.8fr 0.6fr 0.6fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.doc-header-row { color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.03em; }
.doc-row .muted { color: var(--text-muted); }

.top-actions { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; }
.top-actions p { color: var(--text-secondary); font-size: 13px; margin: 4px 0 0; }

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
}

/* ---- cards / sections ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.field-grid {
  display: grid;
  grid-template-columns: 2fr;
  gap: 12px;
  margin-bottom: 16px;
}
.field-grid.meta { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 800px) { .field-grid.meta { grid-template-columns: 1fr 1fr; } }

.field-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
}

.section-block { margin-bottom: 22px; }
.section-block h4 { margin-bottom: 10px; font-size: 14px; color: var(--text-secondary); }

table.fields-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.fields-table th {
  text-align: left; color: var(--text-muted); font-weight: 500;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
table.fields-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.fields-table input, table.fields-table select { width: 100%; padding: 5px 7px; font-size: 12px; }
.allowed-values { color: var(--text-muted); font-size: 11px; }

.bottom-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---- populate view ---- */
.preview-pane {
  height: 460px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
}
.preview-pane canvas { display: block; margin: 0 auto 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.3); }

#jsonEditor {
  width: 100%;
  height: 380px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
}

.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 14px 0; font-size: 13px; color: var(--text-secondary); }
.checkbox-row input { width: auto; }

.spinner-note { color: var(--text-muted); font-size: 13px; }
