<!-- pages/Anjungan/AntreanMasuk/[id].vue -->
<template>
  <div class="antrian-display-container">
    <!-- Header -->
    <div class="display-header">
      <div class="header-left">
        <div class="logo-circle">
          <img 
            src="/Rumah_Sakit_Umum_Daerah_Dr._Saiful_Anwar.webp" 
            alt="RSUD Logo" 
            class="header-logo"
          >
        </div>
        <div class="header-text">
          <h1 class="hospital-name">RSUD dr. Saiful Anwar Provinsi Jawa Timur</h1>
          <!-- <p class="display-subtitle">RSUD dr. Saiful Anwar Provinsi Jawa Timur</p> -->
        </div>
      </div>
      <div class="header-right">
        <div class="datetime-display">
          <div class="time-large">{{ currentTime }}</div>
          <div class="date-small">{{ currentDate }}</div>
        </div>
      </div>
    </div>

    <!-- Main Grid - Display Loket Cards -->
    <div class="loket-grid-container">
      <!-- Loket Grid -->
      <div class="lokets-grid" :style="gridStyle">
        <div
          v-for="loketData in displayedLokets"
          :key="loketData.id"
          class="loket-card"
        >
          <!-- Loket Header -->
          <div class="loket-header-bar">
            <div class="loket-name">{{ loketData.nama }}</div>
            <div class="queue-count">
              <v-icon size="18" color="white">mdi-account-multiple</v-icon>
              <span class="count-number">{{ loketData.totalQueues }}</span>
            </div>
          </div>

          <!-- Queue Display - Vertical Scrollable -->
          <div 
            :ref="el => setQueueDisplayRef(loketData.id, el)"
            class="queue-display" 
            :class="{ 'has-scroll': loketData.queues.length > 20 }"
          >
            <!-- Ticket Cards List -->
            <div v-if="loketData.queues.length > 0" class="ticket-cards-list" :style="ticketGridStyle">
              <div
                v-for="(queue, index) in loketData.queues"
                :key="`${loketData.id}-${queue.no}-${queue.barcode || index}`"
                class="ticket-card"
                :class="{ 'ticket-card-fast-track': queue.fastTrack === 'YA' }"
              >
                <!-- Fast Track Badge - Pojok Kanan Atas -->
                <div v-if="queue.fastTrack === 'YA'" class="ticket-fast-track">
                  <v-icon color="white" size="14">mdi-flash</v-icon>
                </div>
                <div class="ticket-number">{{ queue.noAntrian?.split(" |")[0] || queue.no || '' }}</div>
                <!-- <div v-if="queue.klinik" class="ticket-klinik">{{ queue.klinik }}</div> -->
              </div>
            </div>

            <!-- Empty State -->
            <div
              v-else
              class="empty-queue"
            >
              <v-icon size="40" color="grey-lighten-3">mdi-minus-circle-outline</v-icon>
              <div class="empty-text">Tidak Ada Antrian</div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- Footer Stats -->
    <div class="footer-stats-bar">
      <div class="stat-item">
        <div class="stat-icon stat-icon-total">
          <v-icon size="32" color="primary-600">mdi-format-list-numbered</v-icon>
        </div>
        <div class="stat-info">
          <div class="stat-value">{{ statistics?.total ?? 0 }}</div>
          <div class="stat-label">Total Antrian</div>
        </div>
      </div>

      <div class="stat-divider" />

      <div class="stat-item">
        <div class="stat-icon stat-icon-waiting">
          <v-icon size="32" color="primary-600">mdi-clock-alert-outline</v-icon>
        </div>
        <div class="stat-info">
          <div class="stat-value">{{ statistics?.waiting ?? 0 }}</div>
          <div class="stat-label">Menunggu</div>
        </div>
      </div>

      <div class="stat-divider" />

      <div class="stat-item">
        <div class="stat-icon stat-icon-active">
          <v-icon size="32" color="primary-600">mdi-account-check</v-icon>
        </div>
        <div class="stat-info">
          <div class="stat-value">{{ statistics?.active ?? 0 }}</div>
          <div class="stat-label">Dipanggil untuk Check-in</div>
        </div>
      </div>

      <div class="footer-message">
        <v-icon size="24" color="primary-600" class="mr-2">mdi-information</v-icon>
        <span>Harap perhatikan nomor tiket Anda yang dipanggil untuk check-in</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue'
