@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Shadcn Light Theme (HSL) */
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;

  /* App Specific */
  --stage-w: 1280px;
  --stage-h: 720px;
  --stage-aspect: 16/9;
  --editor-w: min(95vw, 1280px);
  --font-family: "Inter", sans-serif;
}

.dark {
  /* Modern Soft Dark Theme (Slate/Zinc hybrid) */
  --background: 224 10% 10%;
  /* Softer dark grey, not black */
  --foreground: 210 20% 98%;
  /* Soft white */

  --card: 224 10% 12%;
  /* Slightly lighter than bg */
  --card-foreground: 210 20% 98%;

  --popover: 224 10% 12%;
  --popover-foreground: 210 20% 98%;

  --primary: 210 40% 98%;
  --primary-foreground: 222.2 47.4% 11.2%;

  --secondary: 230 10% 8%;
  /* Distinct secondary for inputs/buttons */
  --secondary-foreground: 210 20% 98%;

  --muted: 217 19% 20%;
  --muted-foreground: 215 20% 65%;
  /* Softer text for labels */

  --accent: 217 19% 27%;
  --accent-foreground: 210 20% 98%;

  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 210 20% 98%;

  --border: 217 19% 20%;
  /* Soft border */
  --input: 217 19% 20%;
  --ring: 224 71% 60%;
  /* A nice blueish ring for focus */
}

.theme-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 100;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: hsl(var(--accent));
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  transition: all 0.2s;
}

.dark .theme-toggle .sun {
  display: block;
}

.dark .theme-toggle .moon {
  display: none;
}

.theme-toggle .sun {
  display: none;
}

.theme-toggle .moon {
  display: block;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  /* Optional: also remove default focus outline if desired, but user said 'blue blinking' which is tap highlight */
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: hsl(var(--muted-foreground));
}

/* Firefox support */
* {
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--border)) transparent;
}

body {
  background-color: hsl(var(--secondary));
  /* Light Gray Bg */
  color: hsl(var(--foreground));
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px;
}

/* ============ HEADER GRID ============ */
header {
  width: 100%;
  max-width: var(--editor-w);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 5px;
  width: 100%;
}

.card {
  background-color: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
}

.card-header {
  padding: 8px 12px 4px 12px;
}

.card-header h3 {
  margin: 0;
  font-size: 14px;
  /* Smaller header */
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-content {
  padding: 0 12px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ============ FORM CONTROLS ============ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.form-group label {
  font-size: 12px;
  /* Smaller label */
  font-weight: 500;
  color: hsl(var(--muted-foreground));
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

select {
  height: 30px;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--input));
  background-color: transparent;
  padding: 0 10px;
  font-size: 13px;
  /* smaller font */
  font-family: inherit;
  color: hsl(var(--foreground));
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.25em 1.25em;
}

select:focus {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--ring));
  border-color: hsl(var(--ring));
}

/* SLIDERS */
.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
}

.slider-row span {
  font-size: 11px;
  /* Smaller font */
  font-feature-settings: "tnum";
  width: 44px;
  text-align: right;
  color: hsl(var(--foreground));
  flex-shrink: 0;
}

input[type="range"] {
  flex: 1;
  appearance: none;
  background: transparent;
  cursor: pointer;
  height: 14px;
  /* Reduced from 24px */
  touch-action: pan-y;
  margin: 0;
  width: 100%;
}

/* Webkit Track */
input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  /* Reduced from 6px */
  cursor: pointer;
  background: hsl(var(--secondary));
  border-radius: 999px;
  transition: background 0.2s;
}

/* Webkit Thumb */
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  border: 1px solid hsl(var(--primary));
  /* Thinner border */
  height: 14px;
  /* Reduced from 20px */
  width: 14px;
  border-radius: 50%;
  background: hsl(var(--background));
  cursor: grab;
  margin-top: -5px;
  /* (14 - 4) / 2 = 5. Negate. */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.1s, box-shadow 0.2s;
}

