/* style.css */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&family=Montserrat:wght@400;600&display=swap");

/* ======================================================
   [CSS:ROOT] DESIGN TOKENS
====================================================== */
:root {
  --accent-start: #4fa9ff;
  --accent-end: #6edccf;

  --accent-hover-start: #6bb9ff;
  --accent-hover-end: #7fe5d8;

  --accent-pressed-start: #3f8fe0;
  --accent-pressed-end: #5bc9bc;

  --accent-outline: rgba(79, 169, 255, 0.35);

  --btn-bg: #ffffff;
  --btn-bg-soft: rgba(79, 169, 255, 0.06);
  --btn-border: rgba(79, 169, 255, 0.45);
  --btn-text: #0f172a;

  --btn-font: Poppins, system-ui, sans-serif;
  --btn-font-size: 14px;
  --btn-font-weight: 500;

  --btn-disabled-bg: #f1f5f9;
  --btn-disabled-text: #94a3b8;
  --btn-disabled-border: #e5e7eb;

  --section-bg: rgba(79, 169, 255, 0.05);
  --section-bg-hover: rgba(79, 169, 255, 0.08);
  --section-border: rgba(79, 169, 255, 0.25);
  --section-text: #0f172a;

  --select-bg: #ffffff;
  --select-border: rgba(79, 169, 255, 0.35);
  --select-text: #0f172a;

  --toggle-off-bg: #e5e7eb;
  --toggle-on-start: #6edccf;
  --toggle-on-end: #5bc9bc;

  --icon-size: 22px;
  --icon-gap: 8px;
}

/* ======================================================
   [CSS:BASE]
====================================================== */
body {
  margin: 0;
  font-family: Poppins, system-ui, sans-serif;
  background: #f3f4f6;
}

/* ======================================================
   [CSS:LAYOUT]
====================================================== */
.wix-root {
  width: 100%;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12px;
  box-sizing: border-box;
}

.app {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ======================================================
   [CSS:PREVIEW]
====================================================== */
.preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.design-area {
  width: 260px;
  height: 380px;
  border: 4px dashed rgba(239, 68, 68, 0.7);
  position: relative;
  background: #ffffff;
}

canvas {
  position: absolute;
  inset: 0;
}

.fot {
  width: 260px;
  max-height: 120px;
  object-fit: contain;
  margin-top: -6px;
  pointer-events: none;
}

/* ======================================================
   [CSS:MENU]
====================================================== */
.menu {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
}

.row {
  display: flex;
  gap: 10px;
}

.center {
  justify-content: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.split {
  display: flex;
  gap: 10px;
}

/* ======================================================
   [CSS:SECTIONS]
====================================================== */
.section-title {
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.06),
    rgba(110, 220, 207, 0.06)
  );
  color: var(--section-text);
  border: 1px solid var(--section-border);
  padding: 12px 14px;
  border-radius: 14px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 30px 1fr 18px;
  align-items: center;
  gap: 10px;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.1s ease;
}

.section-title:hover {
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.10),
    rgba(110, 220, 207, 0.10)
  );
  transform: translateY(-1px);
}

.section-title.open {
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.18),
    rgba(110, 220, 207, 0.18)
  );
  border-color: rgba(79, 169, 255, 0.45);
}

.section-body {
  display: none;
  padding-top: 12px;
}

.section-body.open {
  display: block;
}

/* ======================================================
   [CSS:BUTTONS]
====================================================== */
button,
.upload-label {
  background: var(--btn-bg-soft);
  color: var(--btn-text);
  border: 1px solid var(--btn-border);
  font-family: var(--btn-font);
  font-size: var(--btn-font-size);
  font-weight: var(--btn-font-weight);
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  gap: var(--icon-gap);
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.15s ease,
    transform 0.08s ease;
}

.upload-label {
  width: 100%;
  box-sizing: border-box;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.upload-label input {
  display: none;
}

.upload-label .label-text {
  line-height: 1.1;
}

button:hover {
  background: linear-gradient(
    135deg,
    var(--accent-hover-start),
    var(--accent-hover-end)
  );
  color: #ffffff;
  border-color: transparent;
}

.upload-label:hover {
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.10),
    rgba(110, 220, 207, 0.10)
  );
  color: var(--btn-text);
  border-color: rgba(79, 169, 255, 0.40);
}

