<!-- Day Detail Panel Content -->
<div class="flex items-center justify-between mb-6">
    <h2 class="text-xl font-semibold text-gray-900 dark:text-white">{{ date_display }}</h2>
    <button onclick="closeDayPanel()" class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300">
        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
        </svg>
    </button>
</div>

<!-- Summary Stats -->
<div class="grid grid-cols-2 gap-3 mb-6">
    <div class="bg-green-50 dark:bg-green-900/20 rounded-lg p-3 text-center">
        <p class="text-2xl font-bold text-green-700 dark:text-green-300">{{ day_data.counts.available }}</p>
        <p class="text-xs text-green-600 dark:text-green-400">Available</p>
    </div>
    <div class="bg-blue-50 dark:bg-blue-900/20 rounded-lg p-3 text-center">
        <p class="text-2xl font-bold text-blue-700 dark:text-blue-300">{{ day_data.counts.reserved }}</p>
        <p class="text-xs text-blue-600 dark:text-blue-400">Reserved</p>
    </div>
    <div class="bg-yellow-50 dark:bg-yellow-900/20 rounded-lg p-3 text-center">
        <p class="text-2xl font-bold text-yellow-700 dark:text-yellow-300">{{ day_data.counts.expiring_soon }}</p>
        <p class="text-xs text-yellow-600 dark:text-yellow-400">Expiring Soon</p>
    </div>
    <div class="bg-red-50 dark:bg-red-900/20 rounded-lg p-3 text-center">
        <p class="text-2xl font-bold text-red-700 dark:text-red-300">{{ day_data.counts.expired }}</p>
        <p class="text-xs text-red-600 dark:text-red-400">Cal. Expired</p>
    </div>
</div>

<!-- Calibration Expiring TODAY - Important alert -->
{% if day_data.cal_expiring_today %}
<div class="mb-6 p-3 bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-800 rounded-lg">
    <h3 class="text-sm font-semibold text-red-700 dark:text-red-400 mb-2 flex items-center gap-2">
        <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
            <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
        </svg>
        Calibration Expires Today ({{ day_data.cal_expiring_today|length }})
    </h3>
    <div class="space-y-1">
        {% for unit in day_data.cal_expiring_today %}
        <div class="flex items-center justify-between p-2 bg-white dark:bg-gray-800 rounded text-sm">
            <a href="/unit/{{ unit.id }}" class="font-medium text-red-600 dark:text-red-400 hover:underline">
                {{ unit.id }}
            </a>
            <span class="text-red-500 text-xs">
                Last cal: {{ unit.last_calibrated }}
            </span>
        </div>
        {% endfor %}
    </div>
</div>
{% endif %}

<!-- Reservations on this date -->
{% if day_data.reservations %}
<div class="mb-6">
    <h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">Reservations</h3>
    {% for res in day_data.reservations %}
    <div class="reservation-bar mb-2" style="background-color: {{ res.color }}20; border-left: 4px solid {{ res.color }};">
        <div class="flex-1">
            <p class="font-medium text-gray-900 dark:text-white">{{ res.name }}</p>
            <p class="text-xs text-gray-500 dark:text-gray-400">
                {{ res.start_date }} - {{ res.end_date }}
            </p>
        </div>
        <div class="text-right">
            <p class="font-semibold text-gray-900 dark:text-white">
                {% if res.assignment_type == 'quantity' %}
                {{ res.assigned_count }}/{{ res.quantity_needed or '?' }}
                {% else %}
                {{ res.assigned_count }} units
                {% endif %}
            </p>
        </div>
    </div>
    {% endfor %}
</div>
{% endif %}

