:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #f0f4f8;
  --text: #162033;
  --muted: #607086;
  --border: #d8e1ec;
  --border-strong: #b8c7d9;
  --accent: #176bff;
  --accent-dark: #0f4fc2;
  --danger: #b3261e;
  --shadow: 0 18px 48px rgba(22, 32, 51, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 750;
  letter-spacing: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 22px rgba(23, 107, 255, 0.22);
}

.primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

.secondary {
  border-color: var(--border);
  background: #fff;
}

.secondary:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--panel-soft);
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 4px 24px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(1.7rem, 2.5vw, 2.35rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar p,
.pages-header p,
.empty-state p,
.drop-zone span,
.setting-row span,
.status-panel p {
  color: var(--muted);
}

.topbar p {
  margin-bottom: 0;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.sidebar,
.pages-panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  position: sticky;
  top: 24px;
  padding: 18px;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 210px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 8px;
  padding: 22px;
  text-align: center;
  background: linear-gradient(180deg, #fff, #f7faff);
  cursor: pointer;
}

.drop-zone.is-dragging {
  border-color: var(--accent);
  background: #eef5ff;
}

.drop-zone input {
  width: 1px;
  height: 1px;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.drop-zone__icon {
  display: grid;
  width: 54px;
  height: 54px;
  margin-bottom: 14px;
  place-items: center;
  border-radius: 8px;
  background: #e8f1ff;
  color: var(--accent);
}

.drop-zone__icon svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.drop-zone strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1rem;
}

.settings {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.setting-row span,
.setting-row strong {
  font-size: 0.87rem;
}

.status-panel {
  min-height: 82px;
  margin-top: 16px;
  padding: 13px 14px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.status-panel p {
  margin: 0;
  font-size: 0.9rem;
}

.status-panel .error {
  margin-top: 8px;
  color: var(--danger);
  font-weight: 700;
}

.error:empty {
  display: none;
}

.pages-panel {
  overflow: hidden;
}

.pages-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.pages-header h2 {
  margin-bottom: 2px;
  font-size: 1.18rem;
}

.pages-header p {
  margin-bottom: 0;
  font-size: 0.92rem;
}

.empty-state {
  display: grid;
  min-height: 540px;
  place-items: center;
  align-content: center;
  padding: 34px;
  text-align: center;
}

.empty-state svg {
  width: 94px;
  height: 94px;
  margin-bottom: 18px;
  fill: none;
  stroke: #94a5ba;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.empty-state h2 {
  max-width: 460px;
  margin-bottom: 8px;
  font-size: 1.32rem;
}

.empty-state p {
  max-width: 520px;
  margin-bottom: 0;
}

.pages-list {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.page-card {
  display: grid;
  grid-template-columns: minmax(220px, 340px) minmax(260px, 1fr);
  gap: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.preview-wrap {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #eef2f6 25%, transparent 25%),
    linear-gradient(-45deg, #eef2f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef2f6 75%),
    linear-gradient(-45deg, transparent 75%, #eef2f6 75%);
  background-color: #f8fafc;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.preview-stage {
  position: relative;
  max-width: 100%;
  line-height: 0;
  box-shadow: 0 10px 28px rgba(22, 32, 51, 0.12);
}

.preview-stage img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

.crop-box {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(23, 107, 255, 0.1);
  cursor: move;
}

.crop-box[hidden] {
  display: none;
}

.crop-box::before {
  content: "";
  position: absolute;
  inset: -999px;
  border: 999px solid rgba(16, 24, 40, 0.24);
  pointer-events: none;
}

.handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(22, 32, 51, 0.25);
}

.handle--nw {
  top: -8px;
  left: -8px;
  cursor: nwse-resize;
}

.handle--ne {
  top: -8px;
  right: -8px;
  cursor: nesw-resize;
}

.handle--sw {
  bottom: -8px;
  left: -8px;
  cursor: nesw-resize;
}

.handle--se {
  right: -8px;
  bottom: -8px;
  cursor: nwse-resize;
}

.page-controls {
  display: grid;
  align-content: start;
  gap: 14px;
}

.page-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.page-title h3 {
  margin: 0;
  font-size: 1.02rem;
}

.page-title span {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

select,
.readonly {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 11px;
  background: #fff;
  color: var(--text);
  font-size: 0.92rem;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 255, 0.14);
}

.readonly {
  display: flex;
  align-items: center;
  color: var(--muted);
}

.mode-note {
  min-height: 60px;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 920px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .workspace,
  .page-card,
  .control-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .sidebar {
    position: static;
  }
}