button:active {
  background: linear-gradient(
    135deg,
    var(--accent-pressed-start),
    var(--accent-pressed-end)
  );
  transform: scale(0.97);
}

.upload-label:active {
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.16),
    rgba(110, 220, 207, 0.16)
  );
  transform: scale(0.99);
}

button:focus-visible,
.upload-label:focus-visible {
  outline: 2px solid var(--accent-outline);
  outline-offset: 2px;
}

button.active {
  background: linear-gradient(
    135deg,
    var(--accent-start),
    var(--accent-end)
  );
  color: #ffffff;
  border-color: transparent;
}

button.disabled,
button:disabled {
  background: var(--btn-disabled-bg);
  color: var(--btn-disabled-text);
  border-color: var(--btn-disabled-border);
  cursor: not-allowed;
  box-shadow: none;
}

button.disabled .icon,
button:disabled .icon {
  opacity: 0.55;
}

/* --- UX: full width primary text action --- */
#addText {
  width: 100%;
}

/* ======================================================
   [CSS:SIDE BUTTONS]
====================================================== */
#side1,
#side2 {
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.06),
    rgba(110, 220, 207, 0.06)
  );
  border: 1px solid var(--btn-border);
  border-radius: 14px;
  padding: 10px 18px;
  font-family: var(--btn-font);
  font-size: 14px;
  font-weight: 500;
  color: var(--btn-text);
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.08s ease,
    box-shadow 0.15s ease;
}

#side1:active,
#side2:active {
  transform: scale(0.98);
  box-shadow: 0 0 0 2px rgba(79, 169, 255, 0.18) inset;
}

#side1.active,
#side2.active {
  background: linear-gradient(
    135deg,
    var(--accent-start),
    var(--accent-end)
  );
  color: #ffffff;
  border-color: transparent;
  box-shadow: none;
}

#side2.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ======================================================
   [CSS:TEXT ALIGN]
====================================================== */
.text-align-group {
  background: transparent;
  border-radius: 14px;
  padding: 0;
  margin-top: 18px;
  margin-bottom: 24px;
}

.text-align-label {
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.05),
    rgba(110, 220, 207, 0.05)
  );
  border: 1px solid rgba(79, 169, 255, 0.25);
  border-radius: 16px;
  padding: 12px 12px;
  text-align: center;
  font-size: 14px;
  font-weight: var(--btn-font-weight);
  font-family: var(--btn-font);
  color: var(--btn-text);
  margin-bottom: 14px;
  opacity: 1;
}

.icon-row {
  display: flex;
  gap: 10px;
}

.icon-row button {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  min-height: 44px;
  width: 100%;
  padding: 10px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background 0.2s;
}

.icon-row button .icon {
  color: #6b7280;
}

.icon-row button:hover {
  border-color: rgba(79, 169, 255, 0.55);
}

.icon-row button.active {
  background: rgba(79, 169, 255, 0.10);
  border-color: rgba(79, 169, 255, 0.85);
}

.icon-row button.active .icon {
  color: rgba(79, 169, 255, 1);
}

.icon-row button:focus-visible {
  outline: 2px solid var(--accent-outline);
  outline-offset: 2px;
}

/* ======================================================
   [CSS:TOGGLE]
====================================================== */
.same-toggle {
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.05),
    rgba(110, 220, 207, 0.05)
  );
  border: 1px solid rgba(79, 169, 255, 0.25);
  border-radius: 16px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--btn-font);
  font-size: var(--btn-font-size);
  font-weight: var(--btn-font-weight);
  color: var(--btn-text);
}

