/**
 * assets/css/float-window.css
 * Floating Draggable Detail Window Component
 * JFK ERP theme tokens applied (read assets/css/main*.css)
 * Normalized layer: BASE_Z_INDEX = 300, always < 900 (--z-modal-bg)
 */

.jfk-float-window {
  position: fixed;
  display: flex;
  flex-direction: column;
  background: var(--surface, #16202e);
  color: var(--text, #e7ebf2);
  border: 1px solid var(--border, #2a3648);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  z-index: 300; /* Re-normalized layer: BASE_Z_INDEX = 300, always < 900 (--z-modal-bg) */
  min-width: 280px;
  min-height: 160px;
  max-width: 96vw;
  max-height: 90vh;
  outline: none;
  overflow: hidden;
  box-sizing: border-box;
}

[data-theme="light"] .jfk-float-window {
  background: #ffffff;
  color: var(--text, #16233d);
  border-color: var(--border, #d7dee8);
  box-shadow: 0 12px 32px rgba(20, 40, 74, 0.18);
}

.jfk-float-window.is-focused {
  border-color: var(--accent, #5b90d6);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--accent, #5b90d6);
}

[data-theme="light"] .jfk-float-window.is-focused {
  border-color: var(--accent, #2b5ea3);
  box-shadow: 0 14px 36px rgba(20, 40, 74, 0.22), 0 0 0 1px var(--accent, #2b5ea3);
}

/* Header & Title bar */
.jfk-float-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg, #0e1622);
  border-bottom: 1px solid var(--border, #2a3648);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  flex-shrink: 0;
  gap: 8px;
}

[data-theme="light"] .jfk-float-titlebar {
  background: #f2f4f7;
  border-bottom-color: var(--border, #d7dee8);
}

.jfk-float-titlebar:active {
  cursor: grabbing;
}

.jfk-float-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #e7ebf2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

[data-theme="light"] .jfk-float-title {
  color: var(--text, #16233d);
}

.jfk-float-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.jfk-float-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted, #8d9bb3);
  cursor: pointer;
  padding: 0;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.jfk-float-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text, #e7ebf2);
  border-color: var(--border, #2a3648);
}

[data-theme="light"] .jfk-float-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text, #16233d);
  border-color: var(--border, #d7dee8);
}

.jfk-float-btn-close:hover {
  background: var(--danger, #d96666) !important;
  color: #ffffff !important;
  border-color: transparent !important;
}

/* Body Content */
.jfk-float-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 12px 16px;
  background: var(--surface, #16202e);
  color: var(--text, #e7ebf2);
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

[data-theme="light"] .jfk-float-body {
  background: #ffffff;
  color: var(--text, #16233d);
}

/* Bottom Right Resize Handle */
.jfk-float-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: se-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: linear-gradient(135deg, transparent 50%, var(--border, #2a3648) 50%, var(--border, #2a3648) 70%, transparent 70%, transparent 80%, var(--border, #2a3648) 80%);
  opacity: 0.6;
  transition: opacity 0.15s;
  z-index: 10;
}

.jfk-float-resize-handle:hover,
.jfk-float-window.is-focused .jfk-float-resize-handle {
  opacity: 1;
  background: linear-gradient(135deg, transparent 50%, var(--accent, #5b90d6) 50%, var(--accent, #5b90d6) 70%, transparent 70%, transparent 80%, var(--accent, #5b90d6) 80%);
}

[data-theme="light"] .jfk-float-resize-handle {
  background: linear-gradient(135deg, transparent 50%, var(--border, #cbd5e1) 50%, var(--border, #cbd5e1) 70%, transparent 70%, transparent 80%, var(--border, #cbd5e1) 80%);
}

[data-theme="light"] .jfk-float-resize-handle:hover,
[data-theme="light"] .jfk-float-window.is-focused .jfk-float-resize-handle {
  background: linear-gradient(135deg, transparent 50%, var(--accent, #2b5ea3) 50%, var(--accent, #2b5ea3) 70%, transparent 70%, transparent 80%, var(--accent, #2b5ea3) 80%);
}

@media (max-width: 480px) {
  .jfk-float-window {
    min-width: 240px;
    max-width: 98vw;
    border-radius: 6px;
  }
  .jfk-float-body {
    padding: 10px 12px;
  }
}

/* FloatWindow Detail Table & Sticky Header Styles */
.jfk-float-window .table-wrap,
.jfk-float-window .table-responsive,
.jfk-float-window .ship-drill-content,
.jfk-float-window .sales-drill-viewport,
.jfk-float-window .invexp-drill-viewport {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.jfk-float-window table thead th,
.jfk-float-window table.tbl-modern thead th {
  position: sticky;
  top: 0;
  background: var(--surface, #16202e);
  z-index: 2;
  box-shadow: 0 1px 0 var(--border, #2a3648);
}

[data-theme="light"] .jfk-float-window table thead th,
[data-theme="light"] .jfk-float-window table.tbl-modern thead th {
  background: #ffffff;
  box-shadow: 0 1px 0 var(--border, #d7dee8);
}

/* Minimize Button & Minimized Window State */
.jfk-float-btn-min {
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.jfk-float-window.is-minimized {
  display: none !important;
}

/* Float Window Switcher FAB Button */
#jfk-float-switcher-btn {
  position: fixed;
  right: 28px;
  bottom: 148px;
  z-index: var(--z-popover, 2000);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e293b, #334155);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  outline: none;
}

#jfk-float-switcher-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

#jfk-float-switcher-btn.is-hidden {
  display: none !important;
}

[data-theme="light"] #jfk-float-switcher-btn {
  background: linear-gradient(135deg, #2b3b52, #475569);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 18px rgba(30, 41, 59, 0.25);
}

.jfk-switcher-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.jfk-switcher-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: var(--accent, #3b82f6);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  min-width: 19px;
  height: 19px;
  line-height: 19px;
  text-align: center;
  border-radius: 10px;
  padding: 0 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Float Window Switcher List Panel */
#jfk-float-switcher-panel {
  position: fixed;
  right: 28px;
  bottom: 206px;
  z-index: var(--z-popover, 2000);
  width: min(340px, calc(100vw - 32px));
  max-height: min(420px, 60vh);
  background: var(--surface, #16202e);
  color: var(--text, #e7ebf2);
  border: 1px solid var(--border, #2a3648);
  border-radius: 12px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

#jfk-float-switcher-panel.is-open {
  display: flex;
}

[data-theme="light"] #jfk-float-switcher-panel {
  background: #ffffff;
  border-color: var(--border, #d7dee8);
  box-shadow: 0 16px 40px rgba(20, 40, 74, 0.22);
}

.jfk-switcher-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg, #0e1622);
  border-bottom: 1px solid var(--border, #2a3648);
  flex-shrink: 0;
}

[data-theme="light"] .jfk-switcher-header {
  background: #f2f4f7;
  border-bottom-color: var(--border, #d7dee8);
}

.jfk-switcher-header-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text, #e7ebf2);
}

[data-theme="light"] .jfk-switcher-header-title {
  color: var(--text, #16233d);
}

.jfk-switcher-header-close {
  background: transparent;
  border: none;
  color: var(--muted, #8d9bb3);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
}

.jfk-switcher-header-close:hover {
  color: var(--text, #e7ebf2);
}

.jfk-switcher-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.jfk-switcher-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  gap: 6px;
  padding: 2px 4px;
}

.jfk-switcher-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border, #2a3648);
}

[data-theme="light"] .jfk-switcher-item {
  background: #f8fafc;
}

[data-theme="light"] .jfk-switcher-item:hover {
  background: #eef2f7;
  border-color: var(--border, #d7dee8);
}

.jfk-switcher-item.is-active {
  border-color: var(--accent, #3b82f6);
}

.jfk-switcher-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 4px;
}

.jfk-switcher-tag {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1.3;
}

.jfk-switcher-tag.tag-active {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.jfk-switcher-tag.tag-visible {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.jfk-switcher-tag.tag-min {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.jfk-switcher-item-title {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.jfk-switcher-item-close {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted, #8d9bb3);
  cursor: pointer;
  border-radius: 4px;
  font-size: 15px;
  line-height: 1;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.jfk-switcher-item-close:hover {
  background: var(--danger, #d96666);
  color: #ffffff;
}

.jfk-switcher-empty {
  padding: 20px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted, #8d9bb3);
}

/* Mobile adjustments for Switcher & Windows (175px bottom safety area) */
@media (max-width: 768px), (pointer: coarse) {
  .jfk-float-window {
    max-height: calc(100vh - 175px) !important;
    max-width: calc(100vw - 16px) !important;
    box-sizing: border-box !important;
  }

  .jfk-float-body {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: auto !important;
  }

  .jfk-float-window .table-wrap,
  .jfk-float-window .ship-drill-content,
  .jfk-float-window .sales-drill-viewport,
  .jfk-float-window .invexp-drill-viewport {
    max-width: 100% !important;
    overflow-x: auto !important;
    box-sizing: border-box !important;
    -webkit-overflow-scrolling: touch;
  }

  #fb-float-btn {
    white-space: nowrap !important;
    font-size: 13px !important;
    line-height: 1 !important;
  }

  #jfk-float-switcher-btn {
    right: 14px !important;
    bottom: 118px !important;
    width: 44px !important;
    height: 44px !important;
  }

  #jfk-float-switcher-panel {
    right: 14px !important;
    bottom: 170px !important;
    width: calc(100vw - 28px) !important;
    max-width: 360px !important;
  }
}

/* Hide on login screen to prevent obscuring authentication */
#login-screen:not(.hidden) ~ .jfk-float-window,
body:has(#login-screen:not(.hidden)) .jfk-float-window,
#login-screen:not(.hidden) ~ #jfk-float-switcher-btn,
#login-screen:not(.hidden) ~ #jfk-float-switcher-panel,
body:has(#login-screen:not(.hidden)) #jfk-float-switcher-btn,
body:has(#login-screen:not(.hidden)) #jfk-float-switcher-panel {
  display: none !important;
}

/* Hide on mobile sidebar drawer open to keep drawer (--z-drawer: 200) completely visible */
@media (max-width: 768px) {
  body:has(.sidebar.open) .jfk-float-window,
  body:has(.sidebar.open) #jfk-float-switcher-btn,
  body:has(.sidebar.open) #jfk-float-switcher-panel,
  .sidebar.open ~ #jfk-float-switcher-btn,
  .sidebar.open ~ #jfk-float-switcher-panel,
  #overlay.open ~ #jfk-float-switcher-btn,
  #overlay.open ~ #jfk-float-switcher-panel {
    display: none !important;
  }
}
