:root {
  --bg: #f5f4f2;
  --surface: #ffffff;
  --border: #dcd9d4;
  --text: #2a2a28;
  --muted: #7a766f;
  --accent: #4a5d23;
  --accent-text: #ffffff;
  --danger: #b03a2e;
  /* Blåtonade mörka toner */
  --sidebar-bg: #14171e;
  --module-bg: #191d26;
  --module-bg-soft: #1c222d;
  --module-border: rgba(255, 255, 255, 0.075);
  --stage-bg: #161a22;
  --checker-a: #1b1f28;
  --checker-b: #161a22;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --sidebar-w: 360px;
}

* { box-sizing: border-box; }

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

html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============ App-skal: scen + sidebar ============ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Scen (bilden) ---------- */
.stage {
  flex: 1;
  position: relative;
  /* Schackrutigt transparens-mönster som i bildredigerare */
  background-color: var(--checker-a);
  background-image:
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-b) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
/* Mjuk fade på högerkanten så scenen smälter ihop med sidebaren */
.stage::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: clamp(120px, 22%, 240px);
  background: linear-gradient(to right, rgba(20, 23, 30, 0) 0%, var(--sidebar-bg) 100%);
  pointer-events: none;
  z-index: 2;
}

#image-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: crosshair;
  touch-action: none;
  transform-origin: center center;
  will-change: transform;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.dropzone {
  position: absolute;
  inset: 24px;
  width: calc(100% - 48px);
  max-width: 760px;
  height: min(460px, calc(100% - 48px));
  margin: auto;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover,
.dropzone.dragover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.6);
}
.dz-inner .dz-icon {
  display: block;
  width: 128px;
  height: 128px;
  margin: 0 auto 14px;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.35));
  animation: dzFloat 4.5s ease-in-out infinite;
}
@keyframes dzFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@media (prefers-reduced-motion: reduce) {
  .dz-inner .dz-icon { animation: none; }
}
.dz-inner .dz-title { font-size: 1.2rem; font-weight: 600; margin: 8px 0 2px; }
.dz-inner p { margin: 2px 0; }
.dropzone .muted { color: rgba(255, 255, 255, 0.6); }

.stage-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.stage-btn:hover { background: rgba(0, 0, 0, 0.75); }

.pick-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.85rem;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}

/* ---------- Zoom-kontroller ---------- */
.zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  color: #fff;
  z-index: 3;
}
.zoom-controls button {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.zoom-controls button:hover { background: rgba(255, 255, 255, 0.18); }
.zoom-controls #zoom-level {
  min-width: 46px;
  text-align: center;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Sidebar ---------- */
.sidebar {
  /* Mörkt blåtonat tema – endast i sidebaren. Variablerna ärvs av alla barn. */
  --surface: var(--module-bg);
  --bg: var(--module-bg-soft);
  --border: var(--module-border);
  --text: #e9eaf0;
  --muted: #989eac;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--text);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 12px;
}
.sidebar-head {
  padding: 14px 18px 15px;
  position: sticky;
  top: 0;
  z-index: 2;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-top: 1px;
}
.brand-name {
  margin: 0;
  color: #f7f3ea;
  font-family: "IBM Plex Serif", Georgia, serif;
  font-size: 1.32rem;
  font-weight: 700;
  line-height: 1.04;
}
.brand-tagline {
  margin-top: 4px;
  color: #aeb5c2;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.25;
  text-transform: uppercase;
}
/* ---------- Paneler ---------- */
.panel {
  padding: 16px 18px;
}
.panel h2 { font-size: 1rem; margin: 0 0 12px; }

/* Hopfällbara paneler (<details>) */
details.panel { padding: 0; }
details.panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 18px;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
details.panel > summary:hover {
  color: #f2f4f7;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::after {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s;
}
details.panel[open] > summary::after { transform: rotate(90deg); }
.panel-body {
  padding: 0 18px 16px;
}

/* ---------- Moduler i sidebaren ---------- */
.sidebar-module-nav {
  display: grid;
  gap: 10px;
  margin: 92px 18px 0;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.module-nav-btn {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.018)),
    rgba(255, 255, 255, 0.025);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.13);
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}
.module-nav-btn:hover,
.module-nav-btn.is-active {
  border-color: rgba(169, 200, 145, 0.34);
  background:
    linear-gradient(135deg, rgba(169, 200, 145, 0.12), rgba(58, 134, 255, 0.055)),
    rgba(255, 255, 255, 0.035);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
  transform: translateY(-1px);
}
.module-nav-btn:focus-visible {
  outline: 2px solid rgba(169, 200, 145, 0.62);
  outline-offset: 3px;
}
.module-nav-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(169, 200, 145, 0.18), rgba(58, 134, 255, 0.1)),
    rgba(255, 255, 255, 0.04);
  color: #d7edc5;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.module-nav-icon svg,
