/* ===== FLOOR MAP — Factory Floor Styles ===== */

/* Stats bar */
.fm-stats {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px;
}
.fm-stat {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 12px 16px; flex: 1; min-width: 120px;
}
.fm-stat-icon {
  width: 36px; height: 36px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
}
.fm-stat-icon .material-icons-round { font-size: 18px; }
.fm-stat-val { font-size: 1.3rem; font-weight: 800; color: var(--text-primary); }
.fm-stat-lbl { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* Toolbar / Filters */
.fm-toolbar {
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
  align-items: center;
}
.fm-filter-group { display: flex; gap: 4px; }
.fm-fbtn {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 14px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-secondary); color: var(--text-muted); cursor: pointer;
  font-size: 0.78rem; font-weight: 600; transition: all 0.2s;
}
.fm-fbtn:hover { border-color: var(--brand-yellow); color: var(--text-primary); }
.fm-fbtn .material-icons-round { font-size: 16px; }
.fm-fbtn--active { background: var(--brand-yellow); color: #000; border-color: var(--brand-yellow); }
.fm-fbtn--warning { background: #fbbf24; color: #000; border-color: #fbbf24; }
.fm-fbtn--success { background: #4ade80; color: #000; border-color: #4ade80; }

/* Factory floor */
.fm-floor { display: flex; flex-direction: column; gap: 28px; }

/* Sector */
.fm-sector { display: flex; flex-direction: column; gap: 14px; }
.fm-sector-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--bg-secondary);
  border-radius: var(--r-lg); border-left: 4px solid var(--sec-color, #94a3b8);
}
.fm-sector-header .material-icons-round { font-size: 22px; }
.fm-sector-name { font-size: 1rem; font-weight: 800; color: var(--text-primary); }
.fm-sector-badges { display: flex; gap: 8px; margin-left: auto; }
.fm-sector-count {
  font-size: 0.7rem; color: var(--text-muted);
  background: var(--bg-tertiary); padding: 3px 10px; border-radius: var(--r-full);
}

/* Row */
.fm-row {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 16px; overflow: hidden;
  position: relative;
}
.fm-row::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(to bottom, #FFE500, #f59e0b); border-radius: 3px 0 0 3px;
}
.fm-row-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; padding-left: 8px;
}
.fm-row-badge {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 0.9rem; color: var(--text-primary);
}
.fm-row-badge .material-icons-round { color: var(--brand-yellow); font-size: 20px; }
.fm-row-count {
  font-size: 0.7rem; color: var(--text-muted);
  background: var(--bg-tertiary); padding: 3px 10px; border-radius: var(--r-full);
}

/* Machines grid */
.fm-row-machines {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 12px;
}

/* Machine card */
.fm-machine {
  position: relative; cursor: pointer;
  background: var(--mbg, var(--bg-tertiary));
  border: 1px solid var(--mb, var(--border));
  border-radius: var(--r-lg);
  padding: 12px 12px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: all 0.25s ease;
  overflow: hidden;
}
.fm-machine:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  border-color: var(--mc, var(--brand-yellow));
}

/* Drag & Drop */
.fm-drop-target { border: 2px dashed var(--brand-yellow) !important; opacity: 1; }
.fm-drop-hover { border-color: var(--brand-yellow) !important; background: rgba(255,229,0,0.06) !important; transform: scale(1.02); }
.fm-drop-blocked { opacity: 0.3; pointer-events: none; }
.fm-dragging { opacity: 0.4; transform: scale(0.95); }
.fm-card--loading { opacity: 0.5; pointer-events: none; }

/* Pulse animation */
.fm-machine--pulse { animation: fmPulse 2.5s ease-in-out infinite; }
@keyframes fmPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
  50% { box-shadow: 0 0 0 5px rgba(74,222,128,0.1); }
}

/* Late */
.fm-machine--late { border-color: rgba(239,68,68,0.5) !important; }

/* Status bar */
.fm-status-bar {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  border-radius: 3px 3px 0 0;
}

/* Code badge */
.fm-code {
  position: absolute; top: 6px; left: 8px;
  font-size: 0.56rem; font-weight: 800; color: var(--text-muted);
  letter-spacing: 0.4px; opacity: 0.6;
}

