/* ========================================
   FREEFORM LAYOUT - ISOLATED STYLES
   Only applies to .dashboard.layout-freeform
   ======================================== */

/* --- FREEFORM UNIFIED HEADER (matches tabbed layout) --- */
.weather-bar-freeform {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  height: var(--dashboard-weather-bar-height) !important;
  min-height: var(--dashboard-weather-bar-height) !important;
  max-height: var(--dashboard-weather-bar-height) !important;
  display: flex !important;
  align-items: stretch !important;
  overflow: hidden !important;
  background: var(--theme-widget-header-bg, rgba(10, 12, 22, 0.98)) !important;
  border-bottom: 2px solid var(--theme-border) !important;
  padding: 0 !important;
  gap: 10px !important;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--theme-border) !important;
  z-index: 10000 !important;
  box-sizing: border-box !important;
}

.freeform-header-content {
  display: flex !important;
  align-items: stretch !important;
  justify-content: space-between !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  gap: 10px !important;
  padding: 0 !important;
  min-width: 0 !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

.freeform-header-left {
  display: flex !important;
  align-items: center !important;
  gap: 16px !important;
  flex: 1 1 auto !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

.freeform-branding {
  display: flex !important;
  flex-direction: row !important;
  align-items: stretch !important;
  align-self: stretch !important;
  gap: 0 !important;
  flex-shrink: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  opacity: 0.95 !important;
  transition: opacity 0.2s ease, transform 0.2s ease !important;
  cursor: pointer !important;
  border: none !important;
  background: none !important;
  min-height: 0 !important;
}

.freeform-branding:hover {
  opacity: 1 !important;
  transform: translateX(1px) !important;
}

/* Animated orbit graphic (calyxy-mark.svg) */
.freeform-brand-mark {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  flex: 0 0 auto !important;
  box-sizing: border-box !important;
}

.freeform-brand-mark .calyxy-bar-orbit-img {
  height: calc(var(--dashboard-weather-bar-height) - 8px) !important;
  width: auto !important;
  max-height: calc(var(--dashboard-weather-bar-height) - 8px) !important;
  min-width: 28px !important;
}

/* Wordmark sizing only; font + colors from styles.css + theme variables */
.freeform-brand-text {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  margin: 0 !important;
  padding: 0 !important;
  height: 100% !important;
  font-size: calc(var(--dashboard-weather-bar-height) - 11px) !important;
}

.freeform-weather-container {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  min-width: 200px !important;
  flex: 1 1 auto !important;
  max-width: min(680px, 50%) !important;
  margin-left: 8px !important;
  overflow: visible !important;
}

.freeform-weather-container .weather-container {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  flex-wrap: nowrap !important;
  font-size: clamp(0.7rem, 1.2vw, 0.9rem) !important;
  min-width: 0 !important;
  overflow: visible !important;
  flex: 1 1 auto !important;
}

.freeform-weather-container .weather-data-group {
  flex: 1 1 auto !important;
  min-width: 0 !important;
}

.freeform-weather-container .weather-text-group {
  min-width: 0 !important;
  overflow: visible !important;
}

.freeform-weather-container .weather-main-line,
.freeform-weather-container .weather-sub-line {
  white-space: nowrap !important;
  overflow: visible !important;
}

.freeform-weather-container .weather-icon {
  font-size: 1.8rem !important;
  flex-shrink: 0 !important;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.4)) !important;
}

/* NWS alert slot: between weather and app bar, towards center */
.freeform-weather-alert-slot {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  padding: 0 clamp(12px, 2vw, 24px);
}

.freeform-weather-alert-slot:not(:empty) {
  display: flex;
}

.freeform-weather-alert-slot .weather-alert-wrapper {
  margin-left: 0 !important;
  padding-left: 0 !important;
  border-left: none !important;
}

.freeform-app-bar {
  display: flex !important;
  align-items: center !important;
  gap: clamp(6px, 1vw, 10px) !important;
  flex: 1 1 auto !important;
  min-width: 0 !important;
  margin-left: clamp(12px, 2vw, 24px) !important;
  margin-right: clamp(12px, 2vw, 24px) !important;
  justify-content: center !important;
}