.security-icon svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.module-nav-title,
.module-nav-meta {
  display: block;
  min-width: 0;
}
.module-nav-title {
  color: #f2f4f7;
  font-size: 0.93rem;
  line-height: 1.2;
}
.module-nav-meta {
  margin-top: 2px;
  color: #9da6b7;
  font-size: 0.76rem;
}
.module-panel {
  margin: 12px 18px 0;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.085);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.018)),
    radial-gradient(circle at 18% 0%, rgba(169, 200, 145, 0.14), transparent 34%),
    #171c25;
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.module-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.module-head h2 {
  margin: 0;
  color: #f6f7f9;
  font-size: 1.08rem;
  line-height: 1.15;
}
.module-kicker {
  margin: 0 0 5px;
  color: #9fa8b8;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.module-pill {
  flex: 0 0 auto;
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
  color: #cfd6df;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
}
.module-pill.is-ready {
  border-color: rgba(169, 200, 145, 0.32);
  background: rgba(169, 200, 145, 0.11);
  color: #d7edc5;
}
.module-insight,
.settings-security {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 11px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  color: #bac2cf;
  font-size: 0.8rem;
  line-height: 1.35;
}
.insight-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #a9c891;
  box-shadow: 0 0 0 5px rgba(169, 200, 145, 0.12);
}
.security-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: rgba(58, 134, 255, 0.1);
  color: #b8d4ff;
}
.empty-state {
  margin: 14px 0 0;
  padding: 18px 14px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  color: #98a1b0;
  text-align: center;
  font-size: 0.86rem;
  background: rgba(255, 255, 255, 0.025);
}

/* Textmeny + popup-moduler */
.sidebar-module-nav {
  gap: 18px;
  margin: 98px 18px 0;
  padding-top: 0;
  border-top: 0;
}
.module-nav-section {
  margin: 0;
  color: #b9c7e5;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.module-nav-btn {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  min-height: 0;
  padding: 14px 0px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: #f8f9fc;
  transform: none;
}
.module-nav-btn:hover,
.module-nav-btn.is-active {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  transform: none;
}
.module-nav-btn:hover .module-nav-title,
.module-nav-btn.is-active .module-nav-title {
  color: #dbe9ff;
}
.module-nav-btn:focus-visible {
  outline: 2px solid rgba(185, 199, 229, 0.65);
  outline-offset: 5px;
  border-radius: 4px;
}
.module-nav-btn > span:not(.module-nav-title):not(.module-nav-meta) {
  display: block;
}
.module-nav-title {
  color: #ffffff;
  font-size: 0.95rem;
}
.module-nav-meta {
  margin-top: 1px;
  font-size: 0.78rem;
  white-space: nowrap;
}
.module-modal-box {
  max-width: 520px;
  padding: 22px;
}
.module-modal-head {
  align-items: flex-start;
  margin-bottom: 16px;
}
.module-modal-head h3 {
  margin: 0;
  color: #f7f9fc;
  font-size: 1.16rem;
}
.modal-close-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  color: #b8c0cc;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close-btn:hover {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.065);
  color: #ffffff;
}
.module-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 11px 12px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  color: #bac2cf;
  font-size: 0.82rem;
}
.module-summary-row span:last-child {
  color: #d7edc5;
  font-weight: 800;
  white-space: nowrap;
}

h3 { font-size: 1rem; margin: 14px 0 8px; }
h4 { font-size: 0.9rem; margin: 14px 0 6px; }

.muted { color: var(--muted); font-size: 0.88rem; }
.small { font-size: 0.8rem; }
.hidden { display: none !important; }

