/* GLOBAL */
body {
  margin: 0;
  background: #f2f2f2;
  font-family: sans-serif;
  overflow: hidden;
  -webkit-user-select: none; /* reduce accidental selects on touch */
  user-select: none;
}

/* Canvas root is the viewport-sized interaction surface */
#canvas {
  position: absolute;
  inset: 0;
  background: white;
  /* Important for touch: let us handle gestures (pan/zoom) via PointerEvents */
  touch-action: none;
  overflow: hidden; /* hide panned/zoomed edges */
}

/* New: stage that holds all components; transformed for pan/zoom */
#canvasStage {
  position: absolute;
  left: 0; top: 0; width: 100%; height: 100%;
  transform-origin: 0 0; /* top-left origin for stable math */
}

/* (+) BUTTON */
#addBtn {
  position: absolute;
  right: 24px;
  bottom: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #0078ff;
  color: white;
  font-size: 40px;
  text-align: center;
  line-height: 64px;
  cursor: pointer;
  transition: 0.3s;
  user-select: none;
  z-index: 9999;
}
#addBtn.open { transform: rotate(45deg); background: #ff006e; }

/* Trash button (matches the + button, opposite corner) */
#trashBtn {
  position: fixed; /* fixed to viewport (like the radial-menu origin) */
  left: 24px;
  bottom: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #ef4444; /* red to distinguish */
  color: white;
  font-size: 0; /* hide any text; we draw icon via ::before */
  cursor: default;
  user-select: none;
  z-index: 9999;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
/* Trash button highlight when a dragged item is over it */
#trashBtn.hot {
  filter: brightness(1.1);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.35);
  transform: scale(1.06);
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
/* Simple trash-can glyph using CSS only */
#trashBtn::before,
#trashBtn::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
/* lid */
#trashBtn::before {
  top: 18px;
  width: 28px;
  height: 4px;
  background: #fff;
  border-radius: 2px;
}
/* can */
#trashBtn::after {
  top: 24px;
  width: 24px;
  height: 22px;
  border: 3px solid #fff;
  border-top: 0;
  border-radius: 3px 3px 6px 6px;
}
/* optional hover tint to mirror #addBtn feel */
#trashBtn:hover { filter: brightness(1.05); }

/* COMPONENTS: make drags/resizes touch-friendly */
.comp {
  touch-action: none;        /* critical for touch-drags */
  -webkit-user-select: none;
  user-select: none;
}

/* RESIZE HANDLE ON CANVAS COMPONENTS */
.resize-handle {
  position: absolute;
  right: -6px; bottom: -6px;
  width: 14px; height: 14px;
  background: #0078ff;
  border-radius: 50%;
  cursor: nwse-resize;
  touch-action: none;        /* critical for touch-resize */
  z-index: 1000;             /* must be above all widget elements including toolbar */
  pointer-events: auto !important;
}

/* Larger target on tablets/phones */
@media (pointer: coarse), (hover: none) {
  .resize-handle {
    right: -10px; bottom: -10px;
    width: 24px; height: 24px;
  }
  /* invisible hit zone for fat-finger accuracy */
  .resize-handle::after {
    content: "";
    position: absolute;
    left: -8px; top: -8px;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: transparent;
  }
}

