/* ============================================================
   Gerador de Etiquetas DIN — Estilos
   Mobile-first · Ajuste de Folha · Ofício
   ============================================================ */
:root {
  --bg:          #0f172a;
  --panel:       #1e293b;
  --panel-2:     #334155;
  --border:      #334155;
  --text:        #e2e8f0;
  --text-dim:    #94a3b8;
  --accent:      #3b82f6;
  --accent-hov:  #2563eb;
  --danger:      #ef4444;
  --success:     #10b981;
  --touch:       44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(60px + var(--safe-bottom));
  overflow-y: auto;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.brand {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.brand .logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--accent); color: #fff;
  font-weight: 800; border-radius: 8px; font-size: 12px;
}
.brand h1 { font-size: 15px; margin: 0; font-weight: 600; white-space: nowrap; }

.project-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 10px;
  height: 40px;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.project-input:focus {
  outline: none;
  border-color: var(--accent);
}

.toolbar-actions {
  display: flex; gap: 6px; align-items: center;
  flex-shrink: 0;
}

/* ---------- Botões ---------- */
.btn {
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  touch-action: manipulation;
  user-select: none;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:active { transform: scale(.97); }
.btn:hover   { background: #475569; }
.btn-primary   { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hov); }
.btn-danger    { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost     { background: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-block     { width: 100%; }
.btn-small     { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn-icon      { padding: 0 10px; }
.btn-icon span:not([aria-hidden]) { display: none; }

/* ---------- Dropdown ---------- */
.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 260px;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
  z-index: 60;
}
.dropdown.hidden { display: none; }
.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: transparent;
  border: none;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  font-family: inherit;
  min-height: var(--touch);
}
.dropdown-item:hover,
.dropdown-item:focus { background: var(--panel-2); outline: none; }
.dropdown-sep {
  height: 1px; background: var(--border); margin: 4px 0;
}

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  display: block;
  min-height: 0;
}
.config-panel {
  display: none;
  background: var(--panel);
  padding: 16px;
  padding-bottom: 80px;
  min-height: calc(100dvh - 60px);
}
.canvas-area {
  display: none;
  flex-direction: column;
  background: #1a2233;
  min-width: 0;
  min-height: calc(100dvh - 60px);
}
.layout[data-tab="config"] .config-panel { display: block; }
.layout[data-tab="canvas"] .canvas-area  { display: flex; }

.panel-section { margin-bottom: 22px; }
.panel-section h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin: 0 0 10px;
}
.panel-section h3 { font-size: 13px; margin: 0 0 8px; }

/* ---------- Campos ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input[type="number"],
.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 16px;
  min-height: var(--touch);
  font-family: inherit;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 70px; line-height: 1.4; }
.field small { font-size: 12px; color: var(--text-dim); }
.field.inline { margin-top: 6px; }

.toggle {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); font-size: 15px;
  min-height: var(--touch);
  cursor: pointer;
}
.toggle input[type="checkbox"] {
  width: 22px; height: 22px;
  accent-color: var(--accent);
  cursor: pointer;
}

.zoom-row { display: flex; gap: 8px; align-items: center; }
.zoom-row input[type="range"] {
  flex: 1;
  height: 34px;
  accent-color: var(--accent);
}
.zoom-label { font-size: 12px; color: var(--text-dim); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.field input[type="color"] {
  width: 100%;
  height: var(--touch);
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

/* ---------- Rotação do texto ---------- */
.rotation-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.rotation-row input[type="number"] {
  flex: 1;
  min-width: 0;
}
.rotation-row .btn {
  flex-shrink: 0;
  min-width: 48px;
}

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.stat-label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.stat-value { display: block; font-size: 18px; font-weight: 700; color: var(--accent); }

.help { font-size: 12px; color: var(--text-dim); line-height: 1.6; }
.help strong { color: var(--text); }
.help .hint { margin-top: 8px; font-size: 12px; }

/* ---------- Canvas ---------- */
.canvas-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.canvas-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Etiqueta (strip) ---------- */
.label-strip {
  --scale:    1;
  --bw:       0.2;
  --pad:      0.5;
  --line-gap: 0.3;

  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0;
  background: #ffffff;
  width: max-content;
  height: max-content;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55);
  border-radius: 2px;
  transform-origin: top left;
}
.label-module {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;

  width:  calc(var(--w, 17.5) * 1mm * var(--scale));
  height: calc(var(--h, 45) * 1mm * var(--scale));
  font-size: calc(var(--fs, 5) * 1mm * var(--scale));
  padding: calc(var(--pad, 0.5) * 1mm * var(--scale));
  border: calc(var(--bw, 0.2) * 1mm * var(--scale)) solid #1f2937;

  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  line-height: 1.05;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  touch-action: manipulation;
  transition: box-shadow .15s, opacity .15s, transform .15s;
}
.label-module:active {
  box-shadow: inset 0 0 0 calc(0.5mm * var(--scale)) rgba(59,130,246,.9);
}
.label-module.is-spacer {
  border: none;
  background: transparent;
  pointer-events: none;
}