.same-toggle input {
  appearance: none;
  width: 44px;
  height: 26px;
  background: rgba(15, 23, 42, 0.10);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.same-toggle input::after {
  content: "";
  width: 20px;
  height: 20px;
  background: #ffffff;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.same-toggle input:checked {
  background: linear-gradient(
    135deg,
    var(--toggle-on-start),
    var(--toggle-on-end)
  );
}

.same-toggle input:checked::after {
  transform: translateX(18px);
}

.same-toggle input:focus-visible {
  outline: 2px solid var(--accent-outline);
  outline-offset: 2px;
}

/* ======================================================
   [CSS:SELECT]
====================================================== */
select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--select-border);
  font-size: 14px;
  background: linear-gradient(
    135deg,
    rgba(79, 169, 255, 0.04),
    rgba(110, 220, 207, 0.04)
  );
  color: var(--select-text);
  appearance: none;
  font-family: var(--btn-font);
}

select + select {
  margin-top: 14px;
}

select:focus {
  outline: none;
}

select:focus-visible {
  outline: 2px solid var(--accent-outline);
  outline-offset: 2px;
  border-color: rgba(79, 169, 255, 0.55);
}

/* ======================================================
   [CSS:ICONS] IMG SVG SUPPORT
====================================================== */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  min-width: var(--icon-size);
  min-height: var(--icon-size);

  flex: 0 0 auto;
  flex-shrink: 0;
  line-height: 1;
}

/* === INLINE SVG (PRIMARY SYSTEM) === */
.icon svg {
  width: var(--icon-size);
  height: var(--icon-size);

  display: block;
  flex: 0 0 auto;
  overflow: visible;
  pointer-events: none;

  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;

  opacity: 1;
  visibility: visible;

  transition: transform 0.15s ease, opacity 0.2s ease;
}

button:hover .icon svg,
.section-title:hover .icon svg {
  transform: scale(1.05);
}

/* === IMG SVG (LEGACY / TRANSITION SYSTEM) === */
.icon img {
  width: var(--icon-size);
  height: var(--icon-size);
  display: block;
  filter: var(--icon-filter-base);
}

/* Hover -> blå */
button:hover .icon img,
.upload-label:hover .icon img,
.section-title:hover .icon img {
  filter: var(--icon-filter-hover);
}

/* Active/open -> grønn */
button.active .icon img,
.section-title.open .icon img {
  filter: var(--icon-filter-active);
}

/* Disabled -> dempet */
button.disabled .icon img,
#side2.disabled .icon img {
  filter: var(--icon-filter-disabled);
}

/* ======================================================
   [CSS:ICONS] ICON COLOR FIX
====================================================== */
.icon {
  color: currentColor;
  display: inline-flex;
  align-items: center;
}

/* ======================================================
   [CSS:ICONS] ICON STATE CONTROL
====================================================== */
.icon {
  color: currentColor;
  opacity: 1;
  transition: color 0.2s ease, opacity 0.2s ease;
}

button.disabled .icon,
button:disabled .icon {
  opacity: 0.6;
}

button:hover:not(.disabled) .icon,
.section-title:hover .icon {
  color: currentColor;
}

/* ======================================================
   [CSS:ICONS] ICON SIZES
====================================================== */
.icon.md {
  width: 24px;
  height: 24px;
}

.icon.sm {
  width: 18px;
  height: 18px;
}

/* ======================================================
   [CSS:COLOR BUTTONS]
====================================================== */
.color-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  padding: 14px 16px;
  min-height: 52px;

  position: relative;
  overflow: hidden;

  margin-top: 16px;
  margin-bottom: 20px;
}

/* Default state: color wheel */
.color-btn .swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: conic-gradient(
    red,
    yellow,
    lime,
    cyan,
    blue,
    magenta,
    red
  );
  border: 1px solid rgba(0,0,0,0.25);
  flex-shrink: 0;
}

/*
  When JS sets an inline background color
  (style="background: #xxxxxx"),
  it automatically overrides the gradient.
*/

/* iOS-safe invisible color input overlay */
.color-btn .color-input-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* 🔒 HARD DISABLE: block iOS color picker completely */
.color-btn.disabled .color-input-overlay {
  pointer-events: none;
}

/* Disabled state */
.color-btn.disabled {
  opacity: 0.45;
}

