:root {
  color-scheme: dark;
  font-family: "DM Sans", "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --page: #0d121b;
  --panel: #151d29;
  --panel-raised: #1b2533;
  --line: #2a3646;
  --muted: #94a2b5;
  --text: #edf3fa;
  --blue: #4d9dff;
  --blue-hover: #69adff;
  --danger: #ff8585;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--page);
  font-size: 13px;
}

h1, h2, h3, .brand { font-family: "Manrope", "Segoe UI", sans-serif; }

button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #111823;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 650;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .04em;
}

.brand-mark {
  display: grid;
  width: 56px;
  height: 38px;
  flex: 0 0 56px;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.brand-mark-image .shared-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.back-link {
  color: #b8c6d8;
  text-decoration: none;
  font-size: 12px;
}
.back-link:hover { color: #fff; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.menu-toggle {
  display: grid;
  width: 34px;
  height: 34px;
  align-content: center;
  justify-items: center;
  gap: 4px;
  padding: 0;
  border: 1px solid #344255;
  border-radius: 7px;
  background: #1a2432;
  cursor: pointer;
}
.menu-toggle:hover, .menu-toggle[aria-expanded="true"] { border-color: var(--blue); background: #1a2a45; }
.menu-toggle span { width: 15px; height: 2px; border-radius: 2px; background: #dce6f2; }
.menu-toggle:focus-visible, .menu-install:focus-visible, .menu-link:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.menu-backdrop[hidden], .app-menu[hidden] { display: none; }
.menu-backdrop {
  position: fixed;
  z-index: 9000;
  inset: 58px 0 0;
  background: rgb(3 7 12 / 28%);
}
.app-menu {
  position: fixed;
  z-index: 9001;
  top: 66px;
  right: 12px;
  width: min(286px, calc(100vw - 24px));
  padding: 8px;
  border: 1px solid #34445b;
  border-radius: 10px;
  background: #151d29;
  box-shadow: 0 16px 42px rgb(0 0 0 / 42%);
  transform-origin: top right;
  animation: menu-slide-in 150ms ease-out;
}
@keyframes menu-slide-in {
  from { opacity: 0; transform: translateY(-7px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.menu-install {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  gap: 11px;
  padding: 10px;
  border: 1px solid #2a3a4f;
  border-radius: 7px;
  background: #1a2432;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.menu-install:hover:not(:disabled) { border-color: #4777b1; background: #202f43; }
.menu-install:disabled { border-color: #2a3646; background: #19222e; color: #c2ccda; opacity: 1; cursor: default; }
.menu-install > span:last-child { display: grid; min-width: 0; gap: 3px; }
.menu-install strong { display: block; font-size: 12px; font-weight: 650; line-height: 1.3; }
.menu-install small { display: block; color: var(--muted); font-size: 10px; line-height: 1.4; overflow-wrap: anywhere; }
.menu-install-icon {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border: 1px solid #3774bb;
  border-radius: 8px;
  background: #19385b;
  color: #b7d8ff;
  font-size: 21px;
}
.menu-status { margin: 3px 10px 6px; color: #ffb2a6; font-size: 10px; line-height: 1.45; }
.menu-status:empty { display: none; }
.menu-link { display: block; padding: 9px 10px; border-top: 1px solid #2a3646; color: #c8d3e1; font-size: 11px; text-decoration: none; }
.menu-link:hover { color: #fff; background: #1a2432; }

.workspace {
  display: grid;
  grid-template-columns: minmax(390px, 1.02fr) minmax(440px, 1fr);
  gap: 14px;
  width: 100%;
  height: calc(100vh - 58px);
  min-height: 0;
  margin: 0 auto;
  padding: 14px 18px 18px;
}

.left-column {
  display: grid;
  grid-template-rows: minmax(165px, .4fr) minmax(250px, 1.6fr) auto;
  gap: 12px;
  min-height: 0;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgb(0 0 0 / 12%);
}

.photo-panel, .crop-panel, .settings-panel, .preview-panel { padding: 13px; }
.photo-panel, .crop-panel, .settings-panel { min-height: 0; }
.photo-panel, .crop-panel { display: flex; flex-direction: column; }

.panel-heading {
  display: flex;
  min-height: 24px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-heading h1, .panel-heading h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
}

.panel-heading > span, .heading-actions, .page-navigation { color: var(--muted); font-size: 11px; }
.heading-actions { display: flex; align-items: center; gap: 10px; }
.text-button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #202b3a;
  cursor: pointer;
}
.text-button:hover:not(:disabled) { border-color: #4a6079; background: #27364a; }
.text-button.danger { color: var(--danger); }
.text-button:disabled { opacity: .45; cursor: not-allowed; }

.upload-button {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px dashed #48617d;
  border-radius: 7px;
  background: #192638;
  color: #dcecff;
  cursor: pointer;
  font-weight: 600;
}
.upload-button:hover { border-color: var(--blue); background: #1c2d43; }
.upload-button small { color: var(--muted); font-size: 10px; font-weight: 400; }

.photo-list {
  display: flex;
  flex: 1;
  gap: 8px;
  min-height: 52px;
  margin-top: 9px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-color: #43546a transparent;
}
.photo-list:empty { display: none; }

.photo-item {
  position: relative;
  display: flex;
  flex: 0 0 142px;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 52px;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: #111925;
  cursor: pointer;
  text-align: left;
}
.photo-item.selected { border-color: var(--blue); background: #172941; }
.photo-item > img { width: 38px; height: 42px; flex: 0 0 38px; border-radius: 4px; object-fit: cover; }
.photo-item-details { display: grid; flex: 1; gap: 4px; min-width: 0; }
.photo-item-name { overflow: hidden; color: #cad6e4; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.photo-item-details label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 9px; }
.photo-item-details input { width: 42px; height: 20px; padding: 0 4px; border: 1px solid #344255; border-radius: 4px; background: #101721; color: var(--text); font-size: 10px; }
.photo-remove {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 19px;
  height: 19px;
  padding: 0;
  border: 1px solid #29394d;
  border-radius: 5px;
  background: #111925eF;
  color: #fff;
  cursor: pointer;
}
.photo-remove:hover { background: #753c46; }
.status { min-height: 0; margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.status:empty { display: none; }

.crop-panel { position: relative; }
.crop-panel .panel-heading > span {
  overflow: hidden;
  max-width: 48%;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crop-frame {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 130px;
  overflow: hidden;
  border: 1px solid #29384b;
  border-radius: 7px;
  background-color: #090d13;
  background-image: linear-gradient(45deg, #111925 25%, transparent 25%), linear-gradient(-45deg, #111925 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #111925 75%), linear-gradient(-45deg, transparent 75%, #111925 75%);
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-size: 10px 10px;
}
.crop-frame img { display: block; max-width: 100%; }
.crop-empty {
  display: grid;
  flex: 1;
  min-height: 90px;
  place-items: center;
  border: 1px dashed #344256;
  border-radius: 7px;
  color: #75859a;
  background: #111925;
}
.crop-empty[hidden] { display: none; }
.crop-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin-top: 8px;
}
.control-label, .crop-tools output { color: #c8d3e1; font-size: 11px; }
.crop-tools input[type="range"] { flex: 1; min-width: 50px; accent-color: var(--blue); }
.crop-tools output { width: 37px; text-align: right; }
.icon-button {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #202b3a;
  color: #dce6f2;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.icon-button:hover:not(:disabled) { border-color: #4b6d95; background: #2a3a4e; }
.icon-button:disabled { opacity: .4; cursor: not-allowed; }
.apply-crop { align-self: flex-end; }

.primary-button, .secondary-button {
  min-height: 36px;
  padding: 0 15px;
  border: 1px solid #438de0;
  border-radius: 7px;
  background: #2879d0;
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}
.primary-button:hover:not(:disabled) { background: #388ce7; }
.secondary-button {
  border-color: #34475e;
  background: #202b3a;
  color: #e6edf6;
}
.secondary-button:hover:not(:disabled) { background: #2a3a4e; }
.primary-button:disabled, .secondary-button:disabled { opacity: .45; cursor: not-allowed; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px 10px;
}
.field { display: flex; min-width: 0; flex-direction: column; gap: 4px; color: #aebcce; font-size: 10px; }
.border-width-field[hidden] { display: none; }
.field input, .field select {
  width: 100%;
  height: 31px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid #344255;
  border-radius: 6px;
  background: #101721;
  color: var(--text);
  font-size: 11px;
}
.field select { padding-right: 21px; }
.unit-input { position: relative; display: block; }
.unit-input input { padding-right: 29px; }
.unit-input em {
  position: absolute;
  top: 8px;
  right: 8px;
  color: #7e8da0;
  font-size: 10px;
  font-style: normal;
}
.custom-paper { display: contents; }
.custom-paper[hidden] { display: none; }
.check-field {
  display: flex;
  align-items: center;
  align-self: end;
  gap: 7px;
  min-height: 31px;
  color: #d0d9e5;
  font-size: 11px;
  white-space: nowrap;
}
.check-field input { width: 14px; height: 14px; margin: 0; accent-color: var(--blue); }
.auto-center-field { grid-column: span 2; }
.validation { min-height: 13px; margin: 7px 0 0; color: #ff9e9e; font-size: 10px; }
.status.is-error { color: #ff9e9e; }

.preview-panel { display: flex; flex-direction: column; min-height: 0; }
.page-navigation { display: flex; align-items: center; gap: 8px; }
.page-navigation .icon-button { width: 25px; height: 25px; flex-basis: 25px; }
.preview-stage {
  display: grid;
  flex: 1;
  min-height: 240px;
  place-items: center;
  overflow: hidden;
  border: 1px solid #263243;
  border-radius: 8px;
  background: #0c1119;
}
.empty-preview { padding: 20px; color: #718197; text-align: center; }
.paper-preview {
  position: relative;
  flex: none;
  overflow: hidden;
  background: white;
  box-shadow: 0 10px 32px rgb(0 0 0 / 35%);
}
.preview-photo { position: absolute; overflow: hidden; background: #fff; }
.preview-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.preview-photo.bordered { outline: 1px solid #454545; outline-offset: -1px; }
.stats {
  display: flex;
  justify-content: center;
  gap: clamp(28px, 7vw, 90px);
  padding: 13px 0 12px;
}
.stats div { display: flex; align-items: baseline; gap: 7px; }
.stats strong { color: #f3f7fc; font-size: 16px; font-weight: 700; }
.stats span { color: var(--muted); font-size: 11px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.print-hint { margin: 9px 0 0; color: #77869a; font-size: 10px; text-align: right; }

.crop-modal[hidden] { display: none; }
.crop-modal {
  position: fixed;
  z-index: 10000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(3 7 12 / 82%);
  backdrop-filter: blur(3px);
}
.crop-modal-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  width: min(1280px, 100%);
  height: min(900px, 100%);
  min-width: 0;
  min-height: 0;
  padding: 16px;
  border: 1px solid #34445b;
  border-radius: 12px;
  background: #141c28;
  box-shadow: 0 24px 80px rgb(0 0 0 / 55%);
}
.crop-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
}
.crop-modal-header h2 { margin: 0; color: var(--text); font-size: 16px; font-weight: 650; }
.crop-modal-header span { display: block; max-width: min(70vw, 900px); margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.crop-modal-close { width: 34px; height: 34px; flex-basis: 34px; font-size: 22px; }
.crop-modal-stage {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  border: 1px solid #34445b;
  border-radius: 8px;
  background-color: #090d13;
  background-image: radial-gradient(#253143 .7px, transparent .7px);
  background-size: 12px 12px;
}
.crop-modal-frame { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; overflow: hidden; }
.crop-modal-frame img { display: block; max-width: 100%; }
.crop-modal-stage .cropper-container { background-color: transparent; }
.crop-modal-stage .cropper-view-box { outline: 2px solid #79aeff; outline-offset: -1px; }
.crop-modal-stage .cropper-line { background-color: #79aeff; }
.crop-modal-stage .cropper-point { width: 12px; height: 12px; border: 1px solid #08111e; border-radius: 3px; background-color: #dcecff; opacity: 1; }
.crop-modal-stage .cropper-point.point-ne { right: -6px; top: -6px; }
.crop-modal-stage .cropper-point.point-nw { left: -6px; top: -6px; }
.crop-modal-stage .cropper-point.point-se { right: -6px; bottom: -6px; }
.crop-modal-stage .cropper-point.point-sw { left: -6px; bottom: -6px; }
.crop-modal-tools { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 2px 2px; }
.crop-modal-tools input[type="range"] { flex: 1; min-width: 60px; accent-color: var(--blue); cursor: pointer; }
.crop-modal-tools output { width: 44px; color: #c8d3e1; font-size: 12px; text-align: right; }
.crop-modal-status { min-height: 14px; margin: 0; color: var(--muted); font-size: 11px; }
.crop-modal-status.is-error { color: #ff9e9e; }
.crop-modal-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 8px; border-top: 1px solid #263243; }
body.crop-modal-open { overflow: hidden; }

#print-output { display: none; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding-right: 12px; padding-left: 12px; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .left-column { grid-template-rows: minmax(160px, auto) minmax(240px, 1fr) auto; }
}

@media (max-width: 720px) {
  .topbar { height: 54px; padding: 0 12px; }
  .workspace { display: flex; height: auto; min-height: 0; flex-direction: column; padding: 10px; }
  .left-column { display: flex; flex-direction: column; }
  .photo-panel { min-height: 130px; }
  .photo-list { min-height: 58px; }
  .crop-panel { min-height: 300px; }
  .settings-panel { min-height: 204px; }
  .preview-panel { min-height: 600px; }
  .preview-stage { min-height: 430px; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .back-link { font-size: 11px; }
  .header-actions { gap: 9px; }
  .menu-backdrop { inset-block-start: 54px; }
  .app-menu { top: 61px; }
}

@media (max-width: 480px) {
  .header-actions .back-link { display: none; }
}

@media (max-width: 600px) {
  .crop-modal { padding: 0; }
  .crop-modal-dialog { width: 100%; height: 100%; padding: 12px; border-radius: 0; }
  .crop-modal-header { padding-bottom: 8px; }
  .crop-modal-tools { gap: 6px; min-height: 44px; }
  .crop-modal-tools .icon-button { width: 32px; height: 32px; flex-basis: 32px; }
}

@media (max-width: 720px) {
  .workspace {
    display: flex;
    height: auto;
    min-height: 0;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }
  .preview-panel {
    order: -1;
    width: 100%;
    min-height: 0;
    padding: 10px;
  }
  .left-column {
    order: 1;
    width: 100%;
  }
  .preview-stage {
    height: clamp(330px, 47svh, 450px);
    min-height: 0;
    flex: 0 0 auto;
    padding: 10px;
  }
  .paper-preview {
    max-width: 100%;
    max-height: 100%;
  }
  .stats { padding: 10px 0 8px; }
  .actions { margin-top: 2px; }
  .print-hint { margin-bottom: 2px; }
}

@media (max-width: 480px) {
  .workspace { gap: 9px; padding: 8px; }
  .preview-panel { padding: 9px; }
  .preview-stage {
    height: clamp(320px, 46svh, 410px);
    padding: 8px;
  }
  .stats { gap: 18px; }
}

@media (min-width: 721px) and (max-height: 680px) {
  .workspace { height: calc(100vh - 58px); padding: 8px 12px; gap: 8px; }
  .left-column { grid-template-rows: minmax(125px, .4fr) minmax(125px, 1.2fr) auto; gap: 8px; }
  .settings-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .photo-panel, .crop-panel, .settings-panel, .preview-panel { padding: 9px; }
  .panel-heading { min-height: 20px; margin-bottom: 6px; }
  .crop-frame, .crop-empty { min-height: 80px; }
  .crop-tools { min-height: 30px; margin-top: 5px; }
  .settings-grid { gap: 5px 8px; }
  .field input, .field select { height: 27px; }
  .check-field { min-height: 27px; }
  .validation { margin-top: 4px; }
  .preview-stage { min-height: 0; }
  .stats { padding: 8px 0; }
  .print-hint { margin-top: 5px; }
}

@media print {
  @page { size: var(--print-page-size); margin: 0; }
  html, body { width: auto !important; height: auto !important; min-width: 0 !important; min-height: 0 !important; margin: 0 !important; padding: 0 !important; background: #fff !important; }
  body > :not(#print-output) { display: none !important; }
  #print-output { display: block !important; }
  .print-sheet {
    position: relative;
    width: var(--paper-width);
    height: var(--paper-height);
    overflow: hidden;
    page-break-after: always;
    break-after: page;
    background: #fff;
  }
  .print-sheet:last-child { page-break-after: auto; break-after: auto; }
  .print-photo {
    position: absolute;
    overflow: hidden;
    background: #fff;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .print-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .print-photo.bordered { outline: var(--border-width) solid #333; outline-offset: calc(var(--border-width) * -0.5); }
}