/* Hover/Active States */
input[type="range"]:hover::-webkit-slider-runnable-track {
  background: hsl(var(--muted));
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.15);
  cursor: grabbing;
  box-shadow: 0 0 0 4px rgba(var(--primary), 0.2);
}

/* Firefox Track */
input[type="range"]::-moz-range-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: hsl(var(--secondary));
  border-radius: 999px;
}

/* Firefox Thumb */
input[type="range"]::-moz-range-thumb {
  border: 1px solid hsl(var(--primary));
  height: 14px;
  width: 14px;
  border-radius: 50%;
  background: hsl(var(--background));
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* COLORS */
.color-wrapper {
  height: 32px;
  /* reduced height */
  width: 100%;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  background: var(--picker-color, #ffffff);
}

input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  border: none;
  cursor: pointer;
  opacity: 0;
}

.selection-color-popup {
  position: absolute;
  top: calc(100% + 8px);
  right: -1px;
  width: min(330px, calc(100vw - 24px));
  padding: 10px;
  background: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: 6px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  display: none;
  z-index: 10000;
}

.selection-color-popup.open {
  display: block;
}

.selection-color-area {
  position: relative;
  height: 170px;
  border-radius: 4px;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  background:
    linear-gradient(to top, #000, transparent),
    linear-gradient(to right, #fff, hsl(var(--selection-hue, 213) 100% 50%));
}

.selection-color-area__handle {
  position: absolute;
  left: calc(var(--selection-saturation, 100) * 1%);
  top: calc((100 - var(--selection-value, 100)) * 1%);
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.selection-color-controls {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.selection-color-dot {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--picker-color, #006eff);
  border: 1px solid hsl(var(--border));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.selection-hue {
  width: 100%;
  height: 14px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  appearance: none;
}

.selection-hue::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.selection-hue::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.selection-color-fields {
  display: grid;
  grid-template-columns: 1.25fr repeat(3, 0.75fr);
  gap: 8px;
  margin-top: 10px;
}

.selection-color-fields label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.selection-color-fields span {
  font-size: 10px;
  line-height: 1.2;
  font-weight: 700;
  color: hsl(var(--muted-foreground));
}

.selection-color-fields input {
  width: 100%;
  height: 30px;
  border-radius: 4px;
  border: 1px solid hsl(var(--input));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0 8px;
  font: inherit;
  font-size: 12px;
}

.selection-color-popup__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.selection-color-popup__header {
  display: none;
}

.selection-color-popup__actions .btn {
  flex: 1;
  height: 36px;
  font-size: 13px;
  border-radius: var(--radius);
  font-weight: 700;
}

.selection-color-popup__actions .btn.ghost {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border: 1px solid hsl(var(--border));
}

.selection-color-popup__actions .btn.ghost:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.selection-color-popup__actions .btn.primary {
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  border: 1px solid hsl(var(--foreground));
}

.selection-color-popup__actions .btn.primary:hover {
  opacity: 0.9;
}

/* ACTION BAR */
.action-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  padding: 10px 12px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  gap: 5px;
  width: 100%;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.action-templates {
  justify-content: flex-start;
}

.action-text-tools {
  justify-content: center;
}

.action-output {
  justify-content: flex-end;
  padding-left: 4px;
}

.variable-picker {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr);
  gap: 6px;
  width: min(100%, 430px);
  min-width: 0;
}

#variableCaseWrapper,
#variableInsertWrapper {
  width: 100%;
  min-width: 0;
}

.variable-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 2px;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  border-radius: 8px;
}

.variable-token {
  font-size: 12px;
  min-height: 26px;
  white-space: nowrap;
  padding-inline: 8px;
  border-radius: 6px;
  border: 1px dashed hsl(var(--border));
}

.variable-token.btn.ghost {
  color: hsl(var(--foreground));
}

.variable-token.btn.ghost:hover {
  background: hsl(var(--card));
}

.action-label {
  font-size: 11px;
  font-weight: 700;
  color: hsl(var(--muted-foreground));
  letter-spacing: 0;
  text-transform: uppercase;
  white-space: nowrap;
}

/* CUSTOM DROPDOWN */
.custom-select-wrapper {
  position: relative;
  user-select: none;
  width: 100%;
}

#presetSelectWrapper {
  width: 220px;
  /* Fixed width for presets on desktop */
}

@media (max-width: 768px) {
  #presetSelectWrapper {
    width: 100%;
    /* Full width on mobile */
  }

  #variableInsertWrapper {
    width: 100%;
  }
}

