/* =========================================================
   Live · Gerador de Etiquetas
   Estética: ficha técnica industrial. Fundo claro para chão
   de fábrica, tinta escura, laranja Live como acento semântico
   (seleção e código). Códigos sempre em monoespaçada.
   ========================================================= */
:root {
  --ink: #1B1D21;
  --ink-soft: #5A6069;
  --paper: #F4F5F3;
  --panel: #FFFFFF;
  --line: #D9DBD6;
  --orange: #F05A22;
  --orange-soft: #FDE8DE;
  --steel: #2E3238;
  --uph: #1D4ED8;
  --sticker: #B45309;
  --knob: #7C3AED;
  --tipo: #0F766E;
  --mono: 'Consolas', 'Cascadia Mono', 'Courier New', monospace;
  --sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --strip-h: 128px;
}

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

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  padding-bottom: var(--strip-h);
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--steel); color: #fff;
  padding: 0 20px; height: 58px;
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-mark {
  font-weight: 800; font-size: 22px; letter-spacing: 0.18em;
  color: #fff;
  border-bottom: 3px solid var(--orange);
  padding-bottom: 2px;
}
.brand-sub { font-size: 13px; color: #B9BEC6; }
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent; color: #C9CDD3; border: 1px solid transparent;
  font: inherit; font-weight: 600; padding: 8px 16px; cursor: pointer;
  border-radius: 4px;
}
.tab:hover { color: #fff; }
.tab.active { background: var(--orange); color: #fff; }
.tab:focus-visible, .btn:focus-visible, .model-btn:focus-visible {
  outline: 2px solid var(--orange); outline-offset: 2px;
}
.badge {
  background: #fff; color: var(--steel); border-radius: 10px;
  font-size: 11px; padding: 1px 7px; margin-left: 4px; font-weight: 700;
}

/* ---------- Layout ---------- */
.view { display: flex; align-items: flex-start; }
.hidden { display: none !important; }

.sidebar {
  width: 230px; flex-shrink: 0;
  padding: 18px 14px;
  position: sticky; top: 58px;
  max-height: calc(100vh - 58px - var(--strip-h));
  overflow-y: auto;
}
.sidebar-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-soft); margin: 14px 6px 6px;
}
.model-list { display: flex; flex-direction: column; gap: 4px; }
.model-btn {
  text-align: left; font: inherit; font-weight: 600;
  background: transparent; border: 1px solid transparent;
  padding: 9px 12px; border-radius: 6px; cursor: pointer; color: var(--ink);
}
.model-btn:hover { background: #E9EBE7; }
.model-btn.active {
  background: var(--panel); border-color: var(--line);
  border-left: 4px solid var(--orange);
}

.workspace {
  flex: 1; padding: 18px 22px 0; min-width: 0;
  display: grid; grid-template-columns: minmax(360px, 48%) 1fr;
  gap: 18px; align-items: start;
}
/* Coluna dos seletores rola sozinha, com barra sempre visível */
#config-sections {
  max-height: calc(100vh - 58px - var(--strip-h) - 26px);
  overflow-y: scroll;
  padding-right: 10px; padding-bottom: 20px;
  scrollbar-gutter: stable;
}
#config-sections::-webkit-scrollbar { width: 12px; }
#config-sections::-webkit-scrollbar-track { background: #E6E8E4; border-radius: 6px; }
#config-sections::-webkit-scrollbar-thumb {
  background: #9AA1AA; border-radius: 6px; border: 2px solid #E6E8E4;
}
#config-sections::-webkit-scrollbar-thumb:hover { background: var(--orange); }

/* ---------- Diagrama ---------- */
.diagram-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px;
  position: sticky; top: 76px;
}
.diagram-panel img, .diagram-panel canvas { width: 100%; height: auto; display: block; }
.diagram-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.diagram-hint { font-size: 12.5px; color: var(--ink-soft); flex: 1; }
.btn-mini {
  background: transparent; color: var(--ink); border-color: var(--line);
  font-size: 12px; padding: 6px 10px; white-space: nowrap; border: 1px solid var(--line);
}
.btn-mini:hover { border-color: var(--orange); color: var(--orange); }

/* ---------- Seções de configuração ---------- */
.section {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: 14px; overflow: hidden;
}
.section-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.section-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.section-head h3 { font-size: 14px; font-weight: 700; }
.section-head .section-en { font-size: 12px; color: var(--ink-soft); font-weight: 400; }
.section-body {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px 18px; padding: 14px 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.pos-tag {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  background: var(--ink); color: #fff; border-radius: 3px; padding: 1px 6px;
}
.field-control { display: flex; align-items: center; gap: 8px; }
.field-control select {
  flex: 1; font: inherit; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
  cursor: pointer; min-width: 0;
}
.field-control select:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
.swatch {
  width: 34px; height: 34px; border-radius: 6px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.18);
  background:
    linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%),
    linear-gradient(45deg, #ddd 25%, #fff 25%, #fff 75%, #ddd 75%);
  background-size: 12px 12px; background-position: 0 0, 6px 6px;
}
.field-meta { font-size: 11px; color: var(--ink-soft); font-family: var(--mono); }
.confirm-note {
  font-size: 11.5px; color: #B45309; background: #FEF3C7;
  border-radius: 4px; padding: 2px 7px; display: inline-block; margin-top: 3px;
}