import { useQueueStore } from '@/stores/queueStore'
import { useMasterStore } from '@/stores/masterStore'
import { useAntreanMasukScreenStore } from '@/stores/antreanMasukScreenStore'
import { useRoute } from '#app'

definePageMeta({
  layout: false,
})

const route = useRoute()
const queueStore = useQueueStore()
const masterStore = useMasterStore()
const antreanMasukScreenStore = useAntreanMasukScreenStore()

// Get screen ID from route (not loket ID)
const screenId = computed(() => {
  const id = route.params.id
  // Handle both string and array cases
  const idValue = Array.isArray(id) ? id[0] : id
  const parsed = parseInt(idValue)
  return isNaN(parsed) ? null : parsed
})

// Get screen configuration
const screenData = computed(() => {
  const id = screenId.value
  if (!id) return null
  
  const screen = antreanMasukScreenStore.antreanMasukScreenItems.find(s => s.id === id)
  return screen || null
})

// Get all loket IDs configured for this screen
const configuredLoketIds = computed(() => {
  return screenData.value?.loket || []
})


const currentTime = ref('')
const currentDate = ref('')
let timeInterval = null

// Refs for queue display containers (for auto-scroll)
const queueDisplayRefs = ref({})

const setQueueDisplayRef = (loketId, el) => {
  if (el) {
    queueDisplayRefs.value[loketId] = el
  }
}

// Get all patients with processStage 'loket'
// Force reactivity by accessing the computed result directly
const loketPatients = computed(() => {
  try {
    // Get the computed result from store
    const stageResult = queueStore.getPatientsByStage('loket')
    
    // Access .value to get the actual computed value
    // This ensures reactivity after store hydration
    if (stageResult && stageResult.value) {
      const patients = stageResult.value.all || []
      // Ensure it's an array and filter out any null/undefined
      return Array.isArray(patients) ? patients.filter(p => p != null) : []
    }
    return []
  } catch (error) {
    console.error('Error getting loket patients:', error)
    return []
  }
})

// Filter: Only show tickets from anjungan that are called for check-in
// These are tickets printed from anjungan that have been called by admin loket
// Status berubah dari 'menunggu' menjadi 'waiting' ketika dipanggil oleh admin loket
// Status 'waiting' = sudah dipanggil tapi belum check-in
// Filter berdasarkan loket yang dikonfigurasi di screen
const calledForCheckIn = computed(() => {
  const loketIds = configuredLoketIds.value
  
  // Jika tidak ada loket yang dikonfigurasi, return empty array
  if (!loketIds || loketIds.length === 0) {
    return []
  }
  
  return loketPatients.value
    .filter(p => {
      // Must be called (waiting status = sudah dipanggil dari status menunggu) 
      // and not yet checked in (processStage still 'loket')
      const isCalled = p.status === 'waiting' && p.processStage === 'loket'
      
      // Filter berdasarkan loketId yang dikonfigurasi di screen
      const patientLoketId = p.loketId || 1 // Default ke loket 1 jika tidak ada
      const isForConfiguredLoket = loketIds.includes(patientLoketId)
      
      return isCalled && isForConfiguredLoket
    })
    // Tidak perlu sorting - tampilkan semua sesuai urutan dari store
})

// Removed displayedQueues - tidak diperlukan lagi karena menggunakan allCalledQueues