/* POPUP SUBMENU (centered above +, draggable) */
.popup {
  position: fixed; /* works with JS centering */
  min-width: 240px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  background: #ffffff;
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  z-index: 50;
  user-select: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.popup.stream-config-popup {
  max-width: min(92vw, calc(100vw - 16px));
  cursor: grab;
  touch-action: none;
}
.popup.stream-config-popup button,
.popup.stream-config-popup input,
.popup.stream-config-popup select,
.popup.stream-config-popup textarea {
  cursor: auto;
  touch-action: auto;
}
.popup.settings-popup {
  min-width: min(580px, calc(100vw - 16px));
  max-width: min(92vw, calc(100vw - 16px));
}
.popup-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  background: #0b57d0; color: #fff;
  padding: 8px 12px;
  border-top-left-radius: 8px; border-top-right-radius: 8px;
  cursor: move; font-weight: 600; font-size: 14px;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;        /* allow smooth dragging of popups on touch */
}
.popup-close {
  width: 22px; height: 22px; line-height: 22px; text-align: center;
  border-radius: 4px; background: rgba(255,255,255,0.15);
  cursor: pointer;
}
.popup-minimize {
  width: 22px; height: 22px; line-height: 22px; text-align: center;
  border-radius: 4px; background: rgba(255,255,255,0.15);
  cursor: pointer;
}
.popup-body {
  padding: 10px;
  display: grid; grid-template-columns: repeat(2, minmax(90px, 1fr));
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}
.popup-item {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid #e6e6e6; border-radius: 6px;
  padding: 8px; cursor: grab;
  background: #fafafa; transition: background 0.15s ease, box-shadow 0.15s ease;
}
.popup-item:hover { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.popup-item:active { cursor: grabbing; }
.popup-item .dot { width: 10px; height: 10px; border-radius: 50%; background: #0078ff; }

/* DRAG GHOST */
.drag-ghost {
  position: fixed; top: 0; left: 0;
  transform: translate(-50%, -50%);
  pointer-events: none; z-index: 1000;
  padding: 6px 10px;
  background: #333; color: #fff;
  border-radius: 6px; font-size: 12px; opacity: 0.85;
}

/* ========================================
   APP TRAY (Bottom Launcher)
   ======================================== */

.app-tray {
  position: fixed;
  bottom: 20px;
  left: 100px; /* After trash button */
  right: 100px; /* Before radial button */
  height: 60px;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #333;
  border-radius: 30px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  z-index: 900;
  backdrop-filter: blur(10px);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}

.app-tray-inner {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  flex-wrap: nowrap;
  gap: 10px;
  padding: 0 20px;
  margin: 0 auto; /* centers when content fits; resolves to 0 when overflowing so scroll works fully */
}

.app-tray::-webkit-scrollbar {
  display: none; /* Chrome/Safari/Edge */
}

.app-tray-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  gap: 4px;
  padding: 8px 12px;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 11px;
  color: #333;
}

.app-tray-btn:hover {
  background: rgba(100, 149, 237, 0.1);
  border-color: #6495ed;
  transform: translateY(-2px);
}

.app-tray-btn.active {
  background: rgba(100, 149, 237, 0.15);
  border-color: #6495ed;
}

.app-tray-btn .app-icon {
  font-size: 24px;
}

.app-tray-btn .app-label {
  font-weight: 500;
  white-space: nowrap;
}

/* ========================================
   APP SHELLS (Windows)
   ======================================== */

.app-shell {
  position: fixed;
  background: white;
  border: 2px solid #333;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  transition: box-shadow 0.2s;
  min-width: 200px;
  min-height: 150px;
  max-width: calc(100vw - 16px);  /* 8px margin on each side */
  max-height: calc(100vh - 90px); /* reserve space for app tray (~60px) + bottom offset (~20px) */
}

.app-shell.active {
  box-shadow: 0 12px 48px rgba(0,0,0,0.4);
  border-color: #6495ed;
}

.app-shell.dragging {
  opacity: 0.9;
  cursor: move;
}

.app-shell.maximized {
  left: 0 !important;
  top: 0 !important;
  width: 100vw !important;
  height: calc(100vh - 60px) !important;
  border-radius: 0;
  max-width: 100vw;
  max-height: calc(100vh - 60px);
}

.app-shell.maximized .shell-resize-handle {
  display: none;
}

.app-shell.minimized {
  display: none;
}

.shell-titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: 600;
  user-select: none;
  touch-action: none;  /* critical for smooth touch drag */
  gap: 8px;
}

/* Title area holds id-badge, version-badge, and filename */
.shell-title-area {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.shell-id-badge {
  font-size: 10px;
  font-weight: 600;
  background: rgba(255,255,255,0.2);
  padding: 2px 6px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}

.shell-version-badge {
  font-size: 10px;
  font-weight: 600;
  background: rgba(255,255,255,0.2);
  padding: 2px 6px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
  letter-spacing: 0.3px;
}

.shell-version-badge:hover {
  background: rgba(255,255,255,0.4);
}

.shell-filename {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
  padding: 1px 4px;
  border-radius: 4px;
  transition: background 0.15s;
}

.shell-filename:hover {
  background: rgba(255,255,255,0.15);
}

.shell-filename-input {
  font: 600 13px/1 system-ui, sans-serif;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 4px;
  color: white;
  padding: 2px 6px;
  outline: none;
  min-width: 80px;
  max-width: 200px;
}

.shell-filename-input::placeholder {
  color: rgba(255,255,255,0.6);
}

.shell-content {
  /* Standard app-shell content layout:
     - no header row
     - content starts at top-left (0,0)
     - shell chrome controls live in the title bar */
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.shell-main-content {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  margin: 0;
  padding: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
}

.shell-main-content canvas {
  position: absolute;
  inset: 0;
}

/* Shell chrome controls are now in the title bar (horizontal row on the right). */
.shell-right-toolbar,
.shell-controls {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  flex-shrink: 0;
  padding: 0 2px;
}

.shell-right-toolbar button,
.shell-controls button {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.shell-right-toolbar button:hover,
.shell-controls button:hover {
  background: rgba(255,255,255,0.30);
  transform: scale(1.08);
}

.shell-content.hidden {
  display: none;
}

/* Shell footer — shows the current filename at the bottom of the window */
.shell-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-top: 1px solid rgba(0,0,0,0.12);
  flex-shrink: 0;
}

.shell-footer-filename {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.2px;
}

/* Shell resize handle (bottom-right corner grip) */
.shell-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  touch-action: none;
  z-index: 10;
}

.shell-resize-handle::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 10px;
  height: 10px;
  border-right: 3px solid rgba(100, 149, 237, 0.7);
  border-bottom: 3px solid rgba(100, 149, 237, 0.7);
  border-radius: 0 0 2px 0;
}