.custom-select-trigger {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 400;
  color: hsl(var(--foreground));
  height: 28px;
  line-height: 28px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.custom-select-trigger:hover {
  border-color: hsl(var(--ring));
}

.arrow {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid hsl(var(--muted-foreground));
}

.custom-options {
  position: absolute;
  display: none;
  top: 100%;
  left: 0;
  right: 0;
  background: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 50;
  margin-top: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.custom-options.open {
  display: block;
}

.custom-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 13px;
  color: hsl(var(--popover-foreground));
  cursor: pointer;
  transition: background 0.1s;
}

.custom-option:hover {
  background: hsl(var(--accent));
}

.variable-case-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  align-items: center;
}

.variable-case-option span {
  min-width: 0;
}

.variable-case-option small {
  color: hsl(var(--muted-foreground));
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
}

.option-delete {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: hsl(var(--muted-foreground));
  font-size: 14px;
  line-height: 1;
  transition: all 0.2s;
}

.option-delete:hover {
  background: hsl(var(--destructive));
  color: white;
}

/* BASE BUTTON STYLE */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 30px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn.small {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.btn.primary {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border: none;
}

.btn.primary:hover {
  opacity: 0.9;
}

.btn.secondary {
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border: none;
}

.btn.secondary:hover {
  background-color: hsl(var(--muted));
}

.btn.ghost {
  background: transparent;
  color: hsl(var(--muted-foreground));
  border: none;
}

.btn.ghost:hover {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}


/* ============ STAGE (CANVAS) ============ */
.center-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.scale-note {
  font-size: 14px;
  color: hsl(var(--muted-foreground));
  text-align: center;
  margin: 8px 0 0 0;
  padding: 0 16px;
}

.stage {
  width: min(95vw, 1280px);
  aspect-ratio: var(--stage-aspect);
  background: #111;
  position: relative;
  border-radius: 0;
  border: none;
  overflow: hidden;
  box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.7);
  /* Deep Shadow Restored */
  isolation: isolate;
  touch-action: none;
}

.stage.format-square {
  width: min(95vw, 760px);
}

.stage.format-portrait {
  width: min(95vw, 430px);
}

.tiles-container {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.tile {
  position: absolute;
  overflow: hidden;
  background: #0f1014;
  border: 1px dashed rgba(255, 255, 255, 0.1);
  transition: border 0.2s;
}

.tile.loaded {
  border: none;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.3);
  font-size: 14px;
}

.tile.loaded::after {
  display: none;
}

/* DELETE BUTTON ON TILE */
.tile-delete-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  /* Semi-transparent dark background */
  background: rgba(0, 0, 0, 0.4);
  color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  border-radius: 50%;

  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 50;
  opacity: 0;
  transform: scale(0.9);
  transition: all 0.2s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.tile.loaded:hover .tile-delete-btn,
.tile.loaded.manual-hover .tile-delete-btn {
  opacity: 1;
  transform: scale(1);
}

.tile-actions {
  position: absolute;
  display: flex;
  gap: 6px;
  z-index: 30;
}

.tile-actions[data-corner="top-left"] {
  top: 8px;
  left: 8px;
}

.tile-actions[data-corner="top-right"] {
  top: 8px;
  right: 8px;
}

.tile-actions[data-corner="bottom-left"] {
  bottom: 8px;
  left: 8px;
}

