:root {
  --bg: #0f172a;
  --panel: #111c31;
  --panel-2: #17233d;
  --card: #f7f9fc;
  --line: #d5dbea;
  --text: #0b1324;
  --muted: #5c6780;
  --primary: #1a6bb5;
  --primary-2: #165b9a;
  --danger: #b42318;
  --accent: #e9f2ff;
  --ok: #137333;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(26,107,181,0.20), transparent 30%),
    radial-gradient(circle at bottom right, rgba(19,115,51,0.08), transparent 26%),
    linear-gradient(180deg, #eef3fb 0%, #dde7f5 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  padding: .85rem 1rem;
}

.eyebrow {
  margin: 0 0 .35rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--primary);
  font-size: .74rem;
  font-weight: 800;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .2rem; font-size: clamp(1.35rem, 2.2vw, 1.9rem); }
.subtitle, .mode-summary { color: var(--muted); margin-bottom: 0; }

.topbar-actions, .editor-actions, .inline-actions { display: flex; gap: .65rem; flex-wrap: wrap; }

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  gap: .75rem;
  padding: 0 1rem 1rem;
}

.sidebar, .editor {
  min-width: 0;
  min-height: 0;
}

.sidebar {
  overflow-y: auto;
  padding-right: .2rem;
}

.editor {
  overflow-y: auto;
}

.card, .editor {
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .08);
}

.card { padding: .75rem; margin-bottom: .75rem; }
.card h2 { font-size: .95rem; margin-bottom: .6rem; }

label { display: block; font-weight: 600; font-size: .86rem; color: var(--text); margin-bottom: .55rem; }
label input[type="text"], label input[type="number"], select, textarea {
  width: 100%;
  margin-top: .35rem;
  padding: .72rem .8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font: inherit;
}

input[type="text"], input[type="number"], select, textarea, input[type="file"] {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, .04);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease, background .15s ease;
}

input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus, input[type="file"]:focus {
  outline: none;
  border-color: rgba(26, 107, 181, .85);
  box-shadow: 0 0 0 4px rgba(26, 107, 181, .12);
  background: #ffffff;
}

input[type="text"], input[type="number"], select, textarea {
  padding: .55rem .65rem;
}

input::placeholder, textarea::placeholder {
  color: #8c97ad;
}

input[type="file"] {
  width: 100%;
  padding: .6rem .7rem;
  background: linear-gradient(180deg, #fff, #f7f9fc);
}

input[type="file"]::file-selector-button {
  margin-right: .85rem;
  padding: .58rem .85rem;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--primary-2);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: #dcecff;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-weight: 700;
}
.checkbox-row input { width: .95rem; height: .95rem; margin: 0; }

button, a.secondary, .primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 34px;
  padding: .42rem .72rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 650;
  font-size: .86rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease, border-color .12s ease, opacity .12s ease;
}
button:hover, a.secondary:hover, .primary:hover { transform: translateY(-1px); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  color: white;
}
.secondary {
  background: white;
  color: var(--text);
  border-color: var(--line);
}
.danger {
  background: var(--danger);
  color: white;
}
.full { width: 100%; }

.step-nav { display: grid; gap: .6rem; margin-bottom: .55rem; }
.step-nav label {
  margin-bottom: 0;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, #f8fbff);
}
.step-list {
  list-style: none;
  padding: 0;
  margin: .9rem 0 0;
  max-height: 320px;
  overflow: auto;
  border-top: 1px solid var(--line);
}
.step-list li {
  padding: .5rem .58rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  font-size: .83rem;
}
.step-list li.active { background: var(--accent); font-weight: 800; }
.step-list li.unsaved::after { content: "unsaved"; color: var(--danger); font-size: .78rem; }

.editor { padding: .8rem; }
.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: .7rem;
  margin-bottom: .6rem;
  position: sticky;
  top: 0;
  z-index: 8;
  padding: .2rem 0 .45rem;
  background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(255,255,255,.8));
  backdrop-filter: blur(6px);
}
#step-title { margin-bottom: .3rem; }