// Group queues by loketId and create loket cards
const displayedLokets = computed(() => {
  const loketIds = configuredLoketIds.value
  
  if (!loketIds || loketIds.length === 0) {
    return []
  }
  
  // Ensure calledForCheckIn is an array
  const queues = Array.isArray(calledForCheckIn.value) ? calledForCheckIn.value : []
  
  // Group queues by loketId
  const queuesByLoket = new Map()
  
  loketIds.forEach(loketId => {
    const loket = masterStore.getLoketById(loketId)
    const loketQueues = queues
      .filter(q => {
        const patientLoketId = q.loketId || 1
        return patientLoketId === loketId
      })
      .sort((a, b) => {
        // Sort by createdAt or no for consistent ordering
        if (a.createdAt && b.createdAt) {
          return new Date(a.createdAt) - new Date(b.createdAt)
        }
        return (a.no || 0) - (b.no || 0)
      })
    
    queuesByLoket.set(loketId, {
      id: loketId,
      nama: loket ? loket.namaLoket : `Loket ${loketId}`,
      queues: loketQueues,
      totalQueues: loketQueues.length
    })
  })
  
  // Filter: hanya tampilkan loket yang memiliki antrian
  return Array.from(queuesByLoket.values()).filter(loket => loket.queues.length > 0)
})

// Calculate grid columns based on number of displayed lokets
const gridColumns = computed(() => {
  const count = displayedLokets.value.length
  // Jika hanya 1-2 loket, tampilkan 1 kolom (full width)
  if (count <= 2) return 1
  // Jika 3-4 loket, tampilkan 2 kolom
  if (count <= 4) return 2
  // Jika 5-6 loket, tampilkan 3 kolom
  if (count <= 6) return 3
  // Jika 7-9 loket, tampilkan 4 kolom
  if (count <= 9) return 4
  // Jika 10-12 loket, tampilkan 5 kolom
  if (count <= 12) return 5
  // Jika 13-14 loket, tampilkan 6 kolom
  if (count <= 14) return 6
  // Default: 7 kolom untuk 15+ loket
  return 7
})

const gridStyle = computed(() => {
  return {
    gridTemplateColumns: `repeat(${gridColumns.value}, 1fr)`
  }
})

// Calculate ticket grid columns based on loket grid columns
// When loket is wider (fewer columns), tickets can form more columns
const ticketGridColumns = computed(() => {
  const loketCols = gridColumns.value
  // Jika hanya 1 kolom loket (full width), tiket bisa 3 kolom
  if (loketCols === 1) return 3
  // Jika 2 kolom loket, tiket bisa 2 kolom
  if (loketCols === 2) return 2
  // Jika 3 kolom loket, tiket bisa 2 kolom
  if (loketCols === 3) return 2
  // Jika 4+ kolom loket, tiket 1 kolom (vertikal)
  return 1
})

const ticketGridStyle = computed(() => {
  return {
    gridTemplateColumns: `repeat(${ticketGridColumns.value}, 1fr)`
  }
})

const statistics = computed(() => {
  // Ensure we always return default values even if data is not ready
  try {
    const loketIds = configuredLoketIds.value
    
    // Jika tidak ada loket yang dikonfigurasi, return 0
    if (!loketIds || loketIds.length === 0) {
      return {
        total: 0,
        waiting: 0,
        active: 0
      }
    }
    
    // Ensure loketPatients is an array
    const patients = Array.isArray(loketPatients.value) ? loketPatients.value : []
    
    // Filter semua pasien untuk loket-loket yang dikonfigurasi di screen
    const allLoketTickets = patients.filter(p => {
      if (!p) return false
      
      // Filter berdasarkan loketId yang dikonfigurasi
      const patientLoketId = p.loketId || 1 // Default ke loket 1 jika tidak ada
      return loketIds.includes(patientLoketId)
    })
    
    // Menunggu = belum dipanggil (status 'menunggu')
    const menungguCount = allLoketTickets.filter(p => p && p.status === 'menunggu').length
    
    // Dipanggil untuk check-in = sudah dipanggil (status 'waiting')
    const calledForCheckInArray = Array.isArray(calledForCheckIn.value) ? calledForCheckIn.value : []
    const activeCount = calledForCheckInArray.length
    
    return {
      total: allLoketTickets.length || 0,
      waiting: menungguCount || 0, // Jumlah yang masih menunggu untuk dipanggil
      active: activeCount || 0 // Jumlah yang sudah dipanggil dan ditampilkan di layar
    }
  } catch {
    // Return default values if there's any error
    return {
      total: 0,
      waiting: 0,
      active: 0
    }
  }
})