.tile-actions[data-corner="bottom-right"] {
  right: 8px;
  bottom: 8px;
}

.tile[data-action-corner="top-right"] .tile-delete-btn {
  right: auto;
  left: 10px;
}

.tile-action-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.tile-action-btn:hover {
  background: rgba(0, 0, 0, 0.78);
}

.tile-delete-btn:hover {
  background: #ef4444;
  /* Red on hover */
  color: white;
  transform: scale(1.1) !important;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* Ensure it doesn't appear when not loaded (double check) */
.tile:not(.loaded) .tile-delete-btn {
  display: none;
}

/* Hide during drag too */
.tile.dragging .tile-delete-btn {
  display: none !important;
}

.h2c-hide-hints .tile-actions,
.h2c-hide-hints .tile-delete-btn,
.h2c-hide-hints .tile-hint {
  display: none !important;
}

.tile img {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(var(--scale, 1)) translate(var(--tx, 0px), var(--ty, 0px));
  min-width: 100%;
  min-height: 100%;
  object-fit: cover;
  display: none;
  /* Prevent default drag behavior */
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  /* Let clicks pass to tile container for pointer events */
}

.tile.loaded img {
  display: block;
}

.tile input {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, var(--overlay-opacity));
  pointer-events: none;
  z-index: 10;
}

.text-band {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1500px;
  height: var(--band-h);
  background: rgba(0, 0, 0, var(--band-opacity));
  transform: translate(-50%, -50%) rotate(var(--band-rotate)) translateY(var(--band-offset-y));
  z-index: 20;
  display: grid;
  place-items: center;
  pointer-events: none;
  /* Allow clicks to pass through to tiles */
}

.band-text {
  /* Dynamic styles injected via JS usually, but defaults here */
  color: var(--text-color);
  font-size: var(--text-size);
  font-family: var(--font-family);
  font-weight: var(--font-weight, 700);
  font-style: var(--font-style, normal);
  line-height: 1.2;
  text-align: center;
  outline: none;
  width: calc(var(--stage-w) * 0.96);
  max-width: calc(var(--stage-w) * 0.96);
  min-width: 0;
  box-sizing: border-box;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  contain: inline-size;
  transform: translateY(var(--text-offset-y));
  pointer-events: auto;
  /* Allow text selection/editing */
}

.band-text::selection,
.band-text *::selection {
  background: rgba(20, 118, 242, 0.08);
}

.custom-select-trigger.disabled {
  color: hsl(var(--muted-foreground));
  background: hsl(var(--muted));
}

.band-text * {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Keep editor controls stable while the canvas format changes */
header {
  width: 100%;
  max-width: var(--editor-w);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* TILE HINTS & HOVER EFFECTS */
.tile-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: opacity 0.3s ease;
  pointer-events: none;
  /* Let clicks pass through container */
  user-select: none;
  /* Prevent text selection */
}

/* Hide hint completely when dragging to prevent any interference */
.tile.dragging .tile-hint {
  display: none !important;
}

/* Default state (unloaded): visible and clickable */

/* Default state (unloaded): visible and clickable */
.tile:not(.loaded) .tile-hint {
  opacity: 1;
  pointer-events: auto;
}

/* Loaded state: hidden by default, but ready to fade in */
.tile.loaded .tile-hint {
  opacity: 0;
  pointer-events: none;
}

/* Show on hover when loaded */
.tile.loaded:hover .tile-hint,
.tile.loaded.manual-hover .tile-hint {
  opacity: 1;
  /* background: rgba(0, 0, 0, 0.4); REMOVED: No dimming */
  /* backdrop-filter: blur(2px); REMOVED */
  /* Container remains pointer-events: none so panning works on empty space */
}

/* Ensure text/buttons are interactive */
.hint-top,
.hint-bottom {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1;
  width: 100%;
  align-items: center;
  justify-content: center;
}

.hint-top span,
.hint-bottom span {
  padding: 8px 16px;
  /* Slightly darker button bg for contrast */
  border-radius: 20px;
  transition: background 0.2s, opacity 0.2s;
  /* Add subtle scale effect */
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  opacity: 0.6;
  cursor: pointer;
  pointer-events: auto;
}


/* Separate gradients for top vs bottom hover via pseudo-elements for smoothness */
.tile-hint::before,
.tile-hint::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: -1;
}