/* Estados de Arraste */
.label-module.dragging {
  opacity: 0.5;
  transform: scale(0.95);
  box-shadow: 0 0 0 calc(0.5mm * var(--scale)) var(--accent);
  z-index: 10;
}
.label-module.drag-over {
  box-shadow: inset 0 0 0 calc(0.5mm * var(--scale)) var(--success);
}

/* Container do texto */
.label-text {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--line-gap, 0.3) * 1mm * var(--scale));
  transform-origin: center center;
  transition: transform .12s ease-out;
}

.label-line {
  display: block;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.05;
}

/* ---------- Tab bar (mobile) ---------- */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 40;
}
.tab {
  flex: 1;
  min-height: 56px;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: manipulation;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); }
.tab.active .tab-icon { transform: scale(1.1); }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  padding: 0;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  width: 100%;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.6);
  animation: sheet-in .22s ease-out;
  padding-bottom: var(--safe-bottom);
}
@keyframes sheet-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { margin: 0; font-size: 16px; }
.btn-close {
  background: none; border: none;
  color: var(--text-dim);
  font-size: 28px; cursor: pointer;
  padding: 0;
  width: 40px; height: 40px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.btn-close:hover { color: var(--text); }
.modal-body { padding: 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.spacer { flex: 1; }

.guide-body section { margin-bottom: 20px; }
.guide-body h3 { font-size: 14px; margin: 0 0 8px; color: var(--accent); }
.guide-body p, .guide-body li { font-size: 14px; line-height: 1.55; }
.guide-list { padding-left: 18px; margin: 6px 0; }
.guide-list li { margin-bottom: 6px; }
.guide-list kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-2);
  font-size: 12px;
  font-family: ui-monospace, monospace;
}
.guide-warn {
  background: rgba(239, 68, 68, .08);
  border-left: 3px solid var(--danger);
  padding: 12px 14px;
  border-radius: 0 8px 8px 0;
}
.guide-warn h3 { color: #fca5a5; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.6);
  z-index: 2000;
  border: 1px solid var(--border);
  max-width: 90vw;
  text-align: center;
  animation: toast-in .2s ease-out;
}
.toast.hidden { display: none; }
@keyframes toast-in {
  from { transform: translate(-50%, 10px); opacity: 0; }
  to   { transform: translate(-50%, 0);    opacity: 1; }
}

/* ============================================================
   Desktop (≥ 900px)
   ============================================================ */
@media (min-width: 900px) {
  .hide-mobile { display: inline !important; }
  .btn-icon span:not([aria-hidden]) { display: inline; }

  body { padding-bottom: 0; overflow: auto; }

  .toolbar { padding: 12px 20px; gap: 16px; padding-top: 12px; }
  .toolbar-actions { margin-left: auto; }
  .dropdown { right: 20px; top: calc(100% + 8px); }

  .tab-bar { display: none; }

  .layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    align-items: start;
    flex: 1;
    min-height: calc(100vh - 64px);
  }
  .config-panel {
    display: flex !important;
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 64px);
    border-right: 1px solid var(--border);
    padding: 20px;
    padding-bottom: 40px;
  }
  .canvas-area {
    display: flex !important;
    flex-direction: column;
    height: calc(100vh - 64px);
    position: sticky;
    top: 64px;
    overflow: hidden;
  }
  .canvas-scroll { padding: 24px; flex: 1; }
}

@media (max-width: 360px) {
  .project-input { font-size: 14px; }
  .brand h1 { display: none; }
}

/* ============================================================
   Print 1:1 e Ajuste de Folha
   ============================================================ */
@media print {
  @page {
    size: auto; /* O navegador respeita o papel selecionado (Ofício) */
    margin: 0;  /* A margem é controlada pelo CSS interno */
  }

  html, body {
    background: #fff !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
    min-height: 0 !important;
    display: block !important;
    overflow: visible !important;
    -webkit-text-size-adjust: 100%;
  }

  .no-print,
  .toolbar,
  .config-panel,
  .canvas-header,
  .tab-bar,
  .modal,
  .toast,
  .dropdown { display: none !important; }

  .layout {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  .canvas-area {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  .canvas-scroll {
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    background: none !important;
    height: auto !important;
    /* Aplica a margem segura configurada para a impressão */
    padding: calc(var(--paper-margin, 10) * 1mm) !important;
  }
  .label-strip {
    --scale: var(--print-scale, 1) !important;
    box-shadow: none !important;
    background: none !important;
    margin: 0 auto !important; /* Centraliza na folha */
    padding: 0 !important;
    transform: none !important;
  }
  .label-module {
    box-shadow: none !important;
    cursor: default !important;
    outline: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .label-text { transition: none !important; }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
}