:root {
  --navy: #002060;
  --navy-dark: #001645;
  --teal: #104862;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --emerald: #047857;
  --danger: #dc2626;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.w-full { width: 100%; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 18px; }

/* LOGIN */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #001645 0%, #002060 45%, #104862 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.login-brand {
  text-align: center;
  margin-bottom: 22px;
}

.login-logo {
  max-height: 68px;
  object-fit: contain;
  margin-bottom: 10px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
  color: var(--navy);
  letter-spacing: 0.4px;
}

.login-brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-hint {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* TOPBAR */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--navy);
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.16);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo {
  height: 38px;
  background: #fff;
  padding: 3px 6px;
  border-radius: 6px;
}

.topbar-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.4px;
}

.topbar-sub {
  font-size: 11px;
  opacity: 0.82;
}

.topnav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-btn {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.nav-btn.active {
  background: #fff;
  color: var(--navy);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 4px;
}

.user-name {
  font-weight: 600;
  font-size: 13px;
}

/* MAIN LAYOUT */
.main-content {
  padding: 16px 20px 28px;
  max-width: 1620px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.card-title {
  margin: 0;
  font-size: 16px;
  color: var(--navy);
}

.workspace-grid {
  display: grid;
  grid-template-columns: 450px 1fr;
  gap: 16px;
  align-items: start;
}

.editor-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-block {
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 14px;
}

.section-block:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.section-label {
  font-weight: 700;
  font-size: 13px;
  color: var(--navy);
  margin-bottom: 8px;
  display: block;
}

.section-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.section-label-row .section-label {
  margin-bottom: 0;
}

/* FORMS & CONTROLS */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

input[type='text'],
input[type='password'],
input[type='number'],
input[type='search'],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(0, 32, 96, 0.2);
  border-color: var(--navy);
}

.input-sm {
  padding: 5px 8px !important;
  font-size: 12px !important;
  width: auto !important;
}

.seg-group {
  display: flex;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 8px;
  gap: 3px;
}

.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--navy);
  color: #fff;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip-scroll {
  max-height: 92px;
  overflow-y: auto;
  padding-right: 4px;
}

.chip {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #1e293b;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.12s;
}

.chip:hover {
  border-color: var(--navy);
  background: #eff6ff;
  color: var(--navy);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}

/* BUTTONS */
.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s, background 0.15s;
}