.tile-hint::before {
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.03), transparent);
}

.tile-hint::after {
  background: linear-gradient(to top, rgba(255, 255, 255, 0.03), transparent);
}

.tile-hint:has(.hint-top:hover)::before {
  opacity: 1;
}

.tile-hint:has(.hint-bottom:hover)::after {
  opacity: 1;
}

/* Remove default darken to let gradient show */
.hint-top:hover,
.hint-bottom:hover {
  color: rgba(255, 255, 255, 1);
  background: transparent;
}

.hint-top:hover span,
.hint-bottom:hover span {
  opacity: 1;
}

.tile .hover {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 5;
}

.tile:hover .hover,
.tile.manual-hover .hover {
  opacity: 1;
}

.band-text:empty::before {
  content: "Ваш заголовок...";
  opacity: 0.5;
}

/* ============ PRESETS & LIBRARY (Collapsible?) ============ */
/* ============ PRESETS & LIBRARY (Collapsible?) ============ */
.presets-section {
  width: var(--editor-w);
}

.presets-container {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 16px;
}

.presets-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid hsl(var(--border));
  margin-bottom: 12px;
}

.presets-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: hsl(var(--foreground));
  display: flex;
  align-items: center;
  gap: 8px;
}

.presets-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  /* Space for scrollbar if needed */
}

.preset-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: hsl(var(--secondary));
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

.preset-item:hover {
  background: hsl(var(--muted));
  border-color: hsl(var(--border));
}

.preset-item .remove-preset {
  opacity: 0.5;
  cursor: pointer;
  padding: 2px;
}

.preset-item .remove-preset:hover {
  opacity: 1;
  color: hsl(var(--destructive));
}

/* LIBRARY MODAL (Shadcn Style) */
.library-modal {
  display: none;
  /* JS toggles */
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  place-items: center;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.library-modal-content {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  width: 90vw;
  max-width: 900px;
  height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0 auto;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.library-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid hsl(var(--border));
}

.library-modal-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: hsl(var(--muted-foreground));
  border-radius: var(--radius);
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  transition: background 0.2s;
}

.close-btn:hover {
  background: hsl(var(--accent));
  color: hsl(var(--foreground));
}

.library-modal-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar for Categories */
.library-categories {
  width: 240px;
  background: hsl(var(--card));
  /* Light gray sidebar */
  border-right: 1px solid hsl(var(--border));
  padding: 16px;
  overflow-y: auto;
}

.categories-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.category-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  transition: all 0.2s;
}

.category-item:hover {
  background: rgba(0, 0, 0, 0.05);
  color: hsl(var(--foreground));
}

.dark .category-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.category-item.active {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  font-weight: 600;
  box-shadow: none;
  border-left: 3px solid hsl(var(--primary));
  border-radius: 4px;
}

/* Photos Grid */
.library-photos {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  background: hsl(var(--background));
}

.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
}

.photo-item {
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  background: hsl(var(--muted));
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}

.photo-item:hover {
  border-color: hsl(var(--primary));
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.photo-item:hover img {
  transform: scale(1.05);
}

.library-hint {
  grid-column: 1 / -1;
  text-align: center;
  color: hsl(var(--muted-foreground));
  margin-top: 40px;
}

/* BATCH GENERATION */
.batch-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(4px);
  z-index: 110;
  place-items: center;
  animation: fadeIn 0.2s ease-out;
}

.batch-modal,
.batch-modal * {
  box-sizing: border-box;
}

