:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --text: #17212b;
  --muted: #667085;
  --border: #d0d5dd;
  --accent: #111827;
  --danger: #b42318;
  --success: #067647;
  --shadow: 0 14px 42px rgba(16, 24, 40, .10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  min-height: 100vh;
}

a { color: inherit; }

.shell {
  width: min(1100px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.mobile-shell {
  width: min(520px, calc(100% - 24px));
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 22px 0;
}

.card {
  background: var(--card);
  border: 1px solid rgba(16, 24, 40, .08);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 28px;
  width: 100%;
}

.logo {
  display: block;
  max-width: min(300px, 78%);
  max-height: 150px;
  margin: 0 auto 34px;
}

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

.muted { color: var(--muted); }

.upload-box {
  border: 2px dashed var(--border);
  border-radius: 18px;
  padding: 30px 18px;
  text-align: center;
  background: #fafafa;
}

.file-input {
  display: none;
}

.btn, button {
  appearance: none;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  padding: 13px 18px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn.secondary, button.secondary {
  background: #eef2f6;
  color: #1d2939;
}

.btn.danger, button.danger {
  background: var(--danger);
}

.btn.success, button.success {
  background: var(--success);
}

.btn.full { width: 100%; }

.admin-link {
  display: block;
  text-align: center;
  margin-top: 26px;
  color: var(--muted);
  font-size: 14px;
}

.form-grid {
  display: grid;
  gap: 16px;
}

label {
  font-weight: 600;
  display: block;
  margin-bottom: 7px;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  background: white;
}

.alert {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.alert.error {
  background: #fef3f2;
  color: #912018;
}

.alert.success {
  background: #ecfdf3;
  color: #05603a;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grid {
  display: grid;
  gap: 16px;
}

.image-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 18px;
  align-items: center;
  background: white;
  border-radius: 16px;
  padding: 14px;
  border: 1px solid rgba(16,24,40,.08);
}

.thumb {
  width: 110px;
  height: 110px;
  border-radius: 12px;
  object-fit: cover;
  background: #eee;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  background: #f2f4f7;
}

.status.processed {
  background: #ecfdf3;
  color: #067647;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: start;
}

.editor-card {
  background: white;
  border-radius: 18px;
  padding: 18px;
  border: 1px solid rgba(16,24,40,.08);
}

.stage-wrap {
  display: flex;
  justify-content: center;
  overflow: hidden;
}

#stage {
  position: relative;
  width: min(72vw, 720px);
  max-width: 100%;
  aspect-ratio: 1;
  background:
    linear-gradient(45deg, #eee 25%, transparent 25%),
    linear-gradient(-45deg, #eee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eee 75%),
    linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

#editable-image {
  position: absolute;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  cursor: move;
  transform-origin: top left;
}

#selection-box {
  position: absolute;
  border: 1px dashed rgba(255,255,255,.9);
  outline: 1px dashed rgba(0,0,0,.45);
  pointer-events: none;
}

.crop-dim {
  position: absolute;
  background: rgba(0,0,0,.58);
  pointer-events: none;
  z-index: 10;
}

#crop-border {
  position: absolute;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.65), inset 0 0 0 1px rgba(0,0,0,.35);
  pointer-events: none;
  z-index: 12;
}

#crop-label {
  position: absolute;
  z-index: 13;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.72);
  color: white;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
}

.handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border: 2px solid #111827;
  border-radius: 50%;
  z-index: 20;
  transform: translate(-50%, -50%);
  touch-action: none;
}

.handle[data-dir="nw"], .handle[data-dir="se"] { cursor: nwse-resize; }
.handle[data-dir="ne"], .handle[data-dir="sw"] { cursor: nesw-resize; }
.handle[data-dir="n"], .handle[data-dir="s"] { cursor: ns-resize; }
.handle[data-dir="e"], .handle[data-dir="w"] { cursor: ew-resize; }

.control-stack {
  display: grid;
  gap: 14px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
}

.checkbox-row input {
  width: 20px;
  height: 20px;
}

.kv {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  font-size: 14px;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

@media (max-width: 820px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }

  #stage {
    width: min(94vw, 720px);
  }

  .image-row {
    grid-template-columns: 80px 1fr;
  }

  .image-row .actions {
    grid-column: 1 / -1;
  }

  .thumb {
    width: 80px;
    height: 80px;
  }

  .card {
    padding: 22px;
    border-radius: 18px;
  }
}