/* ---------- Faixa do código ---------- */
.code-strip {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--steel); color: #fff;
  border-top: 3px solid var(--orange);
  min-height: var(--strip-h);
}
.code-strip-inner {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px; flex-wrap: wrap;
}
.code-segments { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; min-width: 260px; }
.code-seg { text-align: center; }
.code-seg-val {
  font-family: var(--mono); font-weight: 700; font-size: 15px;
  background: #3A4048; border-radius: 4px; padding: 4px 7px;
  min-width: 30px; display: block; border-bottom: 3px solid transparent;
}
.code-seg-pos { font-size: 9.5px; color: #9AA1AA; font-family: var(--mono); display: block; margin-top: 2px; }
.code-seg.seg-prefix .code-seg-val { background: var(--orange); }
.code-seg.seg-P .code-seg-val { border-bottom-color: #C9CDD3; }
.code-seg.seg-E .code-seg-val { border-bottom-color: #60A5FA; }
.code-seg.seg-A .code-seg-val { border-bottom-color: #FBBF24; }
.code-seg.seg-PU .code-seg-val { border-bottom-color: #C084FC; }
.code-seg.seg-TIPO .code-seg-val { border-bottom-color: #2DD4BF; }

.code-final { display: flex; align-items: center; gap: 18px; }
.code-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: #9AA1AA; }
.code-value { font-family: var(--mono); font-size: 13px; color: #E4E7EB; word-break: break-all; }
.code-value-big { font-size: 19px; font-weight: 700; color: #fff; }
.code-actions { display: flex; gap: 8px; }

.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border-radius: 6px; padding: 10px 18px; border: 1px solid transparent;
}
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: #D64A16; }
.btn-ghost { background: transparent; color: inherit; border-color: currentColor; opacity: 0.85; }
.btn-ghost:hover { opacity: 1; }

/* ---------- Estoque ---------- */
.estoque-wrap { flex: 1; padding: 20px; }
.estoque-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.stage-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.stage-filter {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 20px; padding: 6px 14px; color: var(--ink);
}
.stage-filter.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.estoque-tools { display: flex; gap: 8px; }
.estoque-tools input {
  font: inherit; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 6px; width: 260px; background: #fff;
}
.estoque-list { display: flex; flex-direction: column; gap: 10px; }
.estoque-empty { color: var(--ink-soft); padding: 40px; text-align: center; }

.item-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 16px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 6px 18px; align-items: center;
}
.item-serial { font-family: var(--mono); font-weight: 700; font-size: 15px; }
.item-model { font-weight: 700; }
.item-code { font-family: var(--mono); font-size: 13px; color: var(--ink-soft); word-break: break-all; }
.item-meta { font-size: 12.5px; color: var(--ink-soft); grid-column: 2; }
.item-stage {
  font-size: 12px; font-weight: 700; color: #fff;
  border-radius: 4px; padding: 4px 10px; text-align: center; white-space: nowrap;
}
.item-actions { display: flex; gap: 6px; grid-column: 3; }
.item-actions .btn { padding: 6px 12px; font-size: 13px; }
.btn-danger { color: #B91C1C; border-color: #B91C1C; }
.item-nf { font-family: var(--mono); font-size: 12px; }
.stage-history { font-size: 11.5px; color: var(--ink-soft); grid-column: 1 / -1; }

/* ---------- Modal / etiqueta ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 22, 26, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--panel); border-radius: 10px; max-width: 560px; width: 100%;
  max-height: 92vh; overflow-y: auto;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 16px; }
.modal-close {
  font-size: 26px; line-height: 1; background: none; border: none;
  cursor: pointer; color: var(--ink-soft);
}
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); }
.field-inline { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; margin-bottom: 10px; }
.field-inline input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions .btn-ghost { color: var(--ink); }

/* A etiqueta em si */
.label-sheet {
  margin: 18px; border: 2px solid var(--ink); border-radius: 4px;
  font-size: 13px; background: #fff;
}
.label-head {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--ink); color: #fff; padding: 10px 14px;
}
.label-brand { font-weight: 800; letter-spacing: 0.18em; font-size: 18px; }
.label-brand span { color: var(--orange); }
.label-model { font-weight: 700; font-size: 15px; }
.label-code-block { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: center; }
.label-code {
  font-family: var(--mono); font-weight: 700; font-size: 21px; word-break: break-all;
}
.label-nomus { font-family: var(--mono); font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; word-break: break-all; }
.label-grid { width: 100%; border-collapse: collapse; }
.label-grid td {
  border-top: 1px solid var(--line); padding: 5px 10px; font-size: 12px; vertical-align: top;
}
.label-grid td:first-child {
  font-family: var(--mono); font-weight: 700; width: 44px;
  border-right: 1px solid var(--line); text-align: center;
}
.label-grid .label-section-row td {
  background: #EEF0EC; font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.label-foot {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 14px; border-top: 2px solid var(--ink);
  font-size: 11.5px; font-family: var(--mono);
}

/* ---------- Impressão: só a etiqueta ---------- */
@media print {
  body * { visibility: hidden; }
  .label-sheet, .label-sheet * { visibility: visible; }
  .label-sheet {
    position: fixed; left: 0; top: 0; margin: 0;
    width: 100mm; border-width: 1.5pt;
  }
  .code-strip, .topbar { display: none; }
}

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; padding-bottom: 30px; }
  .diagram-panel { position: static; }
  .diagram-panel img, .diagram-panel canvas { max-height: 300px; width: auto; max-width: 100%; margin: 0 auto; }
  #config-sections { max-height: none; overflow-y: visible; padding-right: 0; }
}

@media (max-width: 900px) {
  .view { flex-direction: column; }
  .sidebar {
    width: 100%; position: static; max-height: none;
    display: flex; gap: 16px; overflow-x: auto; padding: 10px 14px;
  }
  .sidebar .model-list { flex-direction: row; flex-wrap: wrap; }
  .code-strip-inner { gap: 10px; }
  :root { --strip-h: 190px; }
}

@media (prefers-reduced-motion: no-preference) {
  .code-seg-val { transition: background-color 160ms ease; }
  .section { animation: rise 220ms ease; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}