/* ======================================================
   [CSS:POPUP] POPUP SHELL (VISUAL STYLING – FASE 9.1E)
   – Stabil høyde
   – Kontrollert vertikal ekspansjon
   – Klar visuell hierarki (toolbar → panel)
   – Tydelig affordance for panel-knapper
====================================================== */
#popup {
  position: absolute;
  z-index: 9999;
  pointer-events: none;
  box-sizing: border-box;

  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 16px;

  padding: 10px;

  box-shadow:
    0 12px 30px rgba(15, 23, 42, 0.20);

  backdrop-filter: blur(6px);

  width: max-content;
  max-width: 260px;
}

/* ================= TOOLBAR ================= */

#popup [data-popup-toolbar] {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;

  white-space: normal;
}

/* Rows inside toolbar */
#popup [data-popup-toolbar] > [data-popup-row] {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;

  flex-shrink: 0;

  /* ⬇️ NYTT: rad-plate */
  padding: 6px 8px;
  background: rgba(241, 245, 249, 0.6);
  border-radius: 10px;
}

/* --- VISUELL STABLING (VERTIKAL) --- */
/* Kun vertikal rytme – ingen hard separators */
#popup [data-popup-toolbar] > [data-popup-row]:not(:last-child) {
  margin-bottom: 2px;
}

/* --- VISUELL STABLING (VERTIKAL) --- */
#popup [data-popup-toolbar] > [data-popup-row]:not(:last-child) {
  margin-bottom: 2px;
}

/* ================= PANEL ================= */

#popup [data-popup-panel] {
  display: none;
  margin-top: 10px;

  padding: 8px;

  background: rgba(241, 245, 249, 0.97);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 12px;

  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.6),
    0 6px 18px rgba(15, 23, 42, 0.12);

  transform-origin: top center;
}

#popup [data-popup-panel][data-open="true"] {
  display: block;
}

/* ================= GENERIC CONTROLS ================= */

#popup [data-popup-control] {
  pointer-events: auto;

  min-width: 32px;
  height: 32px;
  padding: 0 10px;

  background: rgba(241, 245, 249, 1);
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 10px;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;

  box-sizing: border-box;
  position: relative;

  font-family: system-ui, -apple-system, BlinkMacSystemFont;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1px;
  color: rgba(15, 23, 42, 0.85);

  white-space: nowrap;

  /* iOS-like tappable feel */
  transition:
    background 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease,
    color 140ms ease,
    transform 80ms ease;
}

/* Hover / hover-equivalent */
#popup [data-popup-control]:hover {
  background: rgba(226, 232, 240, 1);
  border-color: rgba(15, 23, 42, 0.18);
}

/* Press feedback (iOS-style) */
#popup [data-popup-control]:active {
  transform: translateY(0.5px);
}

/* Active / toggled state */
#popup [data-popup-control][data-active="true"] {
  background: linear-gradient(
    180deg,
    rgba(96, 165, 250, 1),
    rgba(59, 130, 246, 1)
  );
  border-color: rgba(37, 99, 235, 1);
  color: #ffffff;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.35),
    0 4px 10px rgba(59,130,246,0.35);
}

/* ================= CONTROL SEMANTICS ================= */

/* Font-knapp: primær / modus */
#popup [data-popup-control="font"] {
  min-width: 88px;
  justify-content: space-between;
  padding: 0 14px;
  font-weight: 600;
}

/* Alignment: presise, mekaniske */
#popup [data-popup-control^="align-"] {
  width: 36px;
  min-width: 36px;
  padding: 0;
}

/* Text-style toggles: lette */
#popup [data-popup-control="bold"],
#popup [data-popup-control="italic"],
#popup [data-popup-control="underline"],
#popup [data-popup-control="strike"] {
  min-width: 34px;
  padding: 0 6px;
  font-weight: 600;
}

/* ---------- ICON GLYPHS ---------- */

#popup [data-popup-control]::before {
  display: inline-block;
  font-size: 13px;
  line-height: 1;
  opacity: 0.85;
}

/* Text styles */
#popup [data-popup-control="bold"]::before { content: "B"; }
#popup [data-popup-control="italic"]::before { content: "I"; font-style: italic; }
#popup [data-popup-control="underline"]::before { content: "U"; text-decoration: underline; }
#popup [data-popup-control="strike"]::before { content: "S"; text-decoration: line-through; }

