:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #fafbfc;
  --ink: #171a1f;
  --muted: #68707d;
  --line: #dce1e8;
  --line-strong: #c6ced8;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --success: #15803d;
  --success-soft: #e8f7ed;
  --danger: #c2410c;
  --danger-soft: #fff0e8;
  --warning: #b45309;
  --zone: #0f766e;
  --zone-soft: rgba(15, 118, 110, 0.18);
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.18);
  --shadow: 0 18px 45px rgba(18, 25, 38, 0.14);
  --radius: 8px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button,
.file-button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible,
.file-line:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #1f2937;
  font-size: 13px;
  font-weight: 750;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1,
.brand-copy p,
.drawer-heading h2,
.drawer-heading p,
.details-header h2,
.details-header p {
  margin: 0;
}

.brand-copy h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand-copy p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(52vw, 560px);
}

.header-actions,
.toolbar-group,
.form-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button,
.file-button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  text-decoration: none;
  font-weight: 650;
  font-size: 13px;
  line-height: 1.2;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.button:hover,
.file-button:hover {
  transform: translateY(-1px);
}

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

.button.secondary {
  color: #0f5132;
  background: var(--success-soft);
  border-color: #bfe8ca;
}

.button.neutral,
.button.ghost,
.file-button {
  border-color: var(--line);
  background: var(--panel);
}

.button.ghost {
  color: #2f3744;
  background: var(--panel-soft);
}

.button.danger {
  color: #8a2c0b;
  background: var(--danger-soft);
  border-color: #ffc9b5;
}

.button.disabled,
.button:disabled {
  color: var(--muted);
  background: #e9edf3;
  border-color: var(--line);
  opacity: 1;
  pointer-events: none;
}

.full-width {
  width: 100%;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 296px minmax(480px, 1fr) 380px;
}

.sidebar,
.details-pane,
.map-area {
  min-height: 0;
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  background: #fbfcfd;
  border-right: 1px solid var(--line);
}

.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.search-box input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px 0 38px;
  color: var(--ink);
  background: var(--panel);
}

.search-box input::placeholder {
  color: #8b94a1;
}

.search-results {
  display: grid;
  gap: 6px;
  max-height: 280px;
  overflow: auto;
}

.search-result,
.drawer-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.search-result {
  padding: 10px;
}

.search-result:hover,
.drawer-card:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 8px 18px rgba(18, 25, 38, 0.07);
}

.search-result strong,
.drawer-card strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result span,
.drawer-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #3c4450;
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.counter,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  color: #384150;
  background: var(--panel);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.drawer-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.drawer-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
}

.drawer-card.active {
  border-color: #9ab8ff;
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.drawer-thumb {
  width: 58px;
  height: 46px;
  border-radius: 6px;
  object-fit: cover;
  background: #edf0f4;
  border: 1px solid var(--line);
}

.drawer-thumb.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
}

.sidebar-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.map-area {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: #eef1f5;
}

.map-toolbar,
.map-subbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.map-toolbar {
  min-height: 62px;
}

.drawer-heading {
  min-width: 0;
  margin-right: auto;
}

.drawer-heading h2 {
  font-size: 18px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.mode-button {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.mode-button.active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(18, 25, 38, 0.08);
}

.map-subbar {
  flex-wrap: wrap;
  min-height: 48px;
}

.status-pill {
  margin-right: auto;
}

.status-pill.dirty {
  color: var(--warning);
  background: #fff7ed;
  border-color: #fed7aa;
}

.status-pill.saved {
  color: var(--success);
  background: var(--success-soft);
  border-color: #bfe8ca;
}

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

.tool-button {
  min-width: 34px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #3c4450;
  background: var(--panel);
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
}

.map-stage {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  user-select: none;
  touch-action: none;
}

.map-canvas {
  --zoom: 1;
  position: relative;
  width: calc(100% * var(--zoom));
  min-width: calc(760px * var(--zoom));
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 16px 34px rgba(18, 25, 38, 0.10);
  overflow: hidden;
}

.drawer-image {
  display: block;
  width: 100%;
  height: auto;
}

.drawer-image[src=""],
.drawer-image:not([src]) {
  display: none;
}

.empty-map {
  min-height: 420px;
  display: grid;
  place-items: center;
  gap: 6px;
  align-content: center;
  color: var(--muted);
  background:
    linear-gradient(90deg, rgba(198, 206, 216, 0.42) 1px, transparent 1px),
    linear-gradient(rgba(198, 206, 216, 0.42) 1px, transparent 1px),
    #fbfcfd;
  background-size: 28px 28px;
}

.empty-map strong {
  color: #343b47;
}

.hotspot {
  position: absolute;
  min-width: 30px;
  min-height: 26px;
  border: 2px solid var(--zone);
  border-radius: 7px;
  background: var(--zone-soft);
  color: #083f3b;
  cursor: pointer;
  overflow: visible;
  touch-action: none;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.hotspot:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(15, 118, 110, 0.16);
}

.hotspot.selected {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.18);
  z-index: 10;
}

