/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f8fafc;
}

/* Safe area support for iOS */
body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

#app {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* Patient Selection Grid */
.patient-grid-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 24px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

.title {
    font-size: 2rem;
    font-weight: 700;
    color: #0c4a6e;
    margin-bottom: 8px;
    text-align: center;
}

.subtitle {
    font-size: 1rem;
    color: #64748b;
    margin-bottom: 32px;
    text-align: center;
}

.patient-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    max-width: 600px;
    width: 100%;
}

/* Patient Card */
.patient-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 2px solid transparent;
}

.patient-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

.patient-card:active {
    transform: scale(0.98);
}

.patient-card.selected {
    border-color: #0ea5e9;
    background: #f0f9ff;
}

.patient-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    margin-bottom: 12px;
    object-fit: cover;
}

.patient-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 4px;
}

.patient-details {
    font-size: 0.875rem;
    color: #64748b;
    line-height: 1.4;
}

.patient-procedure {
    font-size: 0.75rem;
    color: #0ea5e9;
    background: #e0f2fe;
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 8px;
}

/* Demo Container */
.demo-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    z-index: 100;
}

.demo-container.hidden {
    display: none;
}

/* app.js toggles this class on the picker too. Without a rule the picker stayed
   in the layout behind the demo overlay, still scrollable and focusable. */
.patient-grid-container.hidden {
    display: none;
}

.app-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: white;
}

/* Back Button */
.back-button {
    position: fixed;
    top: env(safe-area-inset-top, 16px);
    left: env(safe-area-inset-left, 16px);
    z-index: 101;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 16px;
}

.back-button:hover {
    background: rgba(0, 0, 0, 0.8);
}

.back-button svg {
    width: 16px;
    height: 16px;
}

/* Loading State */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e2e8f0;
    border-top-color: #0ea5e9;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    margin-top: 16px;
    color: #64748b;
    font-size: 1rem;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .patient-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .patient-card {
        flex-direction: row;
        text-align: left;
        padding: 16px;
    }

    .patient-avatar {
        width: 60px;
        height: 60px;
        margin-bottom: 0;
        margin-right: 16px;
        flex-shrink: 0;
    }

    .patient-info {
        flex: 1;
    }

    .title {
        font-size: 1.5rem;
    }
}

/* iPad landscape */
@media (min-width: 768px) and (orientation: landscape) {
    .patient-grid {
        grid-template-columns: repeat(4, 1fr);
        max-width: 900px;
    }
}