/* Color */
#popup [data-popup-control="color"] {
  padding: 0;
  min-width: 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background:
    conic-gradient(
      red,
      yellow,
      lime,
      cyan,
      blue,
      magenta,
      red
    );
  border: 1px solid rgba(15, 23, 42, 0.18);
  position: relative;
}

#popup [data-popup-control="color"]::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--popup-text-color, #000000);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.65),
    0 0 0 1px rgba(15,23,42,0.15);
}

/* Font */
#popup [data-popup-control="font"]::before {
  content: "Aa";
  letter-spacing: -0.5px;
}

/* Alignment */
#popup [data-popup-control^="align-"]::before {
  content: "≡";
  font-size: 14px;
}

#popup [data-popup-control="align-left"]::before { content: "≡"; }
#popup [data-popup-control="align-center"]::before { content: "≣"; }
#popup [data-popup-control="align-right"]::before { content: "≡"; }

/* ---------- STATES ---------- */

#popup [data-popup-control]:hover {
  background: rgba(226, 232, 240, 1);
  border-color: rgba(15, 23, 42, 0.14);
}

/* Press feedback (iOS-like) */
#popup [data-popup-control]:active {
  transform: translateY(0.5px);
}

/* Active state = clear semantic signal */
#popup [data-popup-control][data-active="true"] {
  background: linear-gradient(
    180deg,
    rgba(96, 165, 250, 1),
    rgba(59, 130, 246, 1)
  );
  border-color: rgba(37, 99, 235, 1);
  color: #ffffff;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.35);
}

#popup [data-popup-control][data-active="true"]::before {
  opacity: 1;
}

/* ================= PANEL TOGGLE AFFORDANCE ================= */

/* Font-knapp: subtil indikator for "har panel" */
#popup [data-popup-control="font"]::after {
  content: "";
  position: absolute;
  bottom: 4px;
  width: 12px;
  height: 2px;
  border-radius: 2px;
  background: rgba(15, 23, 42, 0.25);
  opacity: 0.6;
}

/* Når font-panel er åpent */
#popup [data-popup-control="font"][data-active="true"] {
  background: linear-gradient(
    180deg,
    rgba(96, 165, 250, 1),
    rgba(59, 130, 246, 1)
  );
  border-color: rgba(37, 99, 235, 1);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.35),
    0 4px 10px rgba(59,130,246,0.35);
}

#popup [data-popup-control="font"][data-active="true"]::after {
  background: rgba(255,255,255,0.85);
  opacity: 1;
}

/* ================= FONT PANEL ================= */

#popup [data-popup-group="font-list"] {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Font item */
#popup [data-popup-control="font-item"] {
  pointer-events: auto;

  min-height: 36px;
  padding: 6px 12px;

  background: rgba(255, 255, 255, 1);
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 10px;

  /* 🔒 LÅS UI-FONT – IGNORER INLINE fontFamily */
  font-family: system-ui, -apple-system, BlinkMacSystemFont !important;
  font-size: 13px;
  line-height: 1.2;

  display: flex;
  align-items: center;
  justify-content: space-between;

  white-space: nowrap;

  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

#popup [data-popup-control="font-item"]::after {
  content: "Aa";
  font-size: 11px;
  opacity: 0.35;
  margin-left: 12px;
}

#popup [data-popup-control="font-item"]:hover {
  background: rgba(226, 232, 240, 1);
  transform: translateX(1px);
}

/* ================= ACTIVE FONT ================= */

#popup
  [data-popup-control="font-item"][data-active="true"] {
  background: linear-gradient(
    180deg,
    rgba(96, 165, 250, 1),
    rgba(59, 130, 246, 1)
  );
  border-color: rgba(37, 99, 235, 1);
  color: #ffffff;
  font-weight: 600;
}

#popup
  [data-popup-control="font-item"][data-active="true"]::after {
  content: "Aktiv";
  font-size: 11px;
  opacity: 0.9;
}