/* Widget Palette Item Styles */
.palette-group {
  margin-bottom: 24px;
}

.palette-group h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
}

.chips-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.widget-palette-chip {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
  user-select: none;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.widget-palette-chip:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.widget-palette-chip.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.widget-palette-chip .chip-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.widget-palette-chip .chip-type {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--accent);
}

/* Placed Widget Instances in Canvas Workspace */
.canvas-widget {
  position: absolute;
  box-sizing: border-box;
  border: 1px solid var(--accent);
  background-color: rgba(0, 229, 255, 0.05);
  cursor: move;
  transition: box-shadow 0.15s ease;
  overflow: hidden; /* Default to hidden to clip text and elements */
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-widget.selected, .canvas-widget.overflow-visible {
  overflow: visible !important; /* Allow handles or overflowing content to leak */
}

/* Ensure inner blocks allow text to leak outside when clipping is unchecked */
.canvas-widget.overflow-visible .widget-text,
.canvas-widget.overflow-visible .widget-preview-label,
.canvas-widget.overflow-visible .widget-preview-label .label-name {
  overflow: visible !important;
}

.canvas-widget.selected:not(.overflow-visible) .widget-text,
.canvas-widget.selected:not(.overflow-visible) .widget-preview-label {
  overflow: hidden; /* Keep inner content clipped even when selection handles are visible */
}

.canvas-widget:hover {
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.3);
}

.canvas-widget.selected {
  border: 2px solid var(--accent) !important;
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.5);
  z-index: 100;
}

/* Spacer dashed outline styling in editor view */
.canvas-widget.spacer-widget {
  border: 1.5px dashed var(--text-muted);
  background-color: rgba(255, 255, 255, 0.02);
}

/* Inner labels of raw widgets during Milestone 2 placeholder staging */
.widget-preview-label {
  display: flex;
  flex-direction: column;
  padding: 4px;
  pointer-events: none;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.widget-preview-label .label-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.widget-preview-label .label-meta {
  font-size: 8px;
  opacity: 0.6;
  white-space: nowrap;
}

/* Properties Form Formatting Styles */
.properties-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  box-sizing: border-box;
}

.prop-section {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
  width: 100%;
  box-sizing: border-box;
}

.prop-section:last-child {
  border-bottom: none;
}

.prop-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 8px;
}

.meta-value {
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.font-mono {
  font-family: var(--font-mono);
}

.prop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
}

.prop-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  box-sizing: border-box;
}

.prop-input-group label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prop-input-group input {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.prop-input-group input:focus {
  border-color: var(--accent);
}

/* Button variants for actions */
.btn-delete {
  background-color: rgba(255, 23, 68, 0.1);
  border-color: rgba(255, 23, 68, 0.3);
  color: var(--negative);
  margin-top: 10px;
  width: 100%;
  justify-content: center;
}

.btn-delete:hover {
  background-color: var(--negative) !important;
  color: #fff !important;
  border-color: var(--negative) !important;
}

.btn-delete-toolbar {
  background-color: rgba(255, 23, 68, 0.1);
  border-color: rgba(255, 23, 68, 0.3) !important;
  color: var(--negative) !important;
}

.btn-delete-toolbar:hover {
  background-color: var(--negative) !important;
  color: #fff !important;
  border-color: var(--negative) !important;
}

/* Resize Handle Indicators (TFT physical boundaries 2x scale = 10px boxes) */
.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: #000;
  border: 1.5px solid var(--accent);
  z-index: 105;
}