.batch-modal-content {
  width: min(1120px, 94vw);
  height: min(780px, 86vh);
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.24);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.batch-modal-body {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  overflow: hidden;
}

.batch-panel {
  min-height: 0;
  padding: 18px;
  overflow: auto;
}

.batch-panel-left {
  border-right: 1px solid hsl(var(--border));
  background: hsl(var(--secondary));
}

.batch-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.batch-section h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.batch-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.batch-vars {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.batch-var {
  border: 1px solid hsl(var(--border));
  background: hsl(var(--background));
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
}

.batch-var.unknown {
  color: hsl(var(--destructive));
  border-color: hsl(var(--destructive));
}

.batch-hint {
  color: hsl(var(--muted-foreground));
  font-size: 12px;
  line-height: 1.4;
  margin: 0;
}

.batch-search {
  width: 100%;
  height: 38px;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0 11px;
  font: inherit;
}

.geo-toggle {
  width: 100%;
}

.geo-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.geo-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
  padding: 10px;
}

.geo-case-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
}

.geo-case-group strong {
  grid-column: 1 / -1;
  font-size: 12px;
  color: hsl(var(--foreground));
}

.geo-case-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.geo-case-field span {
  font-size: 11px;
  line-height: 1.2;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
}

.geo-editor input {
  width: 100%;
  height: 34px;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0 9px;
  font: inherit;
}

.geo-editor-actions {
  display: flex;
  gap: 8px;
}

.geo-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
  cursor: pointer;
}

.geo-item:hover {
  border-color: hsl(var(--ring));
}

.geo-item input {
  margin-top: 3px;
}

.geo-name {
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.geo-meta {
  display: block;
  margin-top: 2px;
  color: hsl(var(--muted-foreground));
  font-size: 12px;
}

.geo-actions {
  display: flex;
  gap: 4px;
}

.geo-action {
  width: 26px;
  height: 26px;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--secondary));
  color: hsl(var(--foreground));
  cursor: pointer;
}

.batch-preview {
  min-height: 76px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--secondary));
  padding: 14px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.25;
  white-space: pre-wrap;
}

.batch-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.batch-count {
  color: hsl(var(--muted-foreground));
  font-size: 13px;
  font-weight: 600;
}

.batch-progress {
  color: hsl(var(--muted-foreground));
  font-size: 13px;
  min-height: 20px;
}

.batch-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.batch-result {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
  font-size: 13px;
}

.batch-result strong {
  display: block;
  margin-bottom: 2px;
}

.batch-result-warning {
  display: block;
  margin-top: 3px;
  color: hsl(var(--ring));
  font-size: 12px;
  font-weight: 700;
}

.batch-result a {
  color: hsl(var(--foreground));
  font-weight: 700;
}

.batch-result[data-kind="archive"] {
  border-color: hsl(var(--ring));
  background: hsl(var(--secondary));
}

.batch-result[data-kind="archive"] a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--radius);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  text-decoration: none;
}

.batch-result.error {
  border-color: hsl(var(--destructive));
}