const updateTime = () => {
  const now = new Date()
  // Format jam dengan titik dua (HH:MM:SS)
  const timeString = now.toLocaleTimeString('id-ID', { 
    hour: '2-digit', 
    minute: '2-digit',
    second: '2-digit'
  })
  currentTime.value = timeString.replace(/\./g, ':')
  currentDate.value = now.toLocaleDateString('id-ID', {
    weekday: 'long',
    day: 'numeric',
    month: 'long',
    year: 'numeric'
  })
}

// Auto-scroll setiap 2 detik dengan loop (atas -> bawah -> atas)
let scrollIntervals = {}

const startAutoScroll = () => {
  // Clear existing intervals
  Object.values(scrollIntervals).forEach(interval => {
    if (interval) clearInterval(interval)
  })
  scrollIntervals = {}

  nextTick(() => {
    displayedLokets.value.forEach(loketData => {
      const container = queueDisplayRefs.value[loketData.id]
      if (container && loketData.queues.length > 0) {
        let isScrollingDown = true
        let currentScrollTop = 0

        scrollIntervals[loketData.id] = setInterval(() => {
          const maxScroll = container.scrollHeight - container.clientHeight
          
          // Jika konten tidak cukup untuk di-scroll, skip
          if (maxScroll <= 0) {
            return
          }
          
          // Hitung ukuran scroll berdasarkan tinggi card
          // Ambil tinggi card pertama jika ada, atau gunakan default 80px (min-height ticket-card)
          let scrollAmount = 80 // Default: min-height ticket-card
          const firstCard = container.querySelector('.ticket-card')
          if (firstCard) {
            const cardRect = firstCard.getBoundingClientRect()
            const cardHeight = cardRect.height
            // Tambahkan gap (10px dari .ticket-cards-list gap)
            scrollAmount = cardHeight + 10
          }
          
          if (isScrollingDown) {
            // Scroll ke bawah dengan ukuran card
            currentScrollTop += scrollAmount
            if (currentScrollTop >= maxScroll) {
              // Sudah sampai bawah, kembali ke atas dan lanjut scroll ke bawah
              currentScrollTop = 0
              // Tetap isScrollingDown = true agar langsung scroll ke bawah lagi
            }
          } else {
            // Scroll ke atas (tidak digunakan karena langsung reset ke atas)
            currentScrollTop -= scrollAmount
            if (currentScrollTop <= 0) {
              currentScrollTop = 0
              isScrollingDown = true
            }
          }

          container.scrollTop = currentScrollTop
        }, 2000) // Setiap 2 detik
      }
    })
  })
}

// Watch loketPatients to ensure reactivity after refresh
watch(loketPatients, (newPatients) => {
  // Force update by accessing the computed
  // This ensures reactivity after store hydration
  if (newPatients && newPatients.length > 0) {
    console.log('Loket patients updated:', newPatients.length)
  }
}, { immediate: true, deep: true })

// Watch store's getPatientsByStage to ensure reactivity after refresh
watch(() => {
  try {
    const result = queueStore.getPatientsByStage('loket')
    return result?.value?.all || []
  } catch {
    return []
  }
}, (newPatients) => {
  // Force reactivity update
  if (newPatients && newPatients.length > 0) {
    console.log('Store loket patients updated:', newPatients.length)
  }
}, { immediate: true, deep: true })

