/**
 * Main Styles
 * AMR Label Maker V2
 */

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-main);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-app);
}

/* ===== App Layout ===== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  gap: var(--space-4);
}

/* ===== Sidebar ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  margin: var(--space-4);
  margin-right: 0;
  overflow: hidden;
}

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-color);
}

.sidebar__toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.sidebar__toggle:hover {
  background: var(--bg-input);
}

.sidebar__content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

/* ===== Brand ===== */
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand__logo {
  width: 60px;
  height: 60px;
  object-fit: contain;
}

.brand__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.brand__subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin: var(--space-1) 0 0;
}

/* ===== Preview Area ===== */
.preview {
  display: grid;
  place-items: center;
  min-height: calc(100vh - var(--space-8));
  background: var(--bg-panel);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  margin: var(--space-4);
  margin-left: 0;
  position: relative;
  overflow: hidden;
}

.preview__canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-base);
  pointer-events: none;
}

/* ===== Label Styles ===== */
.label {
  width: var(--label-w);
  height: var(--label-h);
  background: #fff;
  border-radius: var(--label-radius);
  box-shadow: 0 0 0 1px #cbd5e1 inset, var(--shadow-xl);
  overflow: hidden;
  position: relative;
  z-index: var(--z-dropdown);
  color: #0f172a;
}

.preview .label {
  transform: scale(var(--preview-scale));
  transform-origin: center;
}

.label__inner {
  position: absolute;
  inset: var(--label-pad);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2mm;
}

.label__content {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1mm;
  min-width: 0;
}

.label__web {
  font-size: 2.5mm;
  line-height: 1.1;
  letter-spacing: 0.1mm;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.label__name-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.3mm;
  min-width: 0;
}

.label__name {
  font-size: 3mm;
  line-height: 1.25;
  font-weight: 700;
  padding-top: 0.2mm;
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.label__dept {
  font-size: 2.2mm;
  line-height: 1.2;
  color: #374151;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.label__code {
  font-family: var(--font-mono);
  font-size: 2.5mm;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.12mm;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.label__qr {
  width: var(--qr-size);
  height: var(--qr-size);
  display: grid;
  place-items: center;
  border-radius: var(--label-radius);
  justify-self: end;
  align-self: center;
}

.label__qr img,
.label__qr canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#qrSlot {
  width: 100%;
  height: 100%;
  display: none;
}

#qrSlot canvas,
#qrSlot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Cut Guides */
.label.cut-guides::before,
.label.cut-guides::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.label.cut-guides::before {
  background: 
    repeating-linear-gradient(90deg, transparent 0 4mm, rgba(2, 6, 23, 0.06) 4mm 4.3mm),
    repeating-linear-gradient(0deg, transparent 0 4mm, rgba(2, 6, 23, 0.06) 4mm 4.3mm);
}

.label.cut-guides::after {
  box-shadow: inset 0 0 0 0.4mm rgba(2, 6, 23, 0.2);
  border-radius: var(--label-radius);
}

/* ===== Sheet Number Label ===== */
.sheet-label {
  width: 150mm;
  height: 100mm;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 4mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  position: relative;
}

.preview .sheet-label {
  transform: scale(calc(var(--preview-scale) / 4.5));
  transform-origin: center;
}

.sheet-label__number {
  font-size: 60mm;
  font-weight: 900;
  color: #0f172a;
  font-family: var(--font-main);
  line-height: 1;
  letter-spacing: -2mm;
  margin-bottom: 15mm;
}

.sheet-label__message {
  position: absolute;
  bottom: 6mm;
  left: 50%;
  transform: translateX(-50%);
  font-size: 7mm;
  color: #374151;
  font-family: var(--font-main);
  text-align: center;
  white-space: nowrap;
}

/* Sheet Print Container */
.sheet-print-container {
  display: none;
}

.sheet-print-container .sheet-page {
  width: 150mm;
  height: 100mm;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  page-break-after: always;
}

.sheet-print-container .sheet-page:last-child {
  page-break-after: auto;
}

.sheet-print-container .sheet-number-text {
  font-weight: 900;
  color: var(--text-primary);
  font-family: var(--font-main);
  line-height: 1;
  letter-spacing: -2mm;
  margin-bottom: 15mm;
}

.sheet-print-container .sheet-message {
  position: absolute;
  bottom: 6mm;
  left: 50%;
  transform: translateX(-50%);
  color: #374151;
  font-family: var(--font-main);
  text-align: center;
  white-space: nowrap;
}

/* ===== Action Bar ===== */
.action-bar {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  gap: var(--space-2);
  z-index: var(--z-fixed);
}

/* ===== Footer ===== */
.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--space-3);
  text-align: center;
  font-size: var(--text-xs);
  z-index: var(--z-sticky);
  pointer-events: none;
}

.app-footer__text {
  display: inline-block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  background: rgba(2, 6, 23, 0.75);
  color: #e5e7eb;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  backdrop-filter: saturate(120%) blur(2px);
}

/* ===== Print Styles ===== */
@media print {
  html,
  body {
    background: #fff;
    margin: 0;
    padding: 0;
  }

  .sidebar,
  .action-bar,
  .app-footer,
  #networkCanvas {
    display: none !important;
  }

  .app {
    display: block !important;
    min-height: 0 !important;
  }

  .preview {
    box-shadow: none !important;
    background: transparent !important;
    margin: 0 !important;
    padding: 0 !important;
    min-height: 0 !important;
    display: block !important;
  }

  /* Standard Label Print (single label) */
  body:not(.printing-sheets):not(.batch-printing) * {
    visibility: hidden !important;
  }

  body:not(.printing-sheets):not(.batch-printing) .label,
  body:not(.printing-sheets):not(.batch-printing) .label * {
    visibility: visible !important;
  }

  body:not(.printing-sheets):not(.batch-printing) .label {
    box-shadow: none !important;
    transform: none !important;
    position: fixed !important;
    top: 0;
    left: 0;
    width: var(--label-w) !important;
    height: var(--label-h) !important;
  }

  body:not(.printing-sheets):not(.batch-printing) .preview .label {
    transform: none !important;
  }

  /* Sheet Label Print */
  body.printing-sheets .app,
  body.printing-sheets .action-bar,
  body.printing-sheets .app-footer,
  body.printing-sheets .mobile-header {
    display: none !important;
  }

  body.printing-sheets .sheet-print-container {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    width: 150mm;
  }

  body.printing-sheets .sheet-print-container * {
    visibility: visible !important;
  }

  body.printing-sheets .sheet-print-container .sheet-page {
    box-shadow: none !important;
    border: none !important;
    width: 150mm !important;
    height: 100mm !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    background: #fff !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  body.printing-sheets .sheet-print-container .sheet-page:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  body.printing-sheets .sheet-print-container .sheet-number-text {
    font-weight: 900 !important;
    color: #000 !important;
    line-height: 1 !important;
    letter-spacing: -2mm !important;
  }

  body.printing-sheets .sheet-print-container .sheet-message {
    position: absolute !important;
    bottom: 6mm !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    color: #374151 !important;
    text-align: center !important;
    white-space: nowrap !important;
  }
}
