html {
  font-size: 14px;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: #f3f6fb;
  color: #102033;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 0.1rem #fff, 0 0 0 0.25rem #258cfb;
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
  text-align: start;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar-toggle {
  position: fixed;
  opacity: 0;
  pointer-events: none;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 1040;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid #dbe3ef;
  box-shadow: 10px 0 30px rgba(15, 23, 42, .04);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 14px;
  border-bottom: 1px solid #eef2f7;
}

.sidebar-brand a,
.mobile-brand {
  color: #0f172a;
  font-size: 20px;
  font-weight: 800;
  text-decoration: none;
}

.sidebar-close {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-nav a {
  display: block;
  padding: 11px 12px;
  border-radius: 8px;
  color: #334155;
  font-weight: 600;
  text-decoration: none;
}

.sidebar-nav a:hover {
  background: #eef4ff;
  color: #0d6efd;
}

.sidebar-account {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 12px 10px 4px;
  border-top: 1px solid #eef2f7;
}

.sidebar-user {
  color: #64748b;
  font-size: 14px;
  word-break: break-word;
}

.sidebar-backdrop,
.mobile-header {
  display: none;
}

.main-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content-body {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px;
  flex: 1;
}

.app-footer {
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  padding: 18px 28px;
  border-top: 1px solid #dbe3ef;
}

.auth-card {
  max-width: 420px;
  margin: 48px auto;
  padding: 28px;
  background: #fff;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
}

.auth-card h1,
.main-menu h1 {
  font-size: 28px;
  margin-bottom: 20px;
}

.main-menu {
  max-width: 980px;
  margin: 12px auto 36px;
}

.menu-grid,
.template-grid {
  display: grid;
  gap: 18px;
}

.menu-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.template-page {
  width: 100%;
}

.page-header-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 20px 22px;
  background: #fff;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
}

.page-header-card h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
}

.page-header-card p {
  margin: 6px 0 0;
  color: #64748b;
}

.template-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 420px));
  align-items: start;
}

.menu-card,
.template-card,
.empty-state {
  display: block;
  background: #fff;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  color: #102033;
  text-decoration: none;
}

.menu-card {
  padding: 24px;
}

.menu-card strong,
.menu-card span {
  display: block;
}

.menu-card span {
  color: #64748b;
  margin-top: 8px;
}

.empty-state {
  padding: 28px;
}

.template-card {
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}

.template-preview {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #eef4fb;
}

.template-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.template-placeholder {
  color: #64748b;
}

.template-card-body {
  padding: 16px;
}

.template-card h2 {
  font-size: 18px;
  margin: 0 0 6px;
  overflow-wrap: anywhere;
}

.template-card p {
  color: #64748b;
}

.log-filter {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

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

.designer-page {
  width: 100%;
  display: grid;
  grid-template-columns: 250px minmax(360px, 1fr) 250px;
  gap: 14px;
  align-items: start;
}

.designer-panel,
.designer-topbar {
  background: #fff;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  padding: 14px;
}

.designer-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 56px);
  overflow: auto;
}

.designer-panel-title span {
  display: block;
  color: #2563eb;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.designer-workspace {
  min-width: 0;
}

.designer-topbar {
  margin-bottom: 12px;
}

.designer-topbar h1 {
  font-size: 24px;
  margin: 0;
}

.designer-topbar p {
  color: #64748b;
  margin: 4px 0 0;
}

.canvas-zoom-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin: 0 0 12px;
  max-width: 100%;
  flex-wrap: nowrap;
}

.canvas-zoom-toolbar button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}

.canvas-zoom-toolbar #resetZoomButton {
  width: 70px;
}

.canvas-zoom-toolbar #zoomPercent {
  display: block;
  width: 100%;
  text-align: center;
}