// Watch displayedLokets untuk restart auto-scroll
watch(displayedLokets, () => {
  startAutoScroll()
}, { deep: true })

onMounted(() => {
  // Wait for stores to be hydrated from persisted state
  // Use nextTick to ensure stores are ready
  nextTick(() => {
    // Redirect to index if screen not found
    if (!screenData.value) {
      navigateTo('/anjungan/antreanmasuk')
      return
    }
    
    // Force reactivity by accessing store data after delays
    // This ensures store is fully hydrated after refresh
    setTimeout(() => {
      // Access loketPatients to trigger computed
      const _ = loketPatients.value
      // Access calledForCheckIn to trigger computed
      const __ = calledForCheckIn.value
      // Access displayedLokets to trigger computed
      const ___ = displayedLokets.value
    }, 100)
    
    // Additional delay to ensure store hydration is complete
    setTimeout(() => {
      // Force re-computation by accessing again
      const _ = loketPatients.value
      const __ = calledForCheckIn.value
      const ___ = displayedLokets.value
    }, 300)
    
    updateTime()
    timeInterval = setInterval(updateTime, 1000)
    
    // Start auto-scroll setelah delay singkat
    setTimeout(() => {
      startAutoScroll()
    }, 500)
  })
})

onUnmounted(() => {
  if (timeInterval) clearInterval(timeInterval)
  
  // Clear all scroll intervals
  Object.values(scrollIntervals).forEach(interval => {
    if (interval) clearInterval(interval)
  })
  scrollIntervals = {}
})
</script>

<style scoped lang="scss">
.antrian-display-container {
  background: #FFFFFF;
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  padding: 24px;
  font-family: 'Roboto', sans-serif;
  overflow: auto;
  display: flex;
  flex-direction: column;
  margin: 0;
  box-sizing: border-box;
  position: relative;
}

/* Ensure body/html don't cause layout issues */
:deep(body),
:deep(html) {
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

:deep(#__nuxt) {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

/* ========== HEADER ========== */
.display-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-primary-700) 100%);
  border-radius: 16px;
  padding: 24px 40px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(25, 118, 210, 0.3);
  flex-shrink: 0;
  box-sizing: border-box;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo-circle {
  background: rgba(255, 255, 255, 0.95);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  padding: 4px;
}

.header-text {
  flex: 1;
}

.hospital-name {
  font-size: 48px;
  font-weight: 800;
  color: var(--color-neutral-100);
  margin: 0;
  letter-spacing: 2px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  line-height: 1;
}

.display-subtitle {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-neutral-100);
  margin: 6px 0 0 0;
  opacity: 0.95;
}

.klinik-info {
  font-size: 16px;
  font-weight: 500;
  color: var(--color-neutral-100);
  margin: 4px 0 0 0;
  opacity: 0.85;
}

.loket-info {
  font-size: 16px;
  font-weight: 500;
  color: var(--color-neutral-100);
  margin: 4px 0 0 0;
  opacity: 0.85;
}

.header-right {
  display: flex;
  align-items: center;
}

.datetime-display {
  text-align: right;
}

.time-large {
  font-size: 56px;
  font-weight: 900;
  color: var(--color-neutral-100);
  letter-spacing: 2px;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.date-small {
  font-size: 18px;
  color: var(--color-neutral-100);
  margin-top: 8px;
  font-weight: 500;
  opacity: 0.95;
}

/* ========== LOKET GRID CONTAINER ========== */
.loket-grid-container {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  margin-bottom: 24px;
  min-height: 0;
  box-sizing: border-box;
}

.lokets-grid {
  display: grid;
  gap: 16px;
  width: 100%;
  box-sizing: border-box;
  /* grid-template-columns is set dynamically via :style binding */
}

.loket-card {
  background: #FFFFFF;
  border-radius: 8px;
  border: 1px solid #E0E0E0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  min-height: 400px;
  /* Calculate: viewport - header (~120px) - footer (100px) - container padding (48px) - margins (44px) */
  max-height: calc(100vh - 312px);
}

/* Loket Header */
.loket-header-bar {
  background: #FFFFFF;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px solid #FF9B1B;
  flex-shrink: 0;
}

.loket-name {
  font-size: 20px;
  font-weight: 700;
  color: #212121;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  flex: 1;
}

.queue-count {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-primary-600);
  padding: 6px 12px;
  border-radius: 20px;
  min-width: 50px;
  justify-content: center;
}

