:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #d9232e;
  --primary-hover: #b91c26;
  --accent: #0f172a;        /* Technic Dark Slate */
  --accent-hover: #1e293b;
  --technic-orange: #ea580c;
  --radius: 14px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }
main.container { flex: 1; padding-top: 24px; padding-bottom: 48px; }

.topbar {
  background: var(--surface);
  border-bottom: 2px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  padding-bottom: 14px;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.technic-logo {
  width: 48px;
  height: 30px;
  background: #1e293b;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 6px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.35);
}

.technic-logo span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
}

.brand h1 { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.tag-technic {
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--technic-orange);
  color: #fff;
  padding: 2px 7px;
  border-radius: 5px;
  letter-spacing: 0.06em;
}
.subtitle { font-size: 0.85rem; color: var(--text-muted); }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; font-size: 0.9rem; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: all 0.15s ease; font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.danger-text:hover { color: var(--primary); background: #fef2f2; }

.input, .input-sm {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 0.92rem; font-family: inherit; background: var(--surface); color: var(--text);
}
.input { margin-bottom: 14px; }
.input-sm { padding: 6px 9px; font-size: 0.82rem; background: var(--surface-alt); }
.input:focus, .input-sm:focus { outline: none; border-color: var(--technic-orange); box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.14); }
.field-label { display: block; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 6px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.setup-card { padding: 24px; margin-bottom: 20px; }
.setup-grid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 24px; align-items: stretch; }