.app-shell.minimized .shell-resize-handle {
  display: none;
}

/* ========================================
   MINIMIZED SHELL ICON
   Appears on the canvas when a shell window is minimized.
   ======================================== */

.shell-minimized-icon {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 22px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.30);
  cursor: pointer;
  user-select: none;
  touch-action: none;
  z-index: 999;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.25);
  transition: box-shadow 0.15s, transform 0.1s;
  font: 600 11px/1 system-ui, sans-serif;
}

.shell-minimized-icon:hover {
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.42);
  transform: scale(1.05);
  border-color: rgba(255, 255, 255, 0.5);
}

.shell-min-icon-glyph {
  font-size: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  line-height: 1;
}

.shell-min-icon-glyph svg {
  display: block;
}

.shell-min-icon-label {
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}



.taskboard-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.taskboard-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 2px solid #eee;
}

.taskboard-toolbar button {
  padding: 8px 16px;
  background: #6495ed;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.taskboard-toolbar button:hover {
  background: #4169e1;
  transform: translateY(-1px);
}

/* ── Kanban view ─────────────────────────────────────────────────────── */
.taskboard-kanban {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 12px;
  box-sizing: border-box;
}

.taskboard-columns {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  flex: 1;
  min-height: calc(100% - 24px);
}

.taskboard-column {
  min-width: 220px;
  flex: 1 1 220px;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.taskboard-column h3 {
  margin: 0 0 10px 0;
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  letter-spacing: .3px;
}

.taskboard-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 80px;
  flex: 1;
}

.taskboard-card {
  background: white;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  cursor: default;
  font-size: 13px;
  transition: box-shadow 0.15s, transform 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.taskboard-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.10);
  transform: translateY(-1px);
}

.taskboard-card.dragging {
  opacity: 0.5;
}