.queue-count .v-icon {
  color: white !important;
}

.count-number {
  font-size: 16px;
  font-weight: 700;
  color: #FFFFFF;
}

/* Queue Display - Vertical Scrollable */
.queue-display {
  flex: 1;
  padding: 20px;
  padding-bottom: 120px; /* Extra padding to prevent footer overlap */
  overflow-y: auto;
  overflow-x: hidden;
  background: #FFFFFF;
  min-height: 0;
  scroll-behavior: smooth;
  box-sizing: border-box;
}

.queue-display.has-scroll {
  max-height: calc(100vh - 400px);
}

/* Hide scrollbar */
.queue-display {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.queue-display::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.ticket-cards-list {
  display: grid;
  gap: 10px;
  width: 100%;
  padding-bottom: 20px; /* Additional bottom padding for last card */
  /* grid-template-columns is set dynamically via :style binding */
}

.ticket-card {
  background: #F5F7FA ;
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  min-height: 80px;
  position: relative; /* Untuk absolute positioning fast track icon */
}

.ticket-card-fast-track {
  background: rgba(255, 132, 65, 0.4) !important; /* #FF8441 dengan 40% opacity (66 hex = 102/255) */
}

.ticket-card:hover {
  box-shadow: 0 2px 6px rgba(25, 118, 210, 0.2);
  border-color: var(--color-primary-600);
  transform: translateY(-1px);
}

.ticket-number {
  font-size: 28px;
  font-weight: 800;
  color: #3556AE;
  letter-spacing: 1px;
  line-height: 1.2;
}

.ticket-klinik {
  font-size: 11px;
  font-weight: 500;
  color: #717171;
  text-align: center;
  margin-top: 4px;
}

.ticket-fast-track {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 83, 80, 0.15); /* Red background dengan opacity */
  border: 2px solid rgba(229, 57, 53, 0.4); /* Red border */
  transition: all 0.2s ease;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(229, 57, 53, 0.2);
}

.ticket-fast-track:hover {
  background: #E53935; /* Solid red on hover */
  border-color: #E53935;
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(229, 57, 53, 0.4);
}

.ticket-fast-track .v-icon {
  color: #E53935 !important;
  transition: all 0.2s ease;
}

.ticket-fast-track:hover .v-icon {
  color: white !important;
}

.empty-queue {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  min-height: 300px;
}

.empty-queue .v-icon {
  color: #BDBDBD !important;
  margin-bottom: 12px;
}

.empty-text {
  font-size: 14px;
  color: #89939E;
  margin-top: 8px;
  font-weight: 500;
}

/* ========== FOOTER STATS ========== */
.footer-stats-bar {
  background: #FFFFFF;
  border: 2px solid var(--color-primary-200);
  border-radius: 20px;
  padding: 24px 40px;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  box-shadow: 0 4px 16px rgba(25, 118, 210, 0.08);
  flex: 0 0 100px;
  flex-shrink: 0;
  flex-grow: 0;
  height: 100px;
  order: 999;
  min-height: 100px;
  max-height: 100px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  position: relative;
  overflow: visible;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 10;
  margin-top: auto;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  min-width: fit-content;
  width: auto;
  height: 64px;
}