/* 8 Directions Layout */
.handle-tl { top: -5px; left: -5px; cursor: nwse-resize; }
.handle-tc { top: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.handle-tr { top: -5px; right: -5px; cursor: nesw-resize; }
.handle-ml { top: calc(50% - 5px); left: -5px; cursor: ew-resize; }
.handle-mr { top: calc(50% - 5px); right: -5px; cursor: ew-resize; }
.handle-bl { bottom: -5px; left: -5px; cursor: nesw-resize; }
.handle-bc { bottom: -5px; left: calc(50% - 5px); cursor: ns-resize; }
.handle-br { bottom: -5px; right: -5px; cursor: nwse-resize; }

/* Font size mapping representation (Exact 2x physical scale matching LovyanGFX GFX fonts) */
/* LovyanGFX Font0: 8px (2x = 16px), Font2: 16px (2x = 32px), Font4: 26px (2x = 52px), Font6: 48px (2x = 96px), Font8: 75px (2x = 150px) */
.font-Font0 { font-size: calc(16px * var(--scale-mult, 1)); line-height: 1; font-family: var(--font-mono); }
.font-Font2 { font-size: calc(32px * var(--scale-mult, 1)); line-height: 1; font-family: var(--font-family); }
.font-Font4 { font-size: calc(52px * var(--scale-mult, 1)); line-height: 1; font-family: var(--font-family); font-weight: 700; }
.font-Font6 { font-size: calc(96px * var(--scale-mult, 1)); line-height: 1; font-family: var(--font-mono); }
.font-Font8 { font-size: calc(150px * var(--scale-mult, 1)); line-height: 1; font-family: var(--font-mono); }

/* Alignment configurations */
.align-h-left { justify-content: flex-start; text-align: left; }
.align-h-center { justify-content: center; text-align: center; }
.align-h-right { justify-content: flex-end; text-align: right; }

.align-v-top { align-items: flex-start; }
.align-v-middle { align-items: center; }
.align-v-bottom { align-items: flex-end; }

/* Set transform origin according to flex alignment so scale() scales anchored from alignment edge */
.align-h-left.align-v-top span { transform-origin: left top; }
.align-h-left.align-v-middle span { transform-origin: left center; }
.align-h-left.align-v-bottom span { transform-origin: left bottom; }

.align-h-center.align-v-top span { transform-origin: center top; }
.align-h-center.align-v-middle span { transform-origin: center center; }
.align-h-center.align-v-bottom span { transform-origin: center bottom; }

.align-h-right.align-v-top span { transform-origin: right top; }
.align-h-right.align-v-middle span { transform-origin: right center; }
.align-h-right.align-v-bottom span { transform-origin: right bottom; }

/* Alignment buttons styles in Properties sidebar */
.align-buttons-group {
  display: flex;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.align-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.align-btn:hover {
  background-color: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
}

.align-btn.active {
  background-color: var(--accent-dim);
  color: var(--accent);
}

.spacing-bottom {
  margin-bottom: 12px;
}

/* Color input wrappers styling */
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.color-picker-wrapper input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker-wrapper input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.color-picker-wrapper input[type="color"]:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.color-picker-wrapper input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.prop-input-group select {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px;
  border-radius: 4px;
  outline: none;
  font-size: 12px;
}

/* Divider rendering rules (horizontal / vertical line alignments) */
.divider-line {
  position: absolute;
  pointer-events: none;
}

.divider-line.horizontal {
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
}

.divider-line.vertical {
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 100%;
}

/* Custom inner content overrides for Mock rendering */
.widget-text {
  display: flex;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: 0 4px;
}

.widget-text span {
  display: inline-block;
  white-space: nowrap;
}

.widget-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
}

.widget-wifi-status, .widget-battery-status, .widget-time-status {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.widget-chart {
  width: 100%;
  height: 100%;
  position: relative;
}

.spacing-top {
  margin-top: 8px;
}

/* Modal Backdrop */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

/* Modal Content Container */
.modal-content {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 100%;
  max-width: 700px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-body p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.modal-body pre {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 16px;
  margin: 0;
  overflow: auto;
}

.modal-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--accent);
  white-space: pre;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Excel-Style Border Selection Grid */
.border-matrix-container {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 14px;
  margin-top: 10px;
  width: 100%;
}

.matrix-label {
  font-size: 11px;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 12px;
}

.excel-border-matrix {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin-bottom: 12px;
}

.matrix-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.matrix-cell {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.matrix-cell.empty {
  visibility: hidden;
}

.matrix-cell.preview-cell {
  width: 44px;
  height: 44px;
  border: 1px dashed var(--border-color);
  border-radius: 4px;
  background-color: rgba(255,255,255,0.01);
  padding: 6px;
}

/* Central box mapping borders visually */
.border-preview-box {
  width: 100%;
  height: 100%;
  border: 1px dotted rgba(255,255,255,0.1);
  box-sizing: border-box;
  transition: all 0.15s ease;
}

.border-preview-box.t { border-top: 2px solid var(--accent); }
.border-preview-box.b { border-bottom: 2px solid var(--accent); }
.border-preview-box.l { border-left: 2px solid var(--accent); }
.border-preview-box.r { border-right: 2px solid var(--accent); }

/* Excel-style checkbox buttons */
.border-cb-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border: 1px solid var(--border-color);
  background-color: var(--bg-tertiary);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.border-cb-label:hover {
  background-color: var(--border-color);
}

.border-cb-label input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

/* Custom border icons inside cells */
.border-icon {
  background-color: var(--text-secondary);
  position: absolute;
  transition: all 0.2s ease;
}

.border-cb-label input:checked ~ .border-icon {
  background-color: var(--accent);
}

.border-cb-label:has(input:checked) {
  border-color: var(--accent);
  background-color: var(--accent-dim);
}

/* Visual icons (horizontal/vertical bars) */
.icon-top { top: 8px; left: 8px; right: 8px; height: 3px; }
.icon-bottom { bottom: 8px; left: 8px; right: 8px; height: 3px; }
.icon-left { left: 8px; top: 8px; bottom: 8px; width: 3px; }
.icon-right { right: 8px; top: 8px; bottom: 8px; width: 3px; }

/* Sidebar Tabs */
.tabs-header {
  display: flex;
  padding: 0;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
}

.sidebar-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  padding: 14px 10px;
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.sidebar-tab:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
}

.sidebar-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background-color: #eff6ff;
}

.tab-content {
  flex: 1;
  overflow-y: auto;
}

/* Layers / Objects List Styling */
.layers-container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.layers-empty-message {
  color: var(--text-muted);
  text-align: center;
  font-size: 12px;
  padding: 24px 8px;
}

.layer-item {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: grab;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.layer-item:active {
  cursor: grabbing;
}

.layer-item:hover {
  background-color: var(--border-color);
  border-color: var(--text-muted);
}

.layer-item.selected {
  border-color: var(--accent);
  background-color: var(--accent-dim);
}

.layer-item.dragging {
  opacity: 0.5;
  border: 1px dashed var(--accent);
}

.layer-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0; /* allows text truncation */
}

.layer-drag-handle {
  color: var(--text-muted);
  font-size: 14px;
  cursor: grab;
}

.layer-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.layer-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-meta {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.layer-item-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.layer-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.layer-action-btn:hover {
  color: var(--negative);
  background-color: rgba(255, 23, 68, 0.1);
}

/* Template Manager Modal Styles */
.templates-modal-content {
  max-width: 680px;
  width: 90%;
  height: 520px;
}

.templates-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  height: 100%;
}

.templates-column {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.templates-column h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}

.section-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.4;
}

.save-slot-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.save-slot-form input {
  flex: 1;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}

.save-slot-form input:focus {
  border-color: var(--accent);
}

.slots-list {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--bg-card);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
}

.slot-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-radius: 4px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  transition: border-color 0.15s ease;
}

.slot-item:hover {
  border-color: var(--accent-dim);
}

.slot-name-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.slot-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.slot-actions {
  display: flex;
  gap: 6px;
}

.btn-slot-action {
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 3px;
}

.btn-full {
  width: 100%;
  padding: 10px;
  font-weight: 500;
  margin-bottom: 20px;
}

.import-zone {
  flex: 1;
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background-color: rgba(255, 255, 255, 0.02);
  min-height: 140px;
}

.import-zone:hover {
  border-color: var(--accent);
  background-color: rgba(255, 255, 255, 0.04);
}

.import-zone .icon {
  font-size: 28px;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.import-zone .import-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.autosave-indicator {
  font-size: 11px;
  color: var(--positive);
  display: flex;
  align-items: center;
  gap: 6px;
}

.autosave-indicator::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--positive);
  box-shadow: 0 0 6px var(--positive);
}

.slots-empty-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}