/* MOBILE ADAPTATION */
@media (max-width: 768px) {

  /* APP CONTAINER */
  .app {
    gap: 4px;
    padding: 6px;
  }

  /* HEADER & CONTROL GRID */
  header {
    gap: 4px;
  }

  .control-grid {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .row-2 {
    gap: 6px;
  }

  .card-header {
    padding: 8px 12px 2px 12px;
  }

  .card-header h3 {
    font-size: 13px;
  }

  .card-content {
    padding: 0 12px 8px 12px;
    gap: 4px;
    /* Reduced from 8px */
  }

  .form-group {
    gap: 1px;
    /* Reduced from default */
  }

  .form-group label {
    font-size: 11px;
    margin-bottom: 0px;
  }

  select {
    height: 30px;
    font-size: 12px;
  }

  .slider-row {
    padding: 0;
    /* Remove vertical padding */
    gap: 8px;
    /* Slightly tighter horizontal gap */
  }

  .slider-row span {
    font-size: 11px;
    width: 36px;
  }

  /* ACTION BAR - stack on mobile */
  .action-bar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px;
  }

  .action-group {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
  }

  .action-templates {
    justify-content: space-between;
  }

  .action-text-tools,
  .action-output {
    justify-content: space-between;
    flex-wrap: wrap;
    padding-left: 0;
  }

  .variable-toolbar {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 2px;
  }

  .variable-picker {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .variable-token {
    flex: 1 1 31%;
    min-width: 0;
    padding-inline: 8px;
  }

  .action-label {
    font-size: 12px;
    flex-shrink: 0;
  }

  .custom-select-wrapper {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .custom-select-trigger {
    height: 30px;
    line-height: 30px;
    font-size: 13px;
    padding: 0 10px;
  }

  .btn {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
  }

  .action-text-tools > .btn,
  .action-output > .btn {
    flex: 1;
  }

  .btn.small {
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
  }

  /* Compact Sliders for Mobile */
  input[type="range"] {
    height: 24px;
    margin: 0;
  }

  input[type="range"]::-webkit-slider-thumb {
    height: 20px;
    width: 20px;
    margin-top: -7px;
  }

  input[type="range"]::-moz-range-thumb {
    height: 20px;
    width: 20px;
  }

  /* SCALE NOTE */
  .scale-note {
    font-size: 12px;
    padding: 0 12px;
  }

  /* TILE HINTS */
  .hint-top,
  .hint-bottom {
    font-size: 12px;
  }

  /* LIBRARY MODAL */
  .library-modal-content {
    width: 100%;
    height: 100%;
    max-width: 100%;
    border-radius: 0;
    border: none;
  }

  .batch-modal-content {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .batch-modal .library-modal-header {
    min-width: 0;
    padding: 12px 14px;
    gap: 10px;
  }

  .batch-modal .library-modal-header h2 {
    min-width: 0;
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .batch-modal .close-btn {
    flex: 0 0 32px;
  }

  .batch-modal-body {
    display: block;
    overflow: auto;
    width: 100%;
  }

  .batch-panel {
    width: 100%;
    min-width: 0;
    padding: 14px;
    overflow: visible;
  }

  .batch-panel-left {
    border-right: 0;
    border-bottom: 1px solid hsl(var(--border));
  }

  .batch-result {
    grid-template-columns: 1fr;
  }

  .batch-section-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .batch-section-head .btn {
    flex: 0 0 auto;
  }

  .geo-editor-actions,
  .batch-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .geo-editor-actions .btn,
  .batch-actions .btn {
    width: 100%;
  }

  .geo-case-group {
    grid-template-columns: 1fr;
  }

  .geo-item {
    grid-template-columns: auto minmax(0, 1fr);
    width: 100%;
  }

  .geo-actions {
    grid-column: 2;
    justify-self: start;
    margin-top: 4px;
  }

  .geo-name,
  .geo-meta,
  .batch-preview,
  .batch-result {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .batch-preview {
    font-size: 18px;
  }

  .library-modal-body {
    flex-direction: column;
  }

  .library-categories {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid hsl(var(--card));
    padding: 12px;
  }

  .library-hint {
    display: none;
  }

  .category-item {
    background: rgba(255, 255, 255, 0.5);
    color: hsl(var(--foreground));
  }

  .categories-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .library-photos {
    padding: 16px;
  }

  .photos-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
  }

  /* Theme Toggle FAB */
  .theme-toggle {
    position: fixed;
    top: auto;
    bottom: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    background: hsl(var(--card));
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    border: 1px solid hsl(var(--border));
    border-radius: 50%;
    z-index: 1000;
  }

  .dark .theme-toggle {
    background: hsl(var(--background));
    border-color: hsl(var(--border));
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .app {
    gap: 6px;
    padding: 6px;
  }

  .action-bar {
    padding: 6px;
  }

  .action-label {
    display: none;
  }

  .action-group {
    flex-wrap: wrap;
    justify-content: center;
  }

  .scale-note {
    font-size: 11px;
  }

  .tile::after {
    font-size: 8px;
  }
}

/* PASSWORD MODAL OVERLAY */
.password-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s;
}

.password-modal {
  background: hsl(var(--card));
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 250px;
}

.password-modal h3 {
  margin: 0;
  font-size: 16px;
}

.password-modal p {
  margin: 0;
  font-size: 13px;
  color: hsl(var(--muted-foreground));
}

.pass-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.pass-row input {
  flex: 1;
  text-align: center;
  letter-spacing: 3px;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  height: 32px;
}

/* ADD PHOTO TILE */
.add-photo-item {
  aspect-ratio: 1;
  border: 2px dashed hsl(var(--border));
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: hsl(var(--muted-foreground));
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.03);
}

.add-photo-item:hover {
  border-color: hsl(var(--primary));
  color: hsl(var(--primary));
  background: rgba(255, 255, 255, 0.06);
}

.add-photo-icon {
  font-size: 24px;
  line-height: 1;
  margin-bottom: 4px;
}

.add-photo-text {
  font-size: 11px;
  font-weight: 500;
}

/* SPINNER */
.icon-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid hsl(var(--muted-foreground));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* DELETE BUTTONS */
.photo-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 5;
  font-size: 16px;
  line-height: 1;
}

.photo-item:hover .photo-delete-btn {
  opacity: 1;
}

.photo-delete-btn:hover {
  background: red;
  transform: scale(1.1);
}

/* CATEGORY MANAGEMENT */
.categories-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 40px;
  /* Space for add btn */
}

.category-item {
  position: relative;
  padding-right: 30px;
  /* Space for delete btn */
}

.category-delete-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--destructive));
  opacity: 0;
  cursor: pointer;
  border-radius: 4px;
}