/* ---------- Knappar ---------- */
.btn {
  display: inline-block;
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 4px;
}
.btn:hover { background: var(--bg); border-color: rgba(255, 255, 255, 0.13); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Primär handling i färgbiblioteket */
.add-color-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 39px;
  padding: 7px 10px;
  border-color: rgb(194 199 206 / 16%);
  border-radius: 9px;
  background:transparent;
  color: #c2c7ce;
  font-size: 0.87rem;
  font-weight: 600;
  transition:
    color 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease,
    transform 180ms ease;
}
.add-color-icon {
  display: grid;
  place-items: center;
  width: 29px;
  height: 24px;
  flex: 0 0 auto;
  transition: color 180ms ease, transform 180ms ease;
}
.add-color-icon svg {
  width: 28px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.add-color-btn:hover {
  border-color: rgba(169, 200, 145, 0.42);
  background: rgba(169, 200, 145, 0.075);
  color: #c5dfaf;
}
.add-color-btn:hover .add-color-icon {
  color: #c5dfaf;
}
.add-color-btn:active {
  background: rgba(255, 255, 255, 0.025);
  transform: scale(0.995);
}
.add-color-btn:focus-visible {
  outline: 2px solid #8f96a3;
  outline-offset: 2px;
}

/* ---------- Rader / fält ---------- */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 8px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.field input[type="text"],
.field input[type="password"],
.field textarea,
.field select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  width: 100%;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
}
.field input[type="text"]:focus,
.field input[type="password"]:focus,
.field textarea:focus,
.field select:focus {
  outline: 2px solid rgba(143, 191, 107, 0.42);
  outline-offset: 1px;
  border-color: rgba(143, 191, 107, 0.5);
}
.field textarea {
  min-height: 64px;
  resize: vertical;
}
.modal-swatch-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 7px 10px 7px 7px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease;
}
.modal-swatch-picker:hover {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.055);
}
.field:focus-within .modal-swatch-picker {
  outline: 2px solid rgba(143, 191, 107, 0.42);
  outline-offset: 2px;
  border-color: rgba(143, 191, 107, 0.5);
}
.modal-swatch {
  width: 48px;
  height: 42px;
  flex: 0 0 auto;
}
.modal-swatch-hex {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.015em;
}
input[type="color"] {
  width: 56px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: rgba(255, 255, 255, 0.045);
}

/* ---------- Målfärg-preview ---------- */
#target-panel { cursor: pointer; }
#target-panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

