:root {
  color-scheme: light;
  --bg: #f1f3f5;
  --panel: #ffffff;
  --ink: #111820;
  --muted: #59636f;
  --line: #333b44;
  --soft-line: #c8ced5;
  --accent: #176b87;
  --yellow: #ffe45c;
  --stage: #f7f8f9;
  --shadow: 0 16px 40px rgba(25, 33, 42, .14);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15191d;
  --panel: #20262c;
  --ink: #edf1f5;
  --muted: #a7b0ba;
  --line: #78828d;
  --soft-line: #3a444e;
  --accent: #4aa3b8;
  --stage: #171b20;
  --shadow: 0 16px 40px rgba(0, 0, 0, .42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  overflow: auto;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: var(--panel);
  padding: 8px 12px;
  cursor: pointer;
}

button:hover,
button.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}

input,
select {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 7px 8px;
  color: var(--ink);
  background: var(--panel);
}

label {
  display: grid;
  gap: 4px;
  color: var(--ink);
  font-size: 14px;
}

:root[data-theme="dark"] label,
:root[data-theme="dark"] .tabs button,
:root[data-theme="dark"] .mode-buttons button,
:root[data-theme="dark"] .preset-grid button,
:root[data-theme="dark"] select,
:root[data-theme="dark"] input {
  color: var(--yellow);
  font-weight: 700;
}

:root[data-theme="dark"] option {
  color: var(--yellow);
  background: var(--panel);
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: clamp(190px, 18vw, 235px) minmax(0, 1fr);
  overflow: hidden;
}

.left-panel {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 12px;
  padding: 18px 18px 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}

.brand-logo {
  width: min(178px, 100%);
  max-height: 76px;
  justify-self: center;
  object-fit: contain;
}

:root[data-theme="dark"] .brand-logo {
  filter: brightness(0) invert(1);
}

.clear-artwork {
  justify-self: stretch;
  font-size: 15px;
}

.add-files {
  width: 90px;
  height: 90px;
  justify-self: center;
  border-radius: 50%;
  font-size: 48px;
  line-height: 1;
  font-weight: 700;
}

.add-copy {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
  font-size: 20px;
}

.add-copy span {
  color: var(--muted);
}

.page-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding-right: 5px;
}

.page-list.empty {
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.page-item {
  position: relative;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 9px;
  align-items: center;
  border: 1px solid var(--soft-line);
  padding: 7px;
  background: var(--panel);
}

.page-item.dragging {
  opacity: .55;
}

.delete-page {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  opacity: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  color: #fff;
  background: #b2472e;
  border-color: #8b2f1f;
}

.page-item:hover .delete-page {
  opacity: 1;
}

.thumb {
  width: 62px;
  height: 78px;
  border: 1px solid var(--soft-line);
  background: #f5f6f7 center / cover no-repeat;
}

.thumb.pdf {
  display: grid;
  place-items: center;
  color: #fff;
  background: #b2472e;
  font-weight: 700;
}

.page-meta {
  min-width: 0;
}

.page-meta strong,
.page-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-meta span {
  color: var(--muted);
  font-size: 12px;
}

.main-area {
  min-width: 0;
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.top-controls {
  position: relative;
  display: flex;
  align-items: start;
  flex-wrap: wrap;
  gap: 28px;
  padding: 14px 16px 10px;
  background: var(--panel);
}

.tool-buttons {
  display: flex;
  align-items: end;
  gap: 6px;
}

.tool-buttons button {
  min-width: 38px;
}

.tool-icon {
  display: inline-grid;
  width: 38px;
  height: 36px;
  place-items: center;
  padding: 0;
  font-size: 21px;
  line-height: 1;
}

.control-group,
.control-pair,
.object-toolbar {
  display: flex;
  align-items: end;
  gap: 9px;
}

.paper-group select {
  width: 168px;
  font-size: 22px;
}

.orientation-buttons {
  display: grid;
  grid-template-columns: 26px;
  gap: 5px;
}

.orientation-buttons button {
  width: 26px;
  height: 24px;
  padding: 0;
}

.control-pair input {
  width: 64px;
}

.unit-select select {
  width: 168px;
  font-size: 20px;
}

.object-toolbar {
  min-width: 0;
  flex-wrap: wrap;
  align-content: end;
  max-width: 520px;
}

.floating-object-toolbar {
  position: absolute;
  z-index: 20;
  top: 112px;
  left: 24px;
  right: 360px;
  max-width: none;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.object-toolbar span {
  align-self: center;
  font-size: 20px;
}

.object-toolbar input[type="number"] {
  width: 56px;
}

.compact {
  width: 54px;
}

.icon-btn {
  min-width: 30px;
  width: 30px;
  height: 44px;
  padding: 0;
}

.icon-btn.active {
  background: color-mix(in srgb, var(--accent) 20%, var(--panel));
}

.check-inline {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-subpanel {
  flex-basis: 100%;
  display: flex;
  gap: 8px;
  align-items: end;
  padding-top: 7px;
  border-top: 1px solid var(--soft-line);
}

.toolbar-subpanel label {
  display: flex;
  align-items: center;
  gap: 5px;
}

.toolbar-subpanel input[type="number"] {
  width: 72px;
}

.action-buttons {
  margin-left: auto;
  display: flex;
  gap: 18px;
}

.action-buttons button {
  min-width: 82px;
  font-size: 20px;
}

.auth-btn {
  min-width: 76px;
}

.profile-btn {
  min-width: 38px !important;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-weight: 800;
}

.work-row {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(290px, 27vw, 335px);
  overflow: hidden;
}

.sheet-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr 72px;
  padding: 12px 16px 8px 40px;
  overflow: hidden;
}

.sheet-stage {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 20px 26px;
  background: var(--stage);
}

#sheetSvg {
  display: block;
  overflow: visible;
  filter: drop-shadow(var(--shadow));
}

.sheet-object {
  cursor: move;
}

.sheet-object.selected .object-frame {
  stroke: #176b87;
  stroke-width: .9;
  stroke-dasharray: 2 1;
}

.resize-handle {
  fill: #fff;
  stroke: #176b87;
  stroke-width: .45;
  cursor: nwse-resize;
}

.bottom-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 12px;
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.page-controls button {
  min-width: 26px;
  width: 28px;
  height: 28px;
  padding: 0;
}

.sheet-counter {
  display: inline-grid;
  min-width: 78px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 18px;
}

.zoom-slider {
  width: 42%;
  margin-left: auto;
}

.right-panel {
  min-height: 0;
  padding: 12px 12px 18px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--soft-line);
}

.tabs button {
  min-height: 44px;
  font-size: 18px;
  font-weight: 800;
  border-width: 0 0 3px;
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
}

.tabs button.active {
  border-bottom-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

.mode-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 18px;
}

.mode-buttons button {
  min-height: 42px;
  font-size: 17px;
  font-weight: 650;
}

.layout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  margin: 0 0 18px;
}

.layout-grid input,
.layout-grid select {
  height: 30px;
}

.checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-top: 12px;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-subtitle {
  margin: 8px 0 2px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.full-row {
  grid-column: 1 / -1;
}

.control-stack {
  display: grid;
  gap: 6px;
  align-content: start;
}

.child-control {
  margin-left: 20px;
}

.nested-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.sub-option {
  padding-left: 18px;
}

.report-issue-btn {
  width: 100%;
  margin-top: 18px;
}

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

.preset-grid button {
  min-height: 46px;
  font-size: 16px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 5px 0;
}

.menu-grid button {
  text-align: center;
}

dialog {
  border: 1px solid var(--line);
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, .35);
}

.dialog-card {
  min-width: 460px;
  display: grid;
  gap: 12px;
  padding: 18px;
  background: var(--panel);
}

.dialog-card h2 {
  margin: 0;
}

.full-width-action {
  width: 100%;
  min-height: 42px;
}

.auth-panel {
  display: grid;
  gap: 10px;
}

.auth-switch {
  margin: 0;
  text-align: center;
  color: var(--muted);
}

.license-consent {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--soft-line);
  background: color-mix(in srgb, var(--accent) 5%, var(--panel));
}

.license-consent input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  padding: 0;
}

.license-consent label {
  display: inline;
  line-height: 1.4;
}

.license-consent .text-action {
  display: block;
  margin-top: 4px;
}

.license-dialog-card {
  width: min(760px, calc(100vw - 40px));
  min-width: 0;
}

.license-agreement-content {
  max-height: 65vh;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--soft-line);
  padding: 16px;
  color: var(--ink);
  background: var(--stage);
  font: 14px/1.55 "Segoe UI", Arial, sans-serif;
}

.text-action {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  width: auto;
  justify-self: start;
  box-shadow: none;
  font-weight: 650;
}

.text-action:hover {
  text-decoration: underline;
}

.dialog-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.dialog-divider::before,
.dialog-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

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

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

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.profile-plan {
  padding: 10px;
  border: 1px solid var(--soft-line);
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}

textarea {
  min-width: 0;
  resize: vertical;
  border: 1px solid var(--line);
  padding: 8px;
  color: var(--ink);
  background: var(--panel);
  font: inherit;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 8px;
}

@media (max-width: 1280px), (max-height: 760px) {
  body {
    font-size: 13px;
  }

  .left-panel {
    gap: 8px;
    padding: 12px;
  }

  .brand-logo {
    max-height: 56px;
  }

  .add-files {
    width: 68px;
    height: 68px;
    font-size: 38px;
  }

  .add-copy {
    font-size: 16px;
  }

  .top-controls {
    gap: 12px;
    padding: 10px 12px 8px;
  }

  .paper-group select,
  .unit-select select {
    width: 132px;
    font-size: 15px;
  }

  .action-buttons {
    gap: 8px;
  }

  .action-buttons button {
    min-width: 68px;
    font-size: 15px;
    padding: 7px 9px;
  }

  .sheet-column {
    grid-template-rows: minmax(0, 1fr) 58px;
    padding: 8px 10px 6px;
  }

  .sheet-stage {
    padding: 12px;
  }

  .bottom-controls {
    gap: 8px;
    padding-top: 8px;
  }

  .right-panel {
    padding: 8px 10px 12px;
  }

  .tabs {
    margin-bottom: 10px;
    padding-bottom: 6px;
  }

  .tabs button,
  .mode-buttons button {
    min-height: 36px;
    font-size: 14px;
  }

  .mode-buttons,
  .layout-grid {
    gap: 6px 8px;
    margin-bottom: 10px;
  }

  .checks {
    gap: 6px 8px;
  }
}

@media (max-width: 980px) {
  .app-shell {
    min-height: 100vh;
    height: auto;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .left-panel {
    grid-template-columns: auto auto 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .brand-logo {
    max-width: 150px;
  }

  .page-list {
    grid-column: 1 / -1;
    max-height: 180px;
  }

  .main-area,
  .work-row {
    overflow: visible;
  }

  .work-row {
    grid-template-columns: 1fr;
  }

  .sheet-column {
    min-height: 62vh;
  }

  .right-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media print {
  body {
    min-width: 0;
    overflow: visible;
    background: #fff;
  }

  .printable-area-guide {
    display: none;
  }
}