.mode-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .5rem;
  margin-bottom: .7rem;
}
.mode-card {
  border-radius: 11px;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f7f9fd);
}
.mode-card h3 { margin-bottom: .1rem; font-size: .88rem; }
.mode-card p { margin: 0; font-size: .75rem; }
.mode-card.active { border-color: rgba(26,107,181,.45); box-shadow: 0 0 0 4px rgba(26,107,181,.08); }
.mode-card.barcode.active { background: linear-gradient(180deg, #eef6ff, #ffffff); }
.mode-card.ack.active { background: linear-gradient(180deg, #f2fbf7, #ffffff); }
.mode-card.fastening.active { background: linear-gradient(180deg, #fff7ef, #ffffff); }

.form-container { display: grid; gap: .65rem; }
.image-upload-panel {
  border: 1px dashed rgba(26, 107, 181, .35);
  border-radius: 10px;
  padding: .6rem;
  background: linear-gradient(180deg, #f8fbff, #ffffff);
  display: grid;
  gap: .55rem;
}
.image-upload-controls {
  display: flex;
  gap: .65rem;
  align-items: center;
  flex-wrap: wrap;
}
.image-upload-controls input[type="file"] {
  flex: 1 1 280px;
}
.image-preview {
  display: none;
  max-width: 100%;
  width: min(460px, 100%);
  max-height: 240px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  padding: .35rem;
}
.image-preview.visible {
  display: block;
}

.image-tool-select,
.image-color-picker,
.image-text-input,
.image-size-input {
  height: 34px;
}

.image-tool-select,
.image-text-input,
.image-size-input {
  min-width: 110px;
}

.image-tool-select {
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.35rem 2rem 0.35rem 0.55rem;
  font-size: 0.84rem;
  font-weight: 600;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #5c6780 50%),
    linear-gradient(135deg, #5c6780 50%, transparent 50%),
    linear-gradient(to right, transparent, transparent);
  background-position:
    calc(100% - 14px) calc(50% - 3px),
    calc(100% - 9px) calc(50% - 3px),
    100% 0;
  background-size: 5px 5px, 5px 5px, 2.3rem 100%;
  background-repeat: no-repeat;
}

.image-tool-select option {
  color: #0b1324;
  background: #ffffff;
}

.image-tool-select:focus {
  outline: none;
  border-color: rgba(26, 107, 181, .85);
  box-shadow: 0 0 0 3px rgba(26, 107, 181, .12);
}

.image-color-picker {
  min-width: 44px;
  padding: 0.1rem;
}

.image-canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: 0.35rem;
  overflow: auto;
}

.image-canvas {
  width: 100%;
  display: block;
  border-radius: 10px;
  background: #ffffff;
  cursor: crosshair;
}
.section {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .7rem;
  box-shadow: 0 5px 14px rgba(15, 23, 42, .04);
}
.section h3 { margin-bottom: .45rem; font-size: .92rem; }
.section .note {
  margin: 0 0 .5rem;
  line-height: 1.35;
  font-size: .76rem;
  color: #4f5e7a;
  font-style: normal;
  display: inline-block;
  padding: .22rem .48rem;
  border-radius: 999px;
  background: #eef4ff;
  border: 1px solid #d7e3fa;
}
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .55rem .65rem;
}

.checkbox-row-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-bottom: .55rem;
}

.checkbox-row-grid .field.checkbox {
  display: inline-grid;
  grid-template-columns: 1rem minmax(0, 1fr);
  align-items: center;
  gap: .45rem;
  padding: .45rem .52rem;
  min-width: 180px;
}
.field {
  display: grid;
  gap: .25rem;
  padding: .48rem .52rem .56rem;
  border: 1px solid rgba(213, 219, 234, .8);
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff, #fbfcfe);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.field:hover {
  border-color: rgba(26, 107, 181, .22);
  box-shadow: 0 8px 18px rgba(15, 23, 42, .05);
  transform: translateY(-1px);
}
.field:focus-within {
  border-color: rgba(26, 107, 181, .55);
  box-shadow: 0 0 0 4px rgba(26, 107, 181, .08);
}
.field label { margin: 0; font-size: .78rem; color: var(--muted); line-height: 1.2; }
.field input[type="text"], .field input[type="number"] { margin: 0; width: 100%; }
.field.checkbox {
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr);
  align-items: center;
  gap: .45rem;
  padding-top: .52rem;
}
.field.checkbox input[type="checkbox"] {
  width: .95rem;
  height: .95rem;
  margin: 0;
  accent-color: var(--primary);
}
.field.checkbox label { margin: 0; color: var(--text); font-weight: 700; font-size: .8rem; }

.field-grid .field:nth-child(odd) { animation: fieldFadeIn .18s ease both; }

@keyframes fieldFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Keep note styling lightweight and clearly distinct from input fields. */

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }
  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .sidebar, .editor {
    overflow: visible;
  }
  .mode-cards { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .editor-head { flex-direction: column; }
  .field-grid { grid-template-columns: 1fr; }
}