.stat-icon {
  width: 64px;
  height: 64px;
  min-width: 64px;
  min-height: 64px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon-total,
.stat-icon-waiting {
  background: var(--color-primary-200);
}

.stat-icon-active {
  background: var(--color-primary-200);
}

.stat-info {
  text-align: left;
  flex-shrink: 0;
  min-width: fit-content;
  width: auto;
  height: 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat-value {
  font-size: 42px;
  font-weight: 900;
  color: #212121;
  line-height: 1;
  white-space: nowrap;
  height: 42px;
  display: flex;
  align-items: center;
}

.stat-label {
  font-size: 15px;
  color: #717171;
  font-weight: 600;
  margin-top: 4px;
  height: 18px;
  line-height: 18px;
}

.stat-divider {
  width: 2px;
  height: 64px;
  min-width: 2px;
  min-height: 64px;
  background: var(--color-primary-200);
  flex-shrink: 0;
}

.footer-message {
  flex: 1;
  text-align: right;
  font-size: 20px;
  font-weight: 600;
  color: #4D4D4D;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 64px;
  padding-left: 32px;
}

/* ========== RESPONSIVE ========== */
/* Fullscreen layout - no fixed dimensions to prevent breaking on refresh */

@media (max-width: 1366px) {
  .antrian-display-container {
    padding: 16px;
  }

  .display-header {
    padding: 16px 24px;
  }

  .logo-circle {
    width: 64px;
    height: 64px;
  }

  .logo-circle .v-icon {
    font-size: 40px !important;
  }

  .hospital-name {
    font-size: 36px;
  }

  .display-subtitle {
    font-size: 16px;
  }

  .time-large {
    font-size: 48px;
  }

  .date-small {
    font-size: 14px;
  }

  .hero-call-section {
    padding: 24px;
  }

  .call-label {
    font-size: 24px;
  }

  .call-number {
    font-size: 100px;
  }

  .call-loket {
    font-size: 28px;
  }

  .lokets-grid {
    gap: 12px;
    /* grid-template-columns is set dynamically via :style binding */
  }

  .loket-name {
    font-size: 20px;
  }

  .ticket-number {
    font-size: 28px;
  }

  .footer-stats-bar {
    padding: 16px 32px;
  }

  .stat-icon {
    width: 56px;
    height: 56px;
  }

  .stat-icon .v-icon {
    font-size: 28px !important;
  }

  .stat-value {
    font-size: 36px;
  }

  .stat-label {
    font-size: 13px;
  }

  .stat-divider {
    height: 50px;
  }

  .footer-message {
    font-size: 18px;
  }
}

@media (max-width: 1024px) {
  .display-header {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }

  .header-left {
    flex-direction: column;
    gap: 12px;
  }

  .datetime-display {
    text-align: center;
  }

  .footer-stats-bar {
    flex-direction: column;
    gap: 16px;
  }

  .stat-divider {
    display: none;
  }

  .footer-message {
    text-align: center;
    justify-content: center;
  }
}

@media (max-width: 960px) {
  .lokets-grid {
    gap: 12px;
    /* grid-template-columns is set dynamically via :style binding */
  }
  
  .ticket-number {
    font-size: 20px;
    color: #3556AE;
  }
  
  .ticket-card {
    min-height: 70px;
    padding: 10px;
  }
}

@media (min-width: 961px) and (max-width: 1400px) {
  .lokets-grid {
    gap: 12px;
    /* grid-template-columns is set dynamically via :style binding */
  }
}

@media (min-width: 1401px) and (max-width: 1919px) {
  .lokets-grid {
    gap: 14px;
    /* grid-template-columns is set dynamically via :style binding */
  }
}

/* Fixed layout for 1920x1080 and above */
@media (min-width: 1920px) {
  .lokets-grid {
    gap: 16px;
    /* grid-template-columns is set dynamically via :style binding */
  }
}

@media (max-width: 768px) {
  .hospital-name {
    font-size: 28px;
  }

  .time-large {
    font-size: 36px;
  }

  .loket-name {
    font-size: 18px;
  }

  .ticket-number {
    font-size: 20px;
    color: #3556AE;
  }
}

/* Prevent text selection */
* {
  user-select: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>