.btn:hover { opacity: 0.92; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-lg { padding: 10px 16px; font-size: 14px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-primary { background: var(--navy); color: #fff; }
.btn-secondary { background: var(--teal); color: #fff; }
.btn-emerald { background: var(--emerald); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.topbar .btn-outline { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.35); color: #fff; }
.btn-ghost { background: transparent; color: inherit; border-color: transparent; }
.topbar .btn-ghost { color: #e2e8f0; }

.link-btn {
  border: none;
  background: none;
  color: var(--teal);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #e2e8f0;
  color: #1e293b;
}

.badge-navy { background: var(--navy); color: #fff; }
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-user { background: #dbeafe; color: #1e40af; }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-off { background: #fee2e2; color: #991b1b; }

.hint-sm {
  font-size: 12px;
  color: var(--muted);
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 12.5px;
}

.flex-gap-sm {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* PREVIEW PANEL */
.preview-panel {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 7px;
}

.zoom-val {
  font-size: 12px;
  font-weight: 700;
  min-width: 40px;
  text-align: center;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-canvas {
  background: #cbd5e1;
  border-radius: 8px;
  padding: 22px;
  min-height: 620px;
  max-height: calc(100vh - 220px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.preview-item-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.preview-item-caption {
  font-size: 12px;
  font-weight: 700;
  color: #1e293b;
  background: rgba(255, 255, 255, 0.85);
  padding: 2px 10px;
  border-radius: 999px;
}

.preview-scale-box {
  position: relative;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.25);
  background: #fff;
}

/* EXACT MILLIMETER LABEL DOM RENDERER */
.label-outer {
  background: #ffffff;
  border: 0.26mm solid #000000;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Times New Roman', Times, serif;
  font-weight: 700;
  transform-origin: top left;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.label-inner {
  border: 1.05mm solid #002060;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  overflow: hidden;
}

.label-band-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2mm 4mm;
  box-sizing: border-box;
  flex-shrink: 0;
}

.label-band-logo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.label-band-company {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #104862;
  padding: 0 2mm;
  line-height: 1.15;
  flex-shrink: 0;
}

.label-band-period {
  background: #002060;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 2mm;
  line-height: 1.15;
  flex-shrink: 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.label-band-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #002060;
  padding: 1.5mm 3mm;
  overflow: hidden;
}

.content-part {
  width: 100%;
  text-align: center;
  color: #002060;
  font-weight: 700;
  white-space: pre-wrap;
  word-break: break-word;
}

.content-part-doctype,
.content-part-project {
  line-height: 1.18;
}

.content-part-note {
  line-height: 1.2;
}

.label-band-dates {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.label-band-dates.stacked {
  flex-direction: column;
}

.label-band-dates.inline {
  flex-direction: row;
}

.date-box {
  display: flex;
  border: 0.53mm solid #000000;
  box-sizing: border-box;
  color: #104862;
  background: #ffffff;
}

.label-band-dates.stacked .date-box + .date-box {
  border-top: none;
}

.date-box-label {
  border-right: 0.26mm solid #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.5mm;
  white-space: nowrap;
}

.date-box-value {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.5mm;
  white-space: nowrap;
}

.label-band-footer {
  background: #002060;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 2mm;
  line-height: 1.15;
  flex-shrink: 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* BATCH & LIBRARY TABLES */
.batch-top-grid,
.library-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.checklist-box {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  max-height: 190px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #f8fafc;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  cursor: pointer;
}

.batch-queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid #e2e8f0;
  padding: 8px 10px;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
}

.data-table tr:hover td {
  background: #f8fafc;
}

.logo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.logo-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8fafc;
}

.logo-card img {
  height: 64px;
  width: 100%;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
  padding: 4px;
}

/* MODALS & TOASTS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.modal-wide {
  max-width: 860px;
}

.modal-card h3 {
  margin: 0;
  color: var(--navy);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  max-width: 360px;
}

.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

/* PRINT STAGE */
#print-stage {
  display: none;
}

@page portraitPage {
  size: A4 portrait;
  margin: 0;
}

@page landscapePage {
  size: A4 landscape;
  margin: 0;
}

@media print {
  body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #login-view,
  #app-view,
  .modal-backdrop,
  #toast-container {
    display: none !important;
  }

  #print-stage {
    display: block !important;
  }

  .print-page {
    position: relative;
    overflow: hidden;
    page-break-after: always;
    break-after: page;
  }

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

  .print-page-portrait {
    page: portraitPage;
    width: 210mm;
    height: 297mm;
  }

  .print-page-landscape {
    page: landscapePage;
    width: 297mm;
    height: 210mm;
  }

  .print-slot {
    position: absolute;
  }
}

@media (max-width: 1024px) {
  .workspace-grid,
  .batch-top-grid,
  .library-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Import from Excel drop zone ─────────────────────────────────────── */
.import-drop-zone {
  border: 2px dashed #94a3b8;
  border-radius: 10px;
  background: #f8fafc;
  padding: 24px 16px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}
.import-drop-zone.drag-over {
  border-color: #002060;
  background: #e8f0fe;
}
.import-drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #475569;
  font-size: 14px;
}
.import-drop-icon {
  font-size: 36px;
  line-height: 1;
}
.import-errors-list {
  margin: 6px 0 0 0;
  padding-left: 20px;
  font-size: 12.5px;
  color: #dc2626;
  line-height: 1.6;
}
/* ── End Import styles ───────────────────────────────────────────────── */