.freeform-app-bar-btn {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: clamp(4px, 0.8vw, 8px) !important;
  padding: clamp(8px, 1.2vw, 12px) clamp(12px, 1.8vw, 18px) !important;
  background: var(--theme-card-bg) !important;
  border: 2px solid var(--theme-border) !important;
  border-radius: 14px !important;
  color: var(--theme-text) !important;
  font-size: clamp(12px, 1.5vw, 15px) !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
  touch-action: manipulation !important;
}

.freeform-app-bar-btn:hover {
  background: var(--theme-button-secondary) !important;
  border-color: var(--theme-primary) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
}

.freeform-app-bar-btn:active {
  transform: translateY(0) !important;
}

.freeform-app-bar-btn.freeform-save-btn {
  position: relative !important;
  background: linear-gradient(135deg, var(--theme-primary), var(--theme-secondary)) !important;
  color: #fff !important;
  border: none !important;
}

.freeform-app-bar-btn.freeform-save-btn:hover {
  opacity: 0.95 !important;
  box-shadow: 0 6px 20px rgba(86, 168, 255, 0.35) !important;
}

.freeform-app-bar-btn.freeform-save-btn.dirty::after {
  content: '' !important;
  position: absolute !important;
  top: 4px !important;
  right: 4px !important;
  width: 8px !important;
  height: 8px !important;
  background: #f59e0b !important;
  border: 2px solid rgba(255, 255, 255, 0.95) !important;
  border-radius: 50% !important;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.45) !important;
}

.freeform-app-bar-icon {
  font-weight: 600 !important;
}

.freeform-header-right {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  margin-left: auto !important;
  flex-shrink: 0 !important;
}

.freeform-time {
  position: relative !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
  padding: clamp(6px, 1.2vw, 10px) clamp(12px, 2vw, 18px) !important;
  background: var(--theme-card-bg) !important;
  border-radius: 12px !important;
  border: 1px solid var(--theme-border) !important;
  font-size: clamp(0.75rem, 1.3vw, 1rem) !important;
  font-weight: 700 !important;
  color: var(--theme-text) !important;
  white-space: nowrap !important;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2) !important;
  backdrop-filter: blur(4px) saturate(1.15) !important;
  -webkit-backdrop-filter: blur(4px) saturate(1.15) !important;
}

.freeform-time::before {
  content: '' !important;
  position: absolute !important;
  inset: -4px !important;
  border-radius: 16px !important;
  background: radial-gradient(circle, var(--theme-primary) 0%, transparent 70%) !important;
  opacity: 0.15 !important;
  z-index: -1 !important;
  filter: blur(8px) !important;
  animation: freeform-pulse-halo 3s ease-in-out infinite !important;
}