.hotspot.highlighted {
  box-shadow: 0 0 0 5px rgba(21, 128, 61, 0.18), 0 14px 28px rgba(21, 128, 61, 0.12);
  z-index: 11;
}

.hotspot-label {
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 4px;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
}

.hotspot-label strong,
.hotspot-label span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hotspot-label strong {
  font-size: 12px;
  line-height: 1.15;
  font-weight: 800;
}

.hotspot-label span {
  margin-top: 2px;
  color: #265b58;
  font-size: 10px;
  font-weight: 750;
}

.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 5px;
  background: var(--accent);
  cursor: nwse-resize;
  display: none;
  box-shadow: 0 3px 10px rgba(18, 25, 38, 0.25);
}

.is-editing .resize-handle {
  display: block;
}

.is-editing .hotspot {
  cursor: move;
}

.edit-only {
  display: none;
}

.is-editing .edit-only {
  display: inline-flex;
}

.details-pane {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.details-pane.closed {
  display: none;
}

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

.details-header h2 {
  font-size: 17px;
  line-height: 1.25;
}

.details-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.details-content {
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.product-media {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 210px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  overflow: hidden;
}

.product-media img {
  display: none;
  width: 100%;
  max-height: 250px;
  object-fit: contain;
  padding: 10px;
}

.product-media.has-image img {
  display: block;
}

.product-media.has-image .product-placeholder {
  display: none;
}

.product-placeholder {
  color: var(--muted);
  font-size: 13px;
}

.info-list {
  display: grid;
  gap: 0;
  margin: 14px 0;
}

.info-list div {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.info-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.info-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.description {
  margin: 14px 0;
  color: #384150;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 14px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.tab {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 750;
}

.tab.active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(18, 25, 38, 0.08);
}

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

.form-grid label {
  display: grid;
  gap: 6px;
}

.form-grid label span,
.file-line span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.form-grid input,
.form-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--panel);
  padding: 9px 10px;
}

.form-grid textarea {
  min-height: 104px;
  resize: vertical;
}

.form-grid .wide,
.form-actions {
  grid-column: 1 / -1;
}

.file-line {
  min-height: 58px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--panel-soft);
  cursor: pointer;
}

.file-line strong {
  color: var(--accent);
  font-size: 13px;
}

.form-actions {
  justify-content: stretch;
}

.form-actions .button {
  flex: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 80;
  max-width: calc(100vw - 28px);
  padding: 11px 14px;
  border-radius: 999px;
  color: #fff;
  background: #171a1f;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 13px;
  font-weight: 650;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.dialog {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.48);
  backdrop-filter: blur(8px);
}

.dialog-box {
  width: min(460px, 100%);
  border-radius: 10px;
  padding: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dialog-box h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.dialog-box p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.dialog-actions {
  justify-content: flex-end;
}

@media (max-width: 1220px) {
  .workspace {
    grid-template-columns: 272px minmax(420px, 1fr);
  }

  .details-pane {
    position: fixed;
    top: 72px;
    right: 12px;
    bottom: 12px;
    width: min(380px, calc(100vw - 24px));
    z-index: 40;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
  }

  .details-pane.closed {
    display: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .app-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

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

  .sidebar {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-switch,
  .toolbar-group {
    width: 100%;
  }

  .toolbar-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .map-stage {
    padding: 10px;
  }

  .map-canvas {
    min-width: calc(640px * var(--zoom));
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }
}