/* Icon / Photo */
.fm-icon-wrap {
  position: relative; margin-top: 2px;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary); border-radius: var(--r-md);
  border: 1px solid var(--border); overflow: hidden;
}
.fm-icon-wrap--photo { cursor: zoom-in; }
.fm-machine-photo {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: var(--r-md); transition: transform 0.3s;
}
.fm-icon-wrap--photo:hover .fm-machine-photo { transform: scale(1.15); }
.fm-type-icon { font-size: 22px; }
.fm-type-icon--fallback { align-items: center; justify-content: center; width: 100%; height: 100%; }
.fm-alert-dot {
  position: absolute; top: -2px; right: -2px;
  width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--bg-secondary);
  animation: fmBlink 1.2s ease-in-out infinite; z-index: 2;
}
@keyframes fmBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Machine name */
.fm-name {
  font-size: 0.78rem; font-weight: 700; color: var(--text-primary);
  text-align: center; line-height: 1.2; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Status badge */
.fm-status-badge {
  display: flex; align-items: center; gap: 3px;
  font-size: 0.58rem; font-weight: 700; text-transform: uppercase;
  padding: 2px 7px; border-radius: var(--r-full);
  border: 1px solid; letter-spacing: 0.3px;
}
.fm-status-badge .material-icons-round { font-size: 11px; }

/* Active order */
.fm-active {
  width: 100%; display: flex; flex-direction: column; gap: 3px;
  padding: 6px 8px; background: rgba(0,0,0,0.15);
  border-radius: var(--r-sm); margin-top: 2px;
}
.fm-active-os { font-size: 0.7rem; font-weight: 700; color: var(--text-primary); }
.fm-active-client { font-size: 0.62rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-active-op {
  display: flex; align-items: center; gap: 3px;
  font-size: 0.6rem; color: var(--text-muted);
}
.fm-active-op .material-icons-round { font-size: 11px; }
.fm-active-timer {
  display: flex; align-items: center; gap: 3px;
  font-size: 0.68rem; font-weight: 700; color: #4ade80;
  font-family: 'JetBrains Mono', monospace;
  transition: color 0.5s ease;
}
.fm-active-timer .material-icons-round { font-size: 13px; }
.fm-active-timer--paused { color: #fbbf24; }
/* Large timer variant (in machine cards) */
.fm-active-timer--large {
  font-size: 0.9rem; gap: 5px;
  padding: 4px 8px; border-radius: var(--r-sm);
  background: rgba(0,0,0,0.2);
  justify-content: center; width: 100%;
}
.fm-active-timer--large .material-icons-round { font-size: 16px; }
/* Warning: 2-4 hours */
.fm-timer--warning { color: #fbbf24 !important; }
.fm-timer--warning .material-icons-round { color: #fbbf24 !important; }
/* Danger: >4 hours or paused >30min */
.fm-timer--danger {
  color: #ef4444 !important;
  animation: fmTimerPulse 1.5s ease-in-out infinite;
}
.fm-timer--danger .material-icons-round { color: #ef4444 !important; }
@keyframes fmTimerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
/* Idle timer for waiting machines */
.fm-idle-timer {
  display: flex; align-items: center; gap: 3px;
  font-size: 0.62rem; font-weight: 600; color: #f59e0b;
  font-family: 'JetBrains Mono', monospace;
  margin-top: 2px; opacity: 0.85;
}
.fm-idle-timer .material-icons-round { font-size: 12px; color: #f59e0b; }

/* Mini progress bar */
.fm-progress-mini {
  width: 100%; height: 14px; background: rgba(255,255,255,0.06);
  border-radius: 7px; position: relative; overflow: hidden; margin-top: 2px;
}
.fm-progress-mini .fm-progress-fill {
  height: 100%; border-radius: 7px; transition: width 0.3s;
}
.fm-progress-mini span {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font-size: 0.55rem; font-weight: 700; color: var(--text-primary);
}

/* Queue & Idle */
.fm-queue {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.68rem; color: #60a5fa; margin-top: 2px;
}
.fm-queue .material-icons-round { font-size: 13px; }
.fm-idle {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.68rem; color: var(--text-muted); margin-top: 2px; opacity: 0.6;
}
.fm-idle .material-icons-round { font-size: 13px; }

/* Order list inside machine card */
.fm-order-list {
  width: 100%; display: flex; flex-direction: column; gap: 2px;
  margin-top: 4px; border-top: 1px solid var(--border); padding-top: 4px;
}
.fm-order-mini {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 6px; border-radius: var(--r-xs, 4px);
  cursor: grab; transition: background 0.15s; font-size: 0.66rem;
}
.fm-order-mini:hover { background: rgba(255,255,255,0.06); }
.fm-order-mini--late { color: #ef4444; }
.fm-om-os { font-weight: 700; color: var(--text-primary); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.fm-om-qty { font-size: 0.6rem; color: var(--text-muted); white-space: nowrap; }
.fm-om-drag { color: var(--text-muted); opacity: 0.4; display: flex; }
.fm-om-drag .material-icons-round { font-size: 14px; }
.fm-order-more { font-size: 0.6rem; color: var(--text-muted); text-align: center; padding: 2px; }

/* OS count badge */
.fm-order-count-badge {
  position: absolute; top: 5px; right: 7px;
  font-size: 0.55rem; font-weight: 700; color: var(--text-muted);
  background: var(--bg-primary); padding: 1px 5px; border-radius: var(--r-full);
  border: 1px solid var(--border);
}

/* ===== Detail Modal ===== */
.fm-detail { display: flex; flex-direction: column; gap: 14px; }
.fm-detail-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--bg-tertiary);
  border-radius: var(--r-md); border-left: 4px solid;
}
.fm-detail-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fm-detail-code {
  font-size: 0.72rem; font-weight: 800; padding: 3px 10px;
  border-radius: var(--r-sm); letter-spacing: 0.5px;
}
.fm-detail-name { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); }
.fm-detail-status {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.68rem; font-weight: 700; padding: 3px 10px;
  border-radius: var(--r-full); text-transform: uppercase;
}
.fm-detail-status .material-icons-round { font-size: 14px; }

/* Detail active production */
.fm-detail-active {
  background: var(--bg-tertiary); border-radius: var(--r-md);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.fm-detail-active-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.fm-detail-active-os { font-weight: 700; font-size: 0.9rem; color: var(--text-primary); }
.fm-detail-active-op {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.75rem; color: var(--text-muted);
}
.fm-detail-active-op .material-icons-round { font-size: 14px; }
.fm-detail-active-timer {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.82rem; font-weight: 700; color: #4ade80;
  font-family: 'JetBrains Mono', monospace; margin-left: auto;
}
.fm-detail-active-timer .material-icons-round { font-size: 16px; }
.fm-detail-active-timer--paused { color: #fbbf24; }
.fm-detail-active-qty { font-size: 0.75rem; color: var(--text-secondary); text-align: right; }

/* Orders section */
.fm-detail-orders { display: flex; flex-direction: column; gap: 6px; }
.fm-detail-section-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem; font-weight: 700; color: var(--text-secondary);
  margin-bottom: 4px;
}
.fm-detail-section-title .material-icons-round { font-size: 16px; color: var(--brand-yellow); }

.fm-os-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: var(--bg-tertiary);
  border-radius: var(--r-sm); border-left: 3px solid var(--border);
  cursor: pointer; transition: all 0.2s;
}
.fm-os-row:hover { background: var(--bg-hover); transform: translateX(2px); }
.fm-os--prod { border-left-color: #4ade80; }
.fm-os--pause { border-left-color: #fbbf24; }
.fm-os--rework { border-left-color: #ef4444; }
.fm-os--late { border-left-color: #ef4444; background: rgba(239,68,68,0.04); }
.fm-os-main { display: flex; flex-direction: column; gap: 2px; }
.fm-os-id { font-size: 0.78rem; font-weight: 700; color: var(--text-primary); }
.fm-os-client { font-size: 0.7rem; color: var(--text-muted); }
.fm-os-meta { display: flex; align-items: center; gap: 8px; }
.fm-os-qty { font-size: 0.72rem; font-weight: 600; color: var(--text-secondary); }
.fm-os-date { font-size: 0.66rem; color: var(--text-muted); }
.fm-os-date--late { color: #ef4444; font-weight: 700; }
.fm-os-drag { color: var(--text-muted); opacity: 0.4; display: flex; cursor: grab; }
.fm-os-drag .material-icons-round { font-size: 16px; }

/* Responsive */
@media (max-width: 768px) {
  .fm-row-machines { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
  .fm-machine { padding: 10px 10px 8px; }
  .fm-stats { gap: 6px; }
  .fm-stat { padding: 8px 10px; min-width: 90px; }
  .fm-stat-val { font-size: 1rem; }
}
@media (max-width: 480px) {
  .fm-row-machines { grid-template-columns: repeat(2, 1fr); }
  .fm-stat { min-width: 70px; }
}

/* ===== Photo Zoom Lightbox ===== */
.fm-zoom-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85); z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.25s ease;
  cursor: pointer;
}
.fm-zoom--visible { opacity: 1; }
.fm-zoom-content {
  max-width: 90vw; max-height: 90vh;
  display: flex; flex-direction: column;
  background: var(--bg-secondary); border-radius: var(--r-xl);
  overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  cursor: default; animation: fmZoomIn 0.3s ease;
}
@keyframes fmZoomIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.fm-zoom-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}
.fm-zoom-title {
  font-size: 1rem; font-weight: 700; color: var(--text-primary);
}
.fm-zoom-close {
  width: 32px; height: 32px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.fm-zoom-close:hover { background: #ef4444; color: white; border-color: #ef4444; }
.fm-zoom-close .material-icons-round { font-size: 18px; }
.fm-zoom-img {
  max-width: 85vw; max-height: 80vh; object-fit: contain;
}