<!-- Available Units -->
{% if day_data.available_units %}
<div class="mb-6">
    <h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">
        Available Units ({{ day_data.available_units|length }})
    </h3>
    <div class="max-h-48 overflow-y-auto space-y-1">
        {% for unit in day_data.available_units %}
        <div class="flex items-center justify-between p-2 bg-gray-50 dark:bg-gray-700/50 rounded text-sm">
            <a href="/unit/{{ unit.id }}" class="font-medium text-blue-600 dark:text-blue-400 hover:underline">
                {{ unit.id }}
            </a>
            <span class="text-gray-500 dark:text-gray-400 text-xs">
                {% if unit.last_calibrated %}
                Cal: {{ unit.last_calibrated }}
                {% else %}
                No cal date
                {% endif %}
            </span>
        </div>
        {% endfor %}
    </div>
</div>
{% endif %}

<!-- Reserved Units -->
{% if day_data.reserved_units %}
<div class="mb-6">
    <h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">
        Reserved Units ({{ day_data.reserved_units|length }})
    </h3>
    <div class="max-h-48 overflow-y-auto space-y-1">
        {% for unit in day_data.reserved_units %}
        <div class="flex items-center justify-between p-2 bg-blue-50 dark:bg-blue-900/20 rounded text-sm">
            <a href="/unit/{{ unit.id }}" class="font-medium text-blue-600 dark:text-blue-400 hover:underline">
                {{ unit.id }}
            </a>
            <span class="text-blue-600 dark:text-blue-400 text-xs">
                {{ unit.reservation_name }}
            </span>
        </div>
        {% endfor %}
    </div>
</div>
{% endif %}

<!-- Calibration Expired -->
{% if day_data.expired_units %}
<div class="mb-6">
    <h3 class="text-sm font-semibold text-red-600 dark:text-red-400 mb-3">
        Calibration Expired ({{ day_data.expired_units|length }})
    </h3>
    <div class="max-h-48 overflow-y-auto space-y-1">
        {% for unit in day_data.expired_units %}
        <div class="flex items-center justify-between p-2 bg-red-50 dark:bg-red-900/20 rounded text-sm">
            <a href="/unit/{{ unit.id }}" class="font-medium text-red-600 dark:text-red-400 hover:underline">
                {{ unit.id }}
            </a>
            <span class="text-red-500 text-xs">
                Expired: {{ unit.expiry_date }}
            </span>
        </div>
        {% endfor %}
    </div>
</div>
{% endif %}

<!-- Needs Calibration -->
{% if day_data.needs_calibration_units %}
<div class="mb-6">
    <h3 class="text-sm font-semibold text-gray-600 dark:text-gray-400 mb-3">
        Needs Calibration Date ({{ day_data.needs_calibration_units|length }})
    </h3>
    <div class="max-h-32 overflow-y-auto space-y-1">
        {% for unit in day_data.needs_calibration_units %}
        <div class="flex items-center justify-between p-2 bg-gray-100 dark:bg-gray-700/50 rounded text-sm">
            <a href="/unit/{{ unit.id }}" class="font-medium text-gray-600 dark:text-gray-400 hover:underline">
                {{ unit.id }}
            </a>
            <span class="text-gray-400 text-xs">No cal date set</span>
        </div>
        {% endfor %}
    </div>
</div>
{% endif %}

<!-- Expiring Soon (informational) -->
{% if day_data.expiring_soon_units %}
<div class="mb-6">
    <h3 class="text-sm font-semibold text-yellow-600 dark:text-yellow-400 mb-3">
        Calibration Expiring Soon ({{ day_data.expiring_soon_units|length }})
    </h3>
    <div class="max-h-32 overflow-y-auto space-y-1">
        {% for unit in day_data.expiring_soon_units %}
        <div class="flex items-center justify-between p-2 bg-yellow-50 dark:bg-yellow-900/20 rounded text-sm">
            <a href="/unit/{{ unit.id }}" class="font-medium text-yellow-700 dark:text-yellow-400 hover:underline">
                {{ unit.id }}
            </a>
            <span class="text-yellow-600 text-xs">
                Expires: {{ unit.expiry_date }}
            </span>
        </div>
        {% endfor %}
    </div>
</div>
{% endif %}
