:root {
  color-scheme: light;
  --bg: #eef1f0;
  --surface: #ffffff;
  --surface-2: #f6f7f7;
  --ink: #17201e;
  --muted: #62706c;
  --line: #d8dddb;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(23, 32, 30, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Be Vietnam Pro", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

img {
  display: block;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), transparent 44%),
    linear-gradient(225deg, rgba(180, 35, 24, 0.08), transparent 42%),
    #edf1f0;
}

.auth-card {
  width: min(100%, 360px);
  display: grid;
  gap: 16px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: #102421;
  color: #f8faf9;
  font-weight: 800;
  letter-spacing: 0;
}

.auth-card h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.12;
}

.auth-card p {
  margin: -10px 0 2px;
  color: var(--muted);
}

label {
  display: grid;
  gap: 7px;
  color: #33413d;
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cbd3d0;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.primary-button,
.icon-text-button,
.quiet-button,
.secondary-button,
.tool-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 6px;
  font-weight: 750;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover,
.icon-text-button:hover {
  background: var(--accent-strong);
}

.primary-button img,
.icon-text-button img {
  filter: brightness(0) invert(1);
}

.icon-text-button {
  padding: 0 13px;
  background: var(--accent);
  color: #ffffff;
}

.quiet-button,
.secondary-button {
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.quiet-button:hover,
.secondary-button:hover,
.tool-button:hover,
.icon-button:hover {
  background: #eef5f3;
}

.tool-button {
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: #2d3a36;
}

.tool-button.compact {
  width: 40px;
  padding: 0;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.icon-mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.icon-mini-button img {
  width: 15px;
  height: 15px;
}

.icon-button.danger:hover {
  background: #fff1f0;
}

.icon-button.danger img,
.icon-mini-button.danger img {
  filter: invert(17%) sepia(98%) saturate(2613%) hue-rotate(355deg) brightness(83%) contrast(91%);
}

.icon-mini-button.danger:hover {
  background: #fff1f0;
}

.primary-button img,
.icon-text-button img,
.quiet-button img,
.secondary-button img,
.tool-button img,
.icon-button img {
  width: 18px;
  height: 18px;
}

.form-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.title-stack {
  display: grid;
  gap: 2px;
}

.eyebrow {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.title-stack h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #cfe0dc;
  border-radius: 999px;
  background: #edf8f5;
  color: #0e5d56;
  font-size: 13px;
  font-weight: 750;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(248px, 300px) minmax(460px, 1fr) minmax(260px, 340px);
  gap: 16px;
  min-height: 0;
  padding: 16px;
}

.panel,
.main-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(23, 32, 30, 0.06);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.source-panel {
  max-height: calc(100vh - 106px);
}

.add-student-form {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.search-box {
  position: relative;
  margin: 14px 14px 10px;
}

.search-box img {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 17px;
  height: 17px;
  opacity: 0.58;
  pointer-events: none;
}

.search-box input {
  padding-left: 34px;
}

.class-filters {
  display: grid;
  gap: 8px;
  padding: 0 14px 12px;
}

.class-chip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid #d7ddda;
  border-radius: 6px;
  background: #ffffff;
  font-size: 13px;
  font-weight: 700;
}

.class-chip span:nth-child(2) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.class-chip input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.class-chip span:last-child {
  color: var(--muted);
  font-weight: 700;
}

.data-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-block: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.select-summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 24px;
}

.select-summary input,
.student-check {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.student-list {
  overflow: auto;
  padding: 8px;
}

.student-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 6px;
}

.student-row:hover,
.student-row.is-active {
  background: #eef5f3;
}

.student-pick {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 24px;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.student-pick:hover {
  background: transparent;
}

.student-pick strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.student-pick span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.main-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: calc(100vh - 106px);
  overflow: hidden;
}

.modebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}

.segment {
  min-height: 32px;
  padding: 0 14px;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment.is-active {
  background: #ffffff;
  color: var(--accent-strong);
  box-shadow: 0 1px 3px rgba(23, 32, 30, 0.12);
}

.badge-size,
.print-settings {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge-size label,
.print-settings label,
.check-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.badge-size input,
.print-settings input {
  width: 72px;
  min-height: 32px;
  padding: 5px 7px;
}

.mode-view {
  min-height: 0;
}

#design-view {
  display: grid;
  grid-template-rows: auto 1fr;
}

.toolstrip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.canvas-stage {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 28px;
  background:
    linear-gradient(90deg, rgba(23, 32, 30, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(23, 32, 30, 0.06) 1px, transparent 1px),
    #e2e7e5;
  background-size: 18px 18px;
}

.badge-canvas {
  position: relative;
  width: min(100%, 760px);
  aspect-ratio: 90 / 55;
  overflow: hidden;
  border: 1px solid #aeb8b5;
  background: #ffffff;
  box-shadow: 0 22px 64px rgba(23, 32, 30, 0.22);
}

.badge-background,
.badge-layer-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.badge-element {
  position: absolute;
  display: flex;
  align-items: center;
  min-width: 2%;
  min-height: 2%;
  overflow: hidden;
  user-select: none;
}

.design-element {
  cursor: move;
}

.design-element.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.design-element.is-selected::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  border-left: 2px solid var(--accent);
  border-top: 2px solid var(--accent);
  background: #ffffff;
  cursor: nwse-resize;
}

.badge-field,
.badge-text {
  width: 100%;
  padding: 2px 4px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
}

.badge-qr {
  display: grid;
  place-items: center;
}

.badge-qr img {
  width: min(100%, 100%);
  height: min(100%, 100%);
  object-fit: contain;
}

.badge-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.badge-shape {
  background: transparent;
}

.badge-line {
  min-height: 2px;
}

.print-preview-mode {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.print-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.check-row input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.print-fit-note {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #d7e5df;
  border-radius: 6px;
  background: #f0faf6;
  color: #0f5f55;
  font-size: 13px;
  font-weight: 750;
}

.print-preview {
  overflow: auto;
  padding: 24px;
  background: #dde3e0;
}

.preview-page-shell {
  width: calc(210mm * var(--preview-scale));
  height: calc(297mm * var(--preview-scale));
  margin: 0 auto 22px;
}

.preview-page-shell .print-page {
  transform: scale(var(--preview-scale));
  transform-origin: top left;
}

.print-output {
  display: none;
}

.print-page {
  position: relative;
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 12px 34px rgba(23, 32, 30, 0.18);
  break-inside: avoid;
  page-break-inside: avoid;
}

.print-grid {
  display: grid;
  width: 100%;
  height: 100%;
}

.badge-card {
  position: relative;
  overflow: hidden;
  background: #ffffff;
  break-inside: avoid;
  page-break-inside: avoid;
}

.badge-card.has-crop::before,
.badge-card.has-crop::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.badge-card.has-crop::before {
  border: 0.2mm solid rgba(23, 32, 30, 0.4);
}

.badge-card.has-crop::after {
  background:
    linear-gradient(#17201e, #17201e) left top / 3mm 0.2mm no-repeat,
    linear-gradient(#17201e, #17201e) left top / 0.2mm 3mm no-repeat,
    linear-gradient(#17201e, #17201e) right top / 3mm 0.2mm no-repeat,
    linear-gradient(#17201e, #17201e) right top / 0.2mm 3mm no-repeat,
    linear-gradient(#17201e, #17201e) left bottom / 3mm 0.2mm no-repeat,
    linear-gradient(#17201e, #17201e) left bottom / 0.2mm 3mm no-repeat,
    linear-gradient(#17201e, #17201e) right bottom / 3mm 0.2mm no-repeat,
    linear-gradient(#17201e, #17201e) right bottom / 0.2mm 3mm no-repeat;
  opacity: 0.42;
}

.inspector-panel {
  max-height: calc(100vh - 106px);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 200px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  font-weight: 650;
}

.inspector-form {
  display: grid;
  gap: 12px;
  padding: 14px;
  overflow: auto;
}

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

.wide-field {
  grid-column: 1 / -1;
}

.style-props input[type="color"],
input[type="color"] {
  min-height: 38px;
  padding: 4px;
}

.inspector-check {
  justify-content: start;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.inspector-check input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

label:has(#prop-bg-color:disabled) {
  opacity: 0.62;
}

.inspector-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.inspector-actions .secondary-button {
  padding: 0 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 32, 30, 0.38);
}

.password-card {
  width: min(100%, 420px);
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 6px;
  background: #17201e;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

[hidden] {
  display: none !important;
}

@media (max-width: 1160px) {
  .workbench {
    grid-template-columns: 260px minmax(420px, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .workbench {
    grid-template-columns: 1fr;
  }

  .source-panel,
  .inspector-panel {
    max-height: none;
  }

  .modebar,
  .print-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .badge-size,
  .print-settings {
    align-items: stretch;
  }

  .canvas-stage,
  .print-preview {
    padding: 14px;
  }
}

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

@media print {
  html,
  body {
    width: 210mm;
    min-height: 297mm;
    background: #ffffff;
  }

  .auth-shell,
  .app-shell,
  .modal-backdrop,
  .toast {
    display: none !important;
  }

  .print-output {
    display: block !important;
  }

  .print-page {
    box-shadow: none;
    page-break-after: always;
    break-after: page;
  }

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