:root {
  --ink: #1d2530;
  --muted: #6b7682;
  --line: #e3e8ee;
  --bg: #f6f8fb;
  --card: #ffffff;
  --accent: #3b6ea5;
  --accent-dark: #2c5680;
  --accent-soft: #eaf1f9;
  --mark: #ffe9a8;
  --error: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 35, 60, .08), 0 6px 24px rgba(20, 35, 60, .06);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
/* The [hidden] attribute must beat the .modal/.busy display rules below (same
   specificity, so without !important the class wins and they show on load). */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink);
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
h1, h2, h3 { margin: 0; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
small { color: var(--muted); }

/* top bar */
.topbar {
  flex: none;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 22px;
}
.brand { display: flex; align-items: center; gap: 14px; max-width: 1180px; margin: 0 auto; }
.logo {
  width: 42px; height: 42px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; font-weight: 800; letter-spacing: .5px;
  display: grid; place-items: center; font-size: 16px;
}
.topbar h1 { font-size: 19px; }
.tagline { margin: 1px 0 0; color: var(--muted); font-size: 13px; }

main { flex: 1; min-height: 0; width: 100%; max-width: 1180px; margin: 0 auto;
  padding: 20px 22px; display: flex; flex-direction: column; }
#upload-step { overflow-y: auto; }
#workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* cards */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px;
}
.step-num {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 14px; margin-right: 8px;
}
.upload h2 { font-size: 20px; display: flex; align-items: center; }
.lead { color: var(--ink); margin: 12px 0 6px; }

.howto { margin: 14px 0 18px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 14px; background: #fbfcfe; }
.howto summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
.howto ol { margin: 6px 0 12px 0; padding-left: 20px; line-height: 1.7; }
.screenshot-placeholder {
  border: 2px dashed #c7d2df; border-radius: 8px; color: #93a1b3;
  padding: 26px; text-align: center; font-size: 13px; background: #f4f7fb;
}

.upload-row { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.file-drop {
  flex: 1; display: flex; align-items: center; gap: 10px;
  border: 1.5px dashed #c2cedd; border-radius: 10px; padding: 14px 16px;
  cursor: pointer; background: #fbfcfe; transition: border-color .15s, background .15s;
}
.file-drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.file-drop input { position: absolute; opacity: 0; width: 0; height: 0; }
.file-label { color: var(--muted); }
.file-drop.has-file .file-label { color: var(--ink); font-weight: 600; }

.or { margin: 18px 0 0; color: var(--muted); font-size: 14px; }
.or select { margin: 0 4px; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 16px; border-radius: 9px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: #c2cedd; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: var(--accent-soft); border-color: transparent; color: var(--accent-dark); }
.btn.link { background: none; border: none; color: var(--muted); }
.btn.link:hover { color: var(--ink); text-decoration: underline; }
.btn.small { padding: 6px 12px; font-size: 13px; }

.error {
  margin-top: 14px; color: var(--error); background: #fdecea;
  border: 1px solid #f5c6c2; border-radius: 8px; padding: 10px 14px; font-size: 14px;
}

/* workspace */
.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 16px; margin-bottom: 16px;
}
.tool { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tool select, .tool input[type=text] {
  font-size: 14px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
}
.tool input[type=text] { width: 150px; }
.mode { gap: 12px; }
.mode label { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); font-weight: 500; cursor: pointer; }
.spacer { flex: 1; }

.work { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 320px;
  gap: 16px; align-items: stretch; }

.preview-wrap {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; overflow: hidden;
}
.preview-hint { margin: 2px 4px 12px; color: var(--muted); font-size: 13px; }
.preview-hint .swatch { background: var(--mark); padding: 0 6px; border-radius: 3px; color: #7a5b00; }
#preview {
  flex: 1; min-height: 360px; width: 100%; border: 1px solid var(--line);
  border-radius: 8px; background: #fff;
}

.fields-panel {
  min-height: 0; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.fields-panel h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.pill { background: var(--accent-soft); color: var(--accent-dark); border-radius: 20px; padding: 1px 10px; font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }
#fields-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.field-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fbfcfe; }
.field-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.field-item .field-default { font-size: 12px; color: var(--muted); margin: 0 0 6px; word-break: break-word; }
.field-item .field-default b { color: var(--ink); }
.field-item label.lbl { display: block; font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 3px; }
.field-item input.name { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }
.field-item .row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.field-item .ml { font-size: 12px; color: var(--muted); display: inline-flex; gap: 5px; align-items: center; }
.field-item .remove { background: none; border: none; color: var(--error); font-size: 13px; cursor: pointer; font-weight: 600; }
.field-item .remove:hover { text-decoration: underline; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(20,30,45,.55); display: grid; place-items: center; z-index: 50; padding: 24px; }
.modal-inner { background: #fff; border-radius: 14px; width: min(900px, 96vw); height: 92vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head strong { flex: 1; }
#pdf-frame { flex: 1; width: 100%; border: none; }

/* busy */
.busy { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 30px;
  display: flex; align-items: center; gap: 10px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* [bracket] auto-detect prompt */
.bracket-prompt {
  flex: none;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: #fff8e1; border: 1px solid #f3d98a; color: #7a5b00;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}
.bracket-prompt #bracket-msg { flex: 1; min-width: 200px; }
.bracket-prompt code { background: #fdeec2; }

/* On phones, let the page scroll normally instead of locking to the viewport. */
@media (max-width: 900px) {
  body { height: auto; min-height: 100vh; overflow: visible; }
  main { overflow: visible; }
  .work { grid-template-columns: 1fr; align-items: start; }
  #preview { flex: none; height: 70vh; min-height: 360px; }
  .fields-panel { overflow: visible; }
}