/* Målad penseldrags-swatch */
.target-blob {
  position: relative;
  width: 100%;
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}
.blob-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.blob-label {
  position: relative;
  z-index: 1;
  font-size: 1.3rem;
  font-weight: 600;
  color: #ece8e2;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.target-below {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

/* ---------- Recept ---------- */
.mix-list { list-style: none; padding: 0; margin: 0; }
.mix-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.mix-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.mix-parts { margin-left: auto; font-weight: 600; }
.water { font-weight: 600; margin: 12px 0 0; }
.tip {
  background: rgba(244, 196, 48, 0.12);
  border: 1px solid rgba(244, 196, 48, 0.35);
  color: #f0dca0;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 12px;
}
.disclaimer {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 0;
}

/* ---------- Status / fel ---------- */
.status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.status.loading { background: rgba(122, 170, 90, 0.15); color: #aacb86; }
.status.error { background: rgba(176, 58, 46, 0.18); color: #f0a89e; }
.error { color: #f0a89e; font-size: 0.88rem; }
.warn {
  font-size: 0.82rem;
  color: #d8b0a8;
  background: rgba(176, 58, 46, 0.14);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.saved-msg { color: #8fbf6b; font-size: 0.85rem; margin-left: 8px; }

/* ---------- Färglista ---------- */
.color-list { list-style: none; padding: 0; margin: 12px 0 0; }
.color-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius);
  padding: 10px 0px;
  margin-bottom: 8px;
}
.color-list .swatch {
  width: 38px;
  height: 36px;
  flex-shrink: 0;
}
.color-list .info { flex: 1; min-width: 0; }
.color-list .info .name { font-weight: 600; }
.color-list .info .sub { font-size: 0.8rem; color: var(--muted); }
.color-list .actions {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}
.color-list .icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
  color: #8f96a3;
  cursor: pointer;
  transition:
    color 150ms ease,
    border-color 150ms ease,
    background-color 150ms ease,
    transform 150ms ease,
    box-shadow 150ms ease;
}
.color-list .icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.color-list .icon-btn:hover {
  transform: translateY(-1px);
}
.color-list .icon-btn.edit:hover {
  color: #d8e9c8;
  border-color: rgba(143, 191, 107, 0.35);
  background: rgba(143, 191, 107, 0.1);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.18);
}
.color-list .icon-btn.delete:hover {
  color: #f0a89e;
  border-color: rgba(240, 168, 158, 0.34);
  background: rgba(176, 58, 46, 0.12);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.18);
}
.color-list .icon-btn:active {
  transform: translateY(0) scale(0.96);
}
.color-list .icon-btn:focus-visible {
  outline: 2px solid #b9d99b;
  outline-offset: 2px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 13, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}
.modal-box {
  --surface: var(--module-bg);
  --bg: var(--module-bg-soft);
  --border: var(--module-border);
  --text: #e9eaf0;
  --muted: #989eac;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0)),
    var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-head h3 {
  margin: 0;
}
.ai-auto-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid rgba(169, 200, 145, 0.28);
  border-radius: 9px;
  background: rgba(169, 200, 145, 0.06);
  color: #c5dfaf;
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    color 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease;
}
.ai-auto-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ai-auto-btn:hover {
  border-color: rgba(169, 200, 145, 0.5);
  background: rgba(169, 200, 145, 0.1);
  color: #e3f3d5;
  transform: translateY(-1px);
}
.ai-auto-btn:disabled {
  opacity: 0.58;
  cursor: wait;
  transform: none;
}
.ai-auto-btn:focus-visible {
  outline: 2px solid rgba(143, 191, 107, 0.55);
  outline-offset: 2px;
}
.ai-hint-field {
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions .btn { width: auto; }
.photo-dropzone {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 74px;
  padding: 13px 14px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.025);
  color: #b7bec9;
  cursor: pointer;
  transition:
    color 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease;
}
.photo-dropzone svg {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.photo-drop-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.photo-drop-title {
  color: var(--text);
  font-weight: 600;
}
#photo-drop-meta {
  color: var(--muted);
  font-size: 0.82rem;
}
.photo-dropzone:hover,
.photo-dropzone.is-dragover {
  border-color: rgba(169, 200, 145, 0.48);
  background: rgba(169, 200, 145, 0.075);
  color: #c5dfaf;
}
.field:focus-within .photo-dropzone {
  outline: 2px solid rgba(143, 191, 107, 0.42);
  outline-offset: 2px;
  border-color: rgba(143, 191, 107, 0.5);
}
.photo-dropzone.has-photo {
  border-style: solid;
  border-color: rgba(169, 200, 145, 0.32);
}
.photo-preview {
  display: block;
  max-width: 140px;
  max-height: 120px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

/* ============ Mobil: stapla scen + sidebar ============ */
@media (max-width: 820px) {
  .app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
    background: var(--sidebar-bg);
  }
  .stage {
    order: 1;
    height: 36vh;
    min-height: 240px;
    flex: none;
  }
  .stage.has-image {
    height: 55vh;
    min-height: 340px;
  }
  .sidebar {
    display: contents;
    width: 100%;
    overflow-y: visible;
  }
  .sidebar-head {
    order: 0;
    position: static;
    width: 100%;
    background: var(--sidebar-bg);
    color: var(--text);
  }
  .sidebar > :not(.sidebar-head) {
    order: 2;
    width: auto;
    background: var(--sidebar-bg);
    color: var(--text);
  }
  .sidebar-module-nav,
  .module-panel {
    margin-left: 18px;
    margin-right: 18px;
    max-width: calc(100% - 36px);
  }
  .sidebar-module-nav {
    margin-top: 56px;
  }
  .module-nav-btn {
    min-width: 0;
  }
  .stage::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: clamp(64px, 16%, 140px);
    background: linear-gradient(to bottom, var(--sidebar-bg) 0%, rgba(20, 23, 30, 0) 100%);
    pointer-events: none;
    z-index: 2;
  }
  .dropzone {
    inset: 22px;
    width: calc(100% - 44px);
    height: calc(100% - 44px);
    max-width: none;
  }
  /* På mobil ligger sidebaren under scenen → fada nedåt i stället. */
  .stage::after {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: clamp(80px, 18%, 160px);
    background: linear-gradient(to bottom, rgba(20, 23, 30, 0) 0%, var(--sidebar-bg) 100%);
  }
}
