:root {
  --bg: #0b0d12;
  --panel: #111620;
  --text: #e7ecf5;
  --muted: #a1a8b5;
  --border: #1e2430;
  --accent: #3b82f6;
  --warn: #eab308;
  --error: #ef4444;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #0d1117;
}
.app-title { font-size: 28px; margin: 0; }
.title-group { display: flex; flex-direction: column; gap: 10px; }
.app-subtitle { margin: 0; color: var(--muted); font-size: 16px; }
.section-subtitle { margin: 0 0 10px 0; color: var(--muted); font-size: 15px; }
/* Pleasant spacing between section titles and subtitles */
.panel h2 { margin-bottom: 8px; }
.spacer { flex: 1; }
.header-actions { display: inline-flex; align-items: center; gap: 12px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #0f1623;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}
.icon-btn.icon-text { height: 28px; width: auto; padding: 0 8px; gap: 6px; border-radius: 16px; }
.icon-btn .btn-label { line-height: 1; }
.icon-btn:hover { border-color: #273041; background: #101a2a; }
.icon-btn:focus { outline: 2px solid #3b82f6; outline-offset: 1px; }

.label { color: var(--muted); font-size: 14px; margin-right: 6px; }
.lang-ico { display: inline-flex; align-items: center; justify-content: center; width: 24px; }
select, input, textarea, button {
  font: inherit;
  color: var(--text);
  background: #0f1623;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 150ms ease, transform 60ms ease, opacity 120ms ease;
}
button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { transform: translateY(1px); opacity: 0.9; }

.container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
  flex: 1 0 auto; /* fill available height so footer sticks to bottom */
}
.right-col { grid-column: 2; display: grid; gap: 16px; }
@media (max-width: 900px) {
  .container { grid-template-columns: 1fr; }
  .right-col { grid-column: auto; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  transition: box-shadow 150ms ease, border-color 150ms ease;
  /* Anchor for in-panel overlays like the file viewer */
  position: relative;
}
.panel h2, .panel h3 { margin-top: 0; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, box-shadow 150ms ease;
}
.dropzone:hover { border-color: var(--accent); color: var(--text); }
.dropzone:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(59,130,246,0.5) inset; }
.dropzone.dragover { border-color: var(--accent); color: var(--text); }

.controls { margin-top: 12px; display: flex; gap: 8px; }
.file-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 12px; }
.file-list li.file-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0f1623;
  transition: box-shadow 150ms ease, border-color 150ms ease, background-color 150ms ease;
}
.file-list li.file-card:hover { border-color: #273041; box-shadow: 0 6px 18px rgba(0,0,0,0.25); }
.file-list button { width: 32px; }
.file-left { display: inline-flex; align-items: center; gap: 12px; min-width: 0; }
.file-icon { display: inline-flex; width: 36px; height: 36px; flex: 0 0 auto; }
.file-icon svg { width: 36px; height: 36px; display: block; }
.file-name { font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; max-width: 52vw; }
.file-size-watermark { position: absolute; right: 56px; bottom: 8px; font-weight: 700; font-size: 18px; color: var(--muted); opacity: 0.2; pointer-events: none; user-select: none; }

.schema-builder .row { margin: 12px 0; }
.fields {
  display: grid;
  gap: 6px;
  background: #131a28; /* lighter than panel */
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  max-height: 340px;
  overflow: auto;
}
.field-row {
  display: grid;
  grid-template-columns: 2fr 0.8fr 2.4fr 1fr auto;
  gap: 8px;
  align-items: center;
  background: #0e1626; /* darker than container, different hue */
  border: 1px solid #1a2230;
  border-radius: 8px;
  padding: 8px;
  transition: box-shadow 150ms ease, border-color 150ms ease, background-color 150ms ease;
  cursor: grab;
}
.field-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: #101a2e; /* slightly brighter to stand out */
  border: 1px solid #2c3a58; /* switch from dashed to solid for clearer affordance */
  color: #d5deeb; /* more readable than muted, still not full white */
  border-radius: 8px;
  padding: 12px;
  font-weight: 600;
  transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease, opacity 120ms ease;
}
.field-add:hover { border-color: #3b82f6; color: var(--text); background: #111c33; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
.field-add:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; }
/* Style the leading plus icon within the button */
.field-add > span[aria-hidden="true"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #17233a;
  color: inherit;
  font-weight: 800;
  line-height: 1;
}
.field-add:active { opacity: 0.9; }
.field-row:hover { border-color: #273041; box-shadow: 0 1px 0 rgba(0,0,0,0.1), 0 0 0 2px rgba(59, 130, 246, 0.12) inset; }
.field-row:active { cursor: grabbing; }
.field-row.drag-over { border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59,130,246,0.25) inset; }
.field-error { color: var(--error); font-size: 12px; grid-column: 1 / -1; }
.invalid { border-color: var(--error) !important; }
@media (max-width: 900px) {
  .field-row { grid-template-columns: 1fr; }
}