@keyframes freeform-pulse-halo {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

.freeform-kiosk-btn {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 44px !important;
  height: 44px !important;
  border-radius: 12px !important;
  border: 2px solid var(--theme-border) !important;
  background: var(--theme-card-bg) !important;
  color: var(--theme-text) !important;
  font-size: 1.15rem !important;
  cursor: pointer !important;
  transition: all 0.25s ease !important;
  flex-shrink: 0 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
}

.freeform-kiosk-btn:hover {
  border-color: var(--theme-primary) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
}

.freeform-kiosk-btn.active {
  border-color: var(--theme-primary) !important;
  background: rgba(86, 168, 255, 0.15) !important;
}

.freeform-lock-btn {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 44px !important;
  height: 44px !important;
  border-radius: 12px !important;
  border: 2px solid var(--theme-border) !important;
  background: var(--theme-card-bg) !important;
  color: var(--theme-text) !important;
  font-size: 1.2rem !important;
  cursor: pointer !important;
  transition: all 0.25s ease !important;
  flex-shrink: 0 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
}

.freeform-lock-btn:hover {
  border-color: var(--theme-primary) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
}

.freeform-lock-btn.unlocked {
  background: linear-gradient(135deg, #3FE7A7, #219d70) !important;
  border: none !important;
  color: #000 !important;
  box-shadow: 0 4px 16px rgba(63, 231, 167, 0.4) !important;
}

/* Override floating FAB styles when buttons are in freeform header */
.weather-bar-freeform .freeform-app-bar-btn,
.weather-bar-freeform .freeform-kiosk-btn,
.weather-bar-freeform .freeform-lock-btn {
  position: static !important;
  transform: none !important;
  margin: 0 !important;
  top: auto !important;
  left: auto !important;
}

.weather-bar-freeform .freeform-app-bar-btn:hover,
.weather-bar-freeform .freeform-kiosk-btn:hover,
.weather-bar-freeform .freeform-lock-btn:hover {
  transform: translateY(-2px) !important;
}

.weather-bar-freeform .freeform-app-bar-btn:active,
.weather-bar-freeform .freeform-kiosk-btn:active,
.weather-bar-freeform .freeform-lock-btn:active {
  transform: translateY(0) !important;
}

/* Profile menu: position on left when in freeform layout (anchored to logo, like tabbed) */
body:has(.dashboard.layout-freeform) .profile-menu.open {
  top: var(--dashboard-weather-bar-height) !important;
  left: 24px !important;
  right: auto !important;
}

/* Hide layout-save when admin locked (same as before) */
body.admin-locked .freeform-save-btn {
  display: none !important;
}

@media (max-width: 900px) {
  .freeform-app-bar-btn .freeform-app-bar-icon {
    display: none !important;
  }
  #appsFab .freeform-app-bar-icon {
    display: inline !important; /* Keep "Apps" text visible */
  }
}

@media (max-width: 600px) {
  .freeform-weather-container {
    display: none !important;
  }
  .freeform-weather-alert-slot {
    display: none !important;
  }
  .freeform-time {
    display: none !important;
  }
  .freeform-app-bar {
    margin-left: 8px !important;
    margin-right: 8px !important;
  }
}

/* Freeform container - transparent so custom background shows through */
.dashboard.layout-freeform #freeformContainer {
  display: block;
  min-height: calc(100vh - var(--dashboard-weather-bar-height));
  height: auto;
  position: relative;
  box-sizing: border-box;
  isolation: isolate;
  background: transparent;
}

.dashboard.layout-freeform #freeformContainer {
  isolation: isolate;
}

/* Freeform dashboard base */
.dashboard.layout-freeform {
  position: relative;
  width: 100%;
  height: auto;
  min-height: calc(100vh - var(--dashboard-weather-bar-height));
  overflow: visible;
  padding-top: var(--dashboard-weather-bar-height);
  max-width: none;
}