.category-item:hover .category-delete-btn {
  opacity: 1;
}

.category-delete-btn:hover {
  background: hsla(var(--destructive), 0.1);
}

.add-category-btn {
  margin-top: 10px;
  width: 100%;
  justify-content: center;
  border-style: dashed;
}

/* ADMIN PANEL */
.admin-panel {
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  padding: 12px;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.admin-auth-form {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.admin-auth-form input {
  width: 120px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  text-align: center;
  letter-spacing: 2px;
}

.admin-upload-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-row {
  display: flex;
  gap: 8px;
}

.upload-row select {
  flex: 1;
}

.upload-preview {
  width: 100%;
  height: 120px;
  background: hsl(var(--secondary));
  border-radius: var(--radius);
  display: none;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border: 1px solid hsl(var(--border));
}

.btn.full-width {
  width: 100%;
}

/* ============ NOTIFICATIONS (TOASTS) ============ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  /* Allow clicks through container */
}

.toast {
  min-width: 300px;
  max-width: 400px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  color: hsl(var(--foreground));
  display: flex;
  align-items: center;
  justify-content: space-between;
  transform: translateX(100%);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast-message {
  font-size: 14px;
  font-weight: 500;
}

.toast-icon {
  flex-shrink: 0;
}

.toast-icon.success {
  color: #10b981;
  /* Emerald 500 */
}

.toast-icon.error {
  color: #ef4444;
  /* Red 500 */
}

.toast-icon.info {
  color: #3b82f6;
  /* Blue 500 */
}

@media (max-width: 768px) {
  .toast-container {
    bottom: 20px;
    left: 20px;
    right: 20px;
    align-items: center;
  }

  .toast {
    width: 100%;
    max-width: 100%;
  }
}

/* ============ PROGRESS OVERLAY ============ */
.progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.progress-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.progress-box {
  background: hsl(var(--card));
  padding: 24px;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 200px;
}

.progress-text {
  font-size: 14px;
  font-weight: 500;
  color: hsl(var(--foreground));
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid hsl(var(--muted));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