.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-btn {
  text-align: left; padding: 12px; border-radius: 10px; border: 2px solid var(--border);
  background: var(--surface-alt); cursor: pointer; transition: all 0.15s ease;
  font-family: inherit; display: flex; flex-direction: column; gap: 4px;
}
.mode-btn strong { font-size: 0.92rem; color: var(--text); }
.mode-btn small { font-size: 0.78rem; color: var(--text-muted); line-height: 1.3; }
.mode-btn.active { border-color: var(--technic-orange); background: #fff7ed; }
.mode-btn.active strong { color: var(--technic-orange); }

.upload-zone {
  border: 2px dashed #94a3b8; border-radius: 12px; background: var(--surface-alt);
  padding: 28px 20px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; cursor: pointer; transition: all 0.18s ease; gap: 10px;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--technic-orange); background: #fff7ed; }
.upload-icon { font-size: 2.3rem; }
.upload-zone h3 { font-size: 1.1rem; font-weight: 700; }
.upload-zone p { font-size: 0.88rem; color: var(--text-muted); max-width: 400px; margin-bottom: 6px; }

.toolbar { padding: 14px 20px; margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge { background: var(--technic-orange); color: #fff; font-weight: 800; font-size: 0.85rem; padding: 6px 12px; border-radius: 999px; }

.empty-state { grid-column: 1 / -1; text-align: center; padding: 56px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.empty-gears { display: flex; justify-content: center; align-items: center; gap: 12px; margin-bottom: 18px; }
.gear { width: 32px; height: 32px; border-radius: 50%; border: 5px dashed #334155; }
.gear.g2 { width: 24px; height: 24px; border-color: var(--technic-orange); }
.beam { width: 64px; height: 18px; background: #cbd5e1; border-radius: 9px; border: 2px solid #475569; }
.empty-state h2 { font-size: 1.25rem; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); max-width: 600px; margin: 0 auto; font-size: 0.95rem; }

.steps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 20px; }
.step-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.step-card.dragging { opacity: 0.5; transform: scale(0.98); }
.step-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: #f1f5f9; border-bottom: 1px solid var(--border);
}
.step-number-badge { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1rem; }
.step-num-circle {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 0.95rem;
}
.step-card:last-child .step-num-circle { background: #16a34a; }
.step-controls { display: flex; gap: 4px; }

.icon-btn {
  width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover:not(:disabled) { background: #e2e8f0; }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn.delete:hover { background: #fee2e2; color: var(--primary); border-color: #fecaca; }

.step-image-wrap { position: relative; aspect-ratio: 4 / 3; background: #f8fafc; overflow: hidden; cursor: zoom-in; border-bottom: 1px solid var(--border); }
.step-image-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; }
.final-tag {
  position: absolute; bottom: 10px; right: 10px; background: #16a34a; color: #fff;
  font-size: 0.75rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
}

.step-body { padding: 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }

/* Technic Metadata Fields */
.technic-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.step-note-input {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-family: inherit; font-size: 0.88rem; resize: vertical; min-height: 56px; background: var(--surface-alt);
}
.step-note-input:focus { outline: none; border-color: var(--technic-orange); background: #fff; }
.step-meta-file { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Viewer Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal.hidden, .hidden { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.75); backdrop-filter: blur(4px); }
.modal-content {
  position: relative; background: var(--surface); width: 100%; max-width: 980px; border-radius: 18px;
  overflow: hidden; box-shadow: 0 24px 60px rgba(0,0,0,0.35); display: flex; flex-direction: column; max-height: 92vh;
}
.viewer-header { padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.viewer-project { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; color: var(--technic-orange); letter-spacing: 0.04em; }
.progress-track { height: 6px; background: #e2e8f0; width: 100%; }
.progress-fill { height: 100%; background: var(--technic-orange); width: 0%; transition: width 0.25s ease; }

.viewer-body { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; padding: 24px; overflow-y: auto; align-items: center; }
.viewer-image-box {
  position: relative; background: #f8fafc; border-radius: 12px; aspect-ratio: 4 / 3;
  display: flex; align-items: center; justify-content: center; overflow: hidden; border: 1px solid var(--border);
}
.viewer-image-box img { width: 100%; height: 100%; object-fit: contain; }
.viewer-step-pill {
  position: absolute; top: 14px; left: 14px; background: var(--accent); color: #fff; font-weight: 800;
  font-size: 1.2rem; min-width: 44px; height: 44px; padding: 0 12px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.viewer-notes { display: flex; flex-direction: column; gap: 12px; }
.note-label { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }

.tech-tags-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tech-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  background: #1e293b;
  color: #fff;
}
.tech-pill.orange { background: var(--technic-orange); }

#viewerNoteText {
  font-size: 1.05rem; line-height: 1.6; background: var(--surface-alt); padding: 16px;
  border-radius: 12px; border: 1px solid var(--border); min-height: 110px;
}
.viewer-tip { font-size: 0.82rem; color: var(--text-muted); }
.viewer-footer { padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-alt); display: flex; align-items: center; justify-content: space-between; }
.viewer-counter { font-weight: 700; color: var(--text-muted); }

.footer { text-align: center; padding: 20px 0; color: var(--text-muted); font-size: 0.84rem; border-top: 1px solid var(--border); background: var(--surface); }
.only-print { display: none; }

@media print {
  .no-print, .technic-fields { display: none !important; }
  body { background: #fff; }
  .container { max-width: 100%; padding: 0; }
  .only-print.print-cover {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; page-break-after: always; min-height: 90vh; padding: 40px;
    border: 4px solid var(--accent); border-radius: 16px;
  }
  .print-badge { background: var(--technic-orange); color: #fff; font-weight: 800; letter-spacing: 0.12em; padding: 6px 18px; border-radius: 999px; margin-bottom: 16px; }
  .print-cover h1 { font-size: 2.6rem; margin-bottom: 8px; }
  .print-cover p { font-size: 1.1rem; color: #475569; margin-bottom: 28px; }
  .print-hero-wrap img { max-width: 80%; max-height: 460px; object-fit: contain; border-radius: 12px; border: 2px solid #cbd5e1; }
  .steps-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .step-card { box-shadow: none; border: 2px solid #94a3b8; break-inside: avoid; page-break-inside: avoid; }
  .step-controls, .step-meta-file { display: none !important; }
  .step-note-input { border: none; background: transparent; padding: 0; min-height: auto; font-size: 0.95rem; color: #0f172a; }
}

@media (max-width: 800px) {
  .setup-grid, .viewer-body { grid-template-columns: 1fr; }
  .mode-toggle { grid-template-columns: 1fr; }
}