/* Freeform widgets - only apply to freeform layout */
/* No backdrop-filter: eliminates compositing layers that cause ~20% CPU on mouse move (even in empty space) */
.dashboard.layout-freeform .widget {
  background: var(--theme-widget-bg);
  border: 1px solid var(--theme-border);
  border-radius: 18px;
  padding: 0 clamp(12px, 2vw, 20px) clamp(12px, 2vw, 20px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  resize: none;
  min-width: 240px;
  min-height: 180px;
  position: absolute;
  cursor: default;
  touch-action: none;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  will-change: auto;
  /* Reduce reflow/repaint scope - limits cascade when hover changes */
  contain: layout style paint;
  left: auto;
  top: auto;
  width: auto;
  height: auto;
}
/* Opaque background when no blur - theme-widget-bg is tuned for blur and too transparent alone */
body.dark-mode .dashboard.layout-freeform .widget,
body[data-theme="dark"] .dashboard.layout-freeform .widget,
body[data-theme="midnight"] .dashboard.layout-freeform .widget {
  background: rgba(10, 12, 22, 0.94);
}
body.light-mode .dashboard.layout-freeform .widget,
body[data-theme="light"] .dashboard.layout-freeform .widget {
  background: rgba(255, 255, 255, 0.96);
}

/* Header: extend to top rounded corners, compact vertical space */
.dashboard.layout-freeform .widget .widget-header {
  margin: 0 calc(-1 * clamp(12px, 2vw, 20px));
  margin-bottom: clamp(6px, 1vw, 10px);
  padding: clamp(6px, 1vw, 10px) clamp(12px, 2vw, 20px);
  border-radius: 18px 18px 0 0;
  border-bottom: 1px solid var(--theme-border);
  background: var(--theme-widget-header-bg);
}

/* Move cursor only on header and bottom drag handle so drag is intentional */
.dashboard.layout-freeform .widget .widget-header,
.dashboard.layout-freeform .widget .widget-drag-handle {
  cursor: move;
  touch-action: none;
}
.dashboard.layout-freeform .widget.widget-dragging .widget-header,
.dashboard.layout-freeform .widget.widget-dragging .widget-drag-handle {
  cursor: grabbing;
}

/* Bottom drag bar: grab here when header is stuck behind weather/ticker bar */
.dashboard.layout-freeform .widget .widget-drag-handle {
  flex: 0 0 auto;
  height: 20px;
  min-height: 20px;
  width: 100%;
  background: transparent;
  border-top: 1px solid var(--theme-border);
  margin-top: auto;
  position: relative;
  z-index: 2;
}
/* Resize handles must sit above drag bar and content so corners are always grabbable */
.dashboard.layout-freeform .widget .widget-resize-handle,
.dashboard.layout-freeform .widget .widget-resize-handle-bl {
  z-index: 1001;
  pointer-events: auto;
}
.dashboard.layout-freeform .widget .widget-drag-handle:hover {
  background: rgba(255, 255, 255, 0.04);
}
body.light-mode .dashboard.layout-freeform .widget .widget-drag-handle:hover {
  background: rgba(0, 0, 0, 0.04);
}
.dashboard.layout-freeform .widget .widget-drag-handle::after {
  content: '⋮⋮';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--theme-text-muted);
  pointer-events: none;
}
/* PERFORMANCE: Disable expensive backdrop-filter during drag/resize to eliminate jitter */

/* Pause decorative animations during widget interaction */
body.widget-interacting .freeform-save-fab.pulse-halo,
body.widget-interacting [class*="pulse-halo"],
body.widget-interacting .freeform-time::before {
  animation-play-state: paused !important;
}

/* Maximized freeform: hide drag + resize handles (widget may be in body for correct fixed positioning) */
.dashboard.layout-freeform .widget.maximized .widget-drag-handle,
body > .widget.maximized .widget-drag-handle {
  display: none !important;
}
.dashboard.layout-freeform .widget.maximized .widget-resize-handle,
.dashboard.layout-freeform .widget.maximized .widget-resize-handle-bl,
body > .widget.maximized .widget-resize-handle,
body > .widget.maximized .widget-resize-handle-bl {
  display: none !important;
  pointer-events: none !important;
}

.dashboard.layout-freeform .widget.widget-resizing {
  will-change: width, height;
  contain: layout paint;
  transition: none !important;
}

.dashboard.layout-freeform .widget.widget-dragging {
  will-change: transform;
  contain: layout paint;
  transition: none !important;
}

/* Hover: border-only to avoid expensive background+backdrop repaint on fast mouse move */
.dashboard.layout-freeform .widget:hover {
  border-color: rgba(86, 168, 255, 0.4);
}

/* Maximized in freeform: header/buttons visible. body > .widget when moved for fixed positioning. */
.dashboard.layout-freeform .widget.maximized .widget-header,
body > .widget.maximized .widget-header {
  z-index: 10000 !important;
  position: relative !important;
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

.dashboard.layout-freeform .widget.maximized .widget-header-actions,
body > .widget.maximized .widget-header-actions {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 10001 !important;
  position: relative !important;
}

.dashboard.layout-freeform .widget.maximized .widget-max-btn,
.dashboard.layout-freeform .widget.maximized .widget-voice-btn,
.dashboard.layout-freeform .widget.maximized .widget-refresh-btn,
.dashboard.layout-freeform .widget.maximized .refresh-btn,
body > .widget.maximized .widget-max-btn,
body > .widget.maximized .widget-voice-btn,
body > .widget.maximized .widget-refresh-btn,
body > .widget.maximized .refresh-btn {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  z-index: 10002 !important;
  position: relative !important;
}

/* Hide widgets until layout is restored */
.dashboard.layout-freeform[data-layout-pending] .widget {
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