.preview {
  background: #0c111a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  max-height: 200px;
  overflow: auto;
}

.inputs { display: grid; gap: 8px; margin-top: 16px; }
.adv-grid { display: grid; gap: 12px; }
.adv-section {
  background: #0f1623;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.adv-section input[type="text"],
.adv-section textarea,
.adv-section select { width: 100%; }
.adv-title { margin: 0 0 6px 0; font-size: 14px; color: var(--text); opacity: 0.9; }
.adv-help { margin: 0 0 10px 0; color: var(--muted); font-size: 12px; }
.adv-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; display: inline-block; }
.adv-check { display: inline-flex; align-items: center; gap: 8px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.status { margin-top: 8px; color: var(--muted); }
.status.warn { color: var(--warn); }
.status.error { color: var(--error); }
.dropzone.error { border-color: var(--error); color: var(--error); }
.result { margin-top: 12px; }

.site-footer {
  color: var(--muted);
  text-align: center;
  padding: 12px 16px 16px 16px;
}
.site-footer .cta { font-size: 12px; }
.site-footer a { color: inherit; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer .contact {
  margin-top: 6px;
  line-height: 1.6;
}
.site-footer .contact-item {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.2px;
}

.banner { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.banner-warn { background: rgba(234, 179, 8, 0.1); color: #facc15; }
.banner-error { background: rgba(239, 68, 68, 0.12); color: #f87171; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Collapsible */
.collapsible { margin-top: 12px; }
.collapsible-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0f1623;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.collapsible-header:hover { border-color: #273041; }
.collapsible-content {
  margin-top: 8px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 240ms ease, opacity 200ms ease;
}
.collapsible-content.is-open { opacity: 1; }
.collapsible-header span:last-child { transition: transform 200ms ease; }
.collapsible-header[aria-expanded="true"] span:last-child { transform: rotate(180deg); }
.hidden { display: none; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 1000; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.modal-content {
  position: relative;
  max-width: 640px;
  margin: 10vh auto 0 auto;
  background: #0c111a;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 12px; }
.modal-body a { color: var(--text); text-decoration: none; }
.modal-body a:hover { text-decoration: underline; }
.help-list { margin: 0; padding-left: 0; list-style: none; }
.help-list li { margin: 6px 0; color: var(--text); }
/* Improve readability in modals */
.modal-body p { line-height: 1.65; margin: 10px 0; }
.modal-body ul { margin: 10px 0 14px 22px; }
.modal-body li { line-height: 1.6; margin: 8px 0; }
.modal-body .help-list li { margin: 10px 0; line-height: 1.6; color: var(--text); }

/* File viewer overlay (left column) */
.file-viewer-overlay {
  position: absolute;
  inset: 0; /* fill the panel area */
  z-index: 10; /* above list, below global modals */
  background: #0c111a; /* match app dark tones */
  border-radius: 10px; /* follow panel radius */
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}
.file-viewer-overlay.hidden { display: none; }
.file-viewer-overlay .fv-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
}
.file-viewer-overlay .fv-body {
  display: flex;
  flex: 1 1 auto;
  margin-top: 4px;
  /* Reserve a bit for the close button */
  padding: 32px 12px 12px 12px;
  overflow: hidden;
}
.file-viewer-overlay .fv-body .fv-content {
  width: 100%;
  height: 100%;
  object-fit: contain; /* for images */
  background: #0b0f17;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.file-viewer-overlay .fv-message {
  color: var(--muted);
  margin: auto;
}

/* --- Mobile adjustments (≤640px) --- */
@media (max-width: 640px) {
  /* Header layout: title above, controls row below */
  .topbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .title-group { order: 0; width: 100%; text-align: center; }
  .spacer { display: none; }
  .header-actions { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: nowrap; }

  /* Body lock when modal is open */
  body.has-modal { height: 100vh; overflow: hidden; position: fixed; width: 100%; }

  /* Prevent scroll chaining; allow vertical panning inside modal */
  .modal, .modal-backdrop, .modal-content, .modal-body { overscroll-behavior: contain; touch-action: pan-y; }

  /* Modal layout and internal scroll */
  .modal:not(.hidden) { display: flex; align-items: center; justify-content: center; padding: 12px; }
  .modal.hidden { display: none !important; }
  .modal-content { display: flex; flex-direction: column; width: 100%; max-width: 640px; max-height: 92vh; }
  .modal-header { position: sticky; top: 0; z-index: 1; background: #0c111a; }
  .modal-body { flex: 1 1 auto; overflow: auto; -webkit-overflow-scrolling: touch; }
}