/* Priority left-border accent on kanban cards */
.taskboard-card[data-priority="low"]    { border-left: 3px solid #22c55e; }
.taskboard-card[data-priority="medium"] { border-left: 3px solid #eab308; }
.taskboard-card[data-priority="high"]   { border-left: 3px solid #ef4444; }

.taskboard-card-title {
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 6px;
  word-break: break-word;
}

.taskboard-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 11px;
}

.taskboard-priority-badge {
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.taskboard-priority-badge.priority-low    { background: #dcfce7; color: #15803d; }
.taskboard-priority-badge.priority-medium { background: #fef9c3; color: #a16207; }
.taskboard-priority-badge.priority-high   { background: #fee2e2; color: #b91c1c; }

.taskboard-due-date {
  color: #64748b;
  white-space: nowrap;
}

.taskboard-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.taskboard-move-btn {
  font-size: 10px;
  padding: 2px 7px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
  transition: background .1s, border-color .1s;
}
.taskboard-move-btn:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}
.taskboard-remove-btn {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fff;
}
.taskboard-remove-btn:hover {
  background: #fff1f2;
  border-color: #fda4af;
  color: #991b1b;
}

.taskboard-restore-btn {
  color: #15803d;
  border-color: #bbf7d0;
  background: #f0fdf4;
}
.taskboard-restore-btn:hover {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.taskboard-column-deleted h3 {
  color: #9ca3af;
}

.taskboard-card-deleted {
  opacity: 0.65;
  background: #f9fafb;
  border-color: #e5e7eb;
}
.taskboard-card-deleted .taskboard-card-title {
  text-decoration: line-through;
  color: #9ca3af;
}

.taskboard-empty-col {
  color: #94a3b8;
  font-size: 12px;
  text-align: center;
  padding: 16px 8px;
  font-style: italic;
}

/* Kanban toggle button active state */
.stickies-toolbar .st-btn.active {
  background: #3b82f6;
  color: #fff;
  border-color: #2563eb;
}

/* ========================================
   DESIGNER PALETTE - ICON-BASED COMPACT VERSION
   ======================================== */

.designer-palette {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.palette-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.palette-section h3 {
  margin: 0;
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center; /* Centered */
  padding-bottom: 8px;
  border-bottom: 2px solid #6495ed;
}

.palette-section h3 i {
  font-size: 14px;
  margin-right: 4px;
  color: #6495ed;
}

/* 2-column grid */
.palette-grid {
  display: grid;
  grid-template-columns: 1fr 1fr; /* 2 columns */
  gap: 8px;
}

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  background: white;
  border: 2px solid #ddd;
  border-radius: 8px;
  cursor: grab;
  transition: all 0.2s;
  position: relative;
}

.palette-item i {
  font-size: 24px;
  color: #333;
  pointer-events: none;
}

.palette-item span {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #666;
  text-align: center;
  line-height: 1.2;
  pointer-events: none;
  overflow-wrap: break-word; /* Handle long words */
}

.palette-item:hover {
  border-color: #6495ed;
  background: #f0f4ff;
  transform: scale(1.05);
  z-index: 10;
}

.palette-item:hover i {
  color: #6495ed;
}

.palette-item:hover span {
  color: #6495ed;
}

.palette-item:active {
  cursor: grabbing;
  transform: scale(0.95);
}

.palette-item.dragging-from-palette {
  opacity: 0.5;
  transform: scale(0.9);
}

/* Preserve top-left origin for all app shell content layouts (no extra shell padding). */
.app-shell[data-app-type="designer"] .shell-content {
  padding: 0;
}

/* ========================================
   CANVAS DROP ZONE FEEDBACK
   ======================================== */

.drop-target-active {
  outline: 3px dashed #6495ed;
  outline-offset: -10px;
  background: rgba(100, 149, 237, 0.05);
}

/* Ensure containers can be drop targets and position children */
[data-type='grid'],
[data-type='rails'],
[data-type='flow'],
[data-type='frame'],
.container-body,
.panel-body,
[data-dropzone='absolute'] {
  position: relative;
}

/* Component creation feedback */
.component-creation-feedback {
  position: fixed;
  width: 40px;
  height: 40px;
  background: #4CAF50;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
  pointer-events: none;
  z-index: 10000;
  transform: translate(-50%, -50%);
  animation: popIn 0.3s ease-out;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.component-creation-feedback.fade-out {
  animation: fadeOut 0.3s ease-out forwards;
}

@keyframes popIn {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.2);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
}

/* ZimxShell selector in Designer palette */
.palette-zimxshell-selector {
  background: #f0f7ff;
  border: 1px solid #6495ed;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
}

.palette-zimxshell-selector label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #333;
  margin-bottom: 6px;
}

.zimxshell-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  background: white;
  cursor: pointer;
}

.zimxshell-select:focus {
  outline: none;
  border-color: #6495ed;
  box-shadow: 0 0 0 3px rgba(100, 149, 237, 0.1);
}

/* MAIN radial menu (Add button menu) - Keep as-is for the main canvas menu */
.radial-menu {
  /* Styles for the main Add button radial menu */
  /* This should remain unchanged from whatever exists */
}

/* WIDGET menu containers */
.header-menu-widget,
.radial-menu-widget,
.stacked-menu-widget {
  position: relative;
  background: white;
  border: 2px solid #0b57d0;
  border-radius: 8px;
  overflow: hidden;
  min-width: 200px;
}

/* When the radial menu is open, allow items to overflow the widget bounds */
.radial-menu-widget.open {
  overflow: visible;
}

.menu-widget-header {
  cursor: move !important;
  padding: 8px 12px;
  background: #0b57d0;
  color: white;
  user-select: none;
  font-weight: 600;
  font-size: 12px;
}

.menu-widget-body {
  position: relative;
  min-height: 50px;
  padding: 8px;
  background: white;
  border-top: 1px solid #ddd;
}

/* Menu item widgets */
.menu-image,
.menu-title,
.menu-button-widget,
.menu-icon-widget,
.menu-dropdown-widget,
.menu-counter-widget {
  display: inline-block;
  cursor: pointer;
}

.menu-button-widget,
.menu-icon-widget {
  transition: background 0.15s ease;
}

.menu-button-widget:hover,
.menu-icon-widget:hover {
  background: rgba(0,0,0,0.05) !important;
}

.menu-counter-widget {
  cursor: pointer;
}

.menu-counter-widget:hover {
  transform: scale(1.1);
}

.menu-image:hover {
  opacity: 0.8;
}

.menu-title:focus {
  outline: 2px solid #0b57d0;
  outline-offset: 2px;
}

/* Drop error toast */
.drop-error-toast {
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    transform: translate(-50%, -20px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

/* Resize handle */
.resize-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 14px;
  height: 14px;
  background: #0078ff;
  border-radius: 50%;
  cursor: nwse-resize;
  z-index: 500;
  pointer-events: auto !important;
}

.resize-handle:hover {
  transform: scale(1.2);
}

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

/* Settings button in app tray */
.app-tray-settings {
  margin-left: 8px;
  padding-left: 8px;
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  left: 80px;
  bottom: 20px;
  width: 400px;
  max-height: 600px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  overflow: hidden;
  z-index: 10000;
  transition: opacity 0.2s, transform 0.2s;
}

.settings-panel.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: #f8f9fa;
  border-bottom: 1px solid #e5e7eb;
}

.settings-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.settings-header .close-btn {
  background: none;
  border: none;
  font-size: 28px;
  color: #6c757d;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  line-height: 1;
}

.settings-content {
  padding: 16px;
  max-height: 500px;
  overflow-y: auto;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-info {
  flex: 1;
}

.setting-info label {
  font-weight: 600;
  font-size: 14px;
  display: block;
  margin-bottom: 4px;
  cursor: pointer;
}

.setting-desc {
  font-size: 12px;
  color: #6c757d;
  margin: 0;
}

.setting-control {
  margin-left: 16px;
}

.setting-control input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.setting-control input[type="number"] {
  width: 80px;
  padding: 6px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  font-size: 14px;
}

/* Grid overlay on canvas */
#canvas.show-grid,
#canvasStage.show-grid {
  background-image: 
    linear-gradient(rgba(0,0,0,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.05) 1px, transparent 1px);
  background-size: var(--grid-size, 10px) var(--grid-size, 10px);
}

/* Repo / Canvas Settings popup */
.popup.repo-settings {
  min-width: min(400px, calc(100vw - 16px));
  max-width: min(520px, calc(100vw - 16px));
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.repo-set-section-heading {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  padding: 8px 0 4px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 4px;
}
.repo-set-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.repo-set-item label {
  font-weight: 600;
  font-size: 13px;
  color: #1e293b;
}
.repo-set-item input[type="text"],
.repo-set-item input[type="password"] {
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 13px;
  width: 100%;
  box-sizing: border-box;
}
.repo-set-toggle-item,
.repo-set-number-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
}
.repo-set-toggle-item:last-child,
.repo-set-number-item:last-child {
  border-bottom: none;
}
.repo-set-item-info {
  flex: 1;
}
.repo-set-item-info label {
  font-weight: 600;
  font-size: 13px;
  display: block;
  cursor: pointer;
  color: #1e293b;
}
.repo-set-item-desc {
  font-size: 11px;
  color: #6b7280;
  margin: 2px 0 0;
}
.repo-set-toggle-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  margin-left: 12px;
  flex-shrink: 0;
}
.repo-set-number-item input[type="number"] {
  width: 70px;
  padding: 5px 6px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 13px;
  margin-left: 12px;
  flex-shrink: 0;
}
.repo-set-footer {
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}
.repo-set-save {
  padding: 7px 16px;
  background: #0b57d0;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.repo-set-save:hover {
  background: #0944a8;
}

/* Tabbed settings interface */
.popup.repo-settings .repo-settings-tabbed {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.repo-settings-tab-nav {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #e0e0e0;
  padding: 0 12px;
  background: #f9f9f9;
  flex-shrink: 0;
}

.repo-settings-tab {
  padding: 12px 20px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #666;
  transition: all 0.2s ease;
  position: relative;
  bottom: -2px;
}

.repo-settings-tab:hover {
  color: #0b5ed7;
  background: rgba(11, 94, 215, 0.05);
}

.repo-settings-tab--active {
  color: #0b5ed7;
  border-bottom-color: #0b5ed7;
  background: white;
}

.repo-settings-tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.repo-settings-tab-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  display: none;
}

.repo-settings-tab-panel.repo-settings-tab-panel--active {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  overflow-y: auto;
  opacity: 1;
  pointer-events: auto;
}