.designer-stage {
  height: 620px;
  max-width: 100%;
  overflow: auto;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  background-color: #edf4fb;
  background-image:
    linear-gradient(#dbe7f3 1px, transparent 1px),
    linear-gradient(90deg, #dbe7f3 1px, transparent 1px);
  background-size: 20px 20px;
}

.canvas-viewport {
  width: 100%;
  height: 620px;
  overflow: auto;
  position: relative;
}

.canvas-stage {
  min-width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.designer-stage.is-dragging {
  outline: 3px solid #2563eb;
}

.canvas-container {
  flex: 0 0 auto;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .12);
}

.sheet-preview {
  flex: 0 0 auto;
  max-width: none;
  background: #fff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .12);
}

.designer-layer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.designer-layer-item {
  border: 1px solid #dbe3ef;
  border-radius: 6px;
  padding: 10px;
  text-align: left;
  background: #f8fafc;
}

.designer-layer-item.active {
  border-color: #2563eb;
  background: #eaf1ff;
}

.designer-message {
  border-radius: 6px;
  padding: 10px;
  background: #e9f8ef;
  color: #166534;
}

.designer-message.error {
  background: #fee2e2;
  color: #991b1b;
}

.csv-panel {
  border: 1px solid #dbe3ef;
  border-radius: 6px;
  padding: 10px;
  background: #f8fafc;
}

.csv-columns {
  color: #475569;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.print-area {
  display: none;
}

@media (max-width: 1199.98px) {
  .designer-page {
    grid-template-columns: 230px minmax(320px, 1fr);
  }

  .designer-page > .designer-panel:last-child {
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 991.98px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 240px;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }

  .sidebar-toggle:checked ~ .app-shell .sidebar {
    transform: translateX(0);
  }

  .sidebar-toggle:checked ~ .app-shell .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1030;
    background: rgba(15, 23, 42, .36);
  }

  .sidebar-close {
    display: flex;
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 58px;
    padding: 0 16px;
    background: #fff;
    border-bottom: 1px solid #dbe3ef;
  }

  .hamburger {
    width: 38px;
    height: 38px;
    display: grid;
    place-content: center;
    gap: 5px;
    border: 1px solid #dbe3ef;
    border-radius: 8px;
    cursor: pointer;
  }

  .hamburger span {
    width: 18px;
    height: 2px;
    display: block;
    background: #102033;
  }

  .content-body {
    padding: 18px;
  }

  .app-footer {
    padding: 16px 18px;
  }

  .designer-page {
    grid-template-columns: 1fr;
  }

  .designer-panel {
    max-height: none;
  }
}

@media (max-width: 575.98px) {
  .content-body {
    padding: 14px;
  }

  .page-header-card {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .page-header-card h1 {
    font-size: 24px;
  }

  .template-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .template-card {
    max-width: none;
  }

  .canvas-zoom-toolbar button {
    width: 36px;
    height: 36px;
  }

  .canvas-zoom-toolbar #resetZoomButton {
    width: 64px;
  }

  .designer-stage {
    height: 460px;
  }

  .canvas-stage {
    padding: 18px;
  }
}

@page {
  size: var(--print-width) var(--print-height);
  margin: 0;
}

@media print {
  html,
  body {
    width: var(--print-width);
    min-height: var(--print-height);
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  body.is-printing,
  body.printing {
    width: var(--print-width) !important;
    min-height: var(--print-height) !important;
  }

  body.is-printing > :not(#printArea),
  body.printing > :not(#printArea) {
    display: none !important;
  }

  body.is-printing #printArea,
  body.printing #printArea {
    display: block !important;
    visibility: visible !important;
    width: var(--print-width) !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  body.is-printing .print-sticker,
  body.printing .print-sticker {
    display: block !important;
    visibility: visible !important;
    width: var(--print-width) !important;
    height: var(--print-height) !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    page-break-inside: avoid;
    break-inside: avoid;
    break-after: page;
    background: #fff !important;
  }

  body.is-printing .print-sticker:last-child,
  body.printing .print-sticker:last-child {
    break-after: auto;
  }

  body.is-printing .print-sticker img,
  body.printing .print-sticker img {
    display: block !important;
    visibility: visible !important;
    width: var(--print-width) !important;
    height: var(--print-height) !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain;
    transform: none !important;
    zoom: 1 !important;
  }
}
