:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #687381;
  --line: #d8dee6;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #b42318;
  --stage: #dfe4ea;
  --shadow: 0 16px 40px rgba(24, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 82px;
  padding: 16px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hamburger-button {
  display: grid;
  place-items: center;
  gap: 4px;
  width: 42px;
  min-height: 42px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 9px;
}

.hamburger-button span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--ink);
}

.header-menu {
  position: absolute;
  top: 70px;
  left: 22px;
  z-index: 40;
  display: grid;
  gap: 6px;
  width: 230px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.header-menu[hidden],
.technical-output[hidden] {
  display: none;
}

.header-menu button {
  width: 100%;
  border: 1px solid transparent;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  text-align: left;
}

.header-menu button.active {
  border-color: rgba(15, 118, 110, 0.22);
  background: #e8f3f1;
  color: var(--accent-strong);
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.1;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

body:not(.templates-page) .topbar-actions {
  display: none;
}

.page-view {
  display: none;
}

.page-view.active {
  display: block;
}

.home-page,
.admin-page {
  padding: 18px;
}

.service-grid,
.page-container {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.service-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.service-card {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 145px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--ink);
  text-align: left;
}

.service-card strong {
  font-size: 18px;
}

.service-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.workspace {
  display: grid;
  grid-template-columns: 290px minmax(420px, 1fr) 320px;
  gap: 14px;
  height: calc(100vh - 82px);
  padding: 14px;
}

.sidebar,
.stage-panel {
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
}

.panel,
.stage-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.field,
.check-field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field span,
.zoom-control label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 4px;
}

textarea {
  min-height: 180px;
  resize: vertical;
  color: #2f3945;
  font-family: Consolas, monospace;
  font-size: 12px;
}

.upload-zone {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 118px;
  border: 1px dashed #9aa6b5;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  background: #f8fafc;
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-zone span {
  color: var(--muted);
  font-size: 13px;
}

.image-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 0;
}

.image-info div {
  padding: 10px;
  background: #f7f9fb;
  border-radius: 6px;
}

.image-info dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.image-info dd {
  margin: 4px 0 0;
  font-weight: 700;
}

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

button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
}

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

.ghost-button,
.tool-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.ghost-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.danger-button {
  width: 100%;
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #f0b8b3;
}

.field-list {
  display: grid;
  gap: 8px;
}

.field-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.field-item-main {
  display: grid;
  gap: 2px;
  min-width: 0;
  min-height: auto;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.field-item-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0;
}

.icon-button svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}

.icon-button.danger {
  color: var(--danger);
}

.field-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.field-item small {
  color: var(--muted);
}

.stage-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

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

.stage-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 26px;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%);
  background-color: var(--stage);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.empty-state,
.empty-inspector {
  display: grid;
  gap: 6px;
  max-width: 420px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.canvas-wrap {
  position: relative;
  background: #fff;
  box-shadow: 0 20px 50px rgba(24, 32, 42, 0.18);
}

#templateImage {
  display: block;
  width: auto;
  max-width: min(100%, 980px);
  max-height: calc(100vh - 210px);
  height: auto;
  pointer-events: none;
  user-select: none;
}

.overlay-layer {
  position: absolute;
  inset: 0;
}

.field-box {
  position: absolute;
  min-width: 18px;
  min-height: 18px;
  border: 2px solid #0f766e;
  background: rgba(15, 118, 110, 0.14);
  color: #073b37;
  cursor: default;
  overflow: visible;
  touch-action: none;
}

.field-box.image {
  border-color: #7c3aed;
  background: rgba(124, 58, 237, 0.12);
  color: #3f1b8f;
}

.field-box.photo {
  border-color: #2563eb;
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}

.field-box.ratio-locked {
  border-color: #16a34a;
  background: rgba(22, 163, 74, 0.14);
  color: #166534;
}

.field-box.active {
  outline: 3px solid rgba(15, 118, 110, 0.22);
}

.field-box .move-handle {
  position: absolute;
  top: -26px;
  left: -2px;
  display: flex;
  align-items: center;
  width: calc(100% + 4px);
  min-height: 24px;
  padding: 0 6px;
  border-radius: 5px 5px 0 0;
  background: currentColor;
  cursor: grab;
  touch-action: none;
}

.field-box .move-handle:active {
  cursor: grabbing;
}

.field-box .label {
  width: 100%;
  color: #fff;
  font-size: 11px;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field-box .resize-handle {
  position: absolute;
  right: -9px;
  bottom: -9px;
  width: 22px;
  height: 22px;
  border: 2px solid #fff;
  border-radius: 50%;
  border-left: 2px solid rgba(255, 255, 255, 0.85);
  border-top: 2px solid rgba(255, 255, 255, 0.85);
  background: currentColor;
  cursor: nwse-resize;
  touch-action: none;
}

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

.check-field {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--ink);
  font-size: 13px;
}

.asset-field {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #c8d8f6;
  border-radius: 6px;
  background: #f4f7ff;
}

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

.menu-panel {
  padding: 0;
  overflow: hidden;
}

.menu-title {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.admin-nav {
  display: grid;
  gap: 6px;
  padding: 10px;
}

.nav-button {
  width: 100%;
  justify-content: flex-start;
  min-height: 38px;
  border: 1px solid transparent;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  text-align: left;
}

.nav-button.active {
  border-color: rgba(15, 118, 110, 0.22);
  background: #e8f3f1;
  color: var(--accent-strong);
}

.right-view {
  display: none;
}

.right-view.active {
  display: block;
}

.hamburger {
  display: grid;
  gap: 4px;
  width: 20px;
}

.hamburger span {
  display: block;
  height: 2px;
  background: var(--ink);
}

.template-list {
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow: auto;
  padding: 12px;
}

.template-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

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

.template-row small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

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

.level-list,
.payment-list {
  display: grid;
  gap: 8px;
}

.level-row,
.payment-row {
  display: grid;
  gap: 4px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.level-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.level-row strong,
.payment-row strong {
  font-size: 13px;
}

.level-row span,
.payment-row span,
.metric-grid span {
  color: var(--muted);
  font-size: 11px;
}

.level-badge {
  padding: 5px 8px;
  border-radius: 999px;
  background: #e8f3f1;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
}

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

.metric-grid div {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 6px;
  background: #f7f9fb;
}

.metric-grid strong {
  font-size: 15px;
}

.preview-dialog {
  width: min(92vw, 980px);
  max-height: 92vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(24, 32, 42, 0.28);
}

.preview-dialog::backdrop {
  background: rgba(24, 32, 42, 0.5);
}

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

.preview-body {
  max-height: calc(92vh - 70px);
  overflow: auto;
  padding: 18px;
  background: var(--stage);
}

#previewCanvas {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 16px 40px rgba(24, 32, 42, 0.16);
}

@media (max-width: 1120px) {
  .service-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 260px minmax(360px, 1fr);
  }

  .workspace > .sidebar:last-child {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr;
  }
}

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

  .workspace {
    height: auto;
    grid-template-columns: 1fr;
  }

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

  .workspace > .sidebar:last-child {
    display: flex;
  }
}
