:root {
    --primary: #2563eb;
    --primary-gradient: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --primary-light: #eff6ff;
    --primary-border: #bfdbfe;
    --primary-dark: #1e40af;
    
    --success: #16a34a;
    --success-light: #f0fdf4;
    --success-border: #bbf7d0;
    
    --notice-bg: #fff1f2;
    --notice-border: #fecdd3;
    --notice-text: #be123c;
    --notice-gradient: linear-gradient(135deg, #fff1f2 0%, #ffe4e6 100%);
    
    --delete-bg: #f8fafc;
    --delete-border: #cbd5e1;
    --delete-text: #64748b;
    
    --bg-app: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-sub: #334155;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-card: 0 2px 8px -2px rgba(15, 23, 42, 0.06), 0 1px 4px -1px rgba(15, 23, 42, 0.04);
    --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    height: 100dvh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 540px;
    background: var(--bg-app);
    position: relative;
    overflow: hidden;
}

/* =========================================================================
   📱 1. COMPACT STREAMLINED HEADER
   ========================================================================= */
/* 🌟 Ultra-Compact Header */
.app-header {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.header-control-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.control-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 7px 10px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    outline: none;
}

.control-btn:hover, .control-btn:active {
    background: var(--primary-light);
    border-color: var(--primary-border);
    color: var(--primary-dark);
}

.date-control-btn {
    position: relative;
    flex: 1.1;
    overflow: hidden;
}

.date-control-btn input[type="date"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.room-control-btn {
    flex: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
}

.caret-icon {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-left: auto;
}

.modal-chip-btn {
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-weight: 700;
    background: #f8fafc;
    border: 1px solid var(--border);
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.15s;
}

.modal-chip-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.modal-chip-btn.room-active {
    background: #0f172a;
    color: white;
    border-color: #0f172a;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.25);
}

.btn-icon {
    background: var(--bg-app);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.btn-icon:hover, .btn-icon:active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-border);
}

/* Search Bar */
.search-row {
    position: relative;
    width: 100%;
}

.search-input {
    width: 100%;
    height: 34px;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0 30px 0 32px;
    font-size: 0.82rem;
    color: var(--text-main);
    outline: none;
    transition: all 0.2s;
}

.search-input:focus {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
    pointer-events: none;
}

.search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    display: none;
}

/* =========================================================================
   🔬 2. MODALITY & ROOM TABS (1 Modality, 1 Room)
   ========================================================================= */
.filter-selection-area {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 6px 12px 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-label-inline {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    width: 65px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.modality-scroll-bar, .room-scroll-bar {
    display: flex;
    gap: 5px;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
}
.modality-scroll-bar::-webkit-scrollbar, .room-scroll-bar::-webkit-scrollbar { display: none; }

.modality-chip, .room-chip {
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 700;
    background: var(--bg-app);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.modality-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 5px rgba(37, 99, 235, 0.25);
}

.room-chip.active {
    background: #0f172a;
    color: white;
    border-color: #0f172a;
    box-shadow: 0 2px 5px rgba(15, 23, 42, 0.25);
}

/* =========================================================================
   📊 3. SUMMARY COUNTERS (STATUS PILLS)
   ========================================================================= */
.summary-bar {
    display: flex;
    gap: 5px;
    overflow-x: auto;
    padding: 6px 12px 6px 12px;
    scrollbar-width: none;
    flex-shrink: 0;
    background: #f1f5f9;
}
.summary-bar::-webkit-scrollbar { display: none; }

.summary-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    flex-shrink: 0;
}

.summary-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.summary-count {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-main);
}

.summary-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* =========================================================================
   📋 4. ULTRA-COMPACT APPOINTMENT CARD (Maximum Density)
   ========================================================================= */
.appointment-stream {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px 40px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
}

.app-card {
    background: white;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    padding: 6px 10px 6px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    transition: transform 0.1s, box-shadow 0.1s;
}

.app-card:active {
    transform: scale(0.99);
}

.app-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3.5px;
    background: var(--primary);
}

.app-card.status-appointed::before { background: var(--primary); }
.app-card.status-delete {
    opacity: 0.65;
    background: #f8fafc;
}
.app-card.status-delete::before { background: var(--slate); }

/* 🌟 Notice Card (ธีมสีน้ำเงินฟ้า กระชับ) */
.app-card.card-notice {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
    box-shadow: 0 1px 3px rgba(2, 132, 199, 0.06);
    padding: 5px 10px 5px 12px;
    gap: 2px;
}
.app-card.card-notice::before {
    background: #0284c7 !important;
    width: 3.5px;
}

.notice-banner {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    font-weight: 800;
    color: #0369a1;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    padding: 1px 6px;
    border-radius: 4px;
    width: fit-content;
}

.notice-title {
    font-size: 0.9rem;
    font-weight: 800;
    color: #0c4a6e;
    line-height: 1.25;
}

/* Card Header: ⏰ เวลานัดหมาย + Duration & HN / Status */
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.time-duration-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--primary-light);
    border: 1px solid var(--primary-border);
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--primary-dark);
}

.time-val {
    font-size: 0.86rem;
    font-weight: 800;
    letter-spacing: -0.2px;
}

.duration-val {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--primary);
    background: rgba(255, 255, 255, 0.7);
    padding: 0 4px;
    border-radius: 4px;
}

.card-badges {
    display: flex;
    align-items: center;
    gap: 5px;
}

.patient-hn-tag {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    font-family: monospace;
    white-space: nowrap;
}

.badge-status {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 3px;
}
.status-pill-appointed { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.status-pill-delete { background: #e2e8f0; color: #475569; border: 1px solid #cbd5e1; }

/* Card Patient Row: 👤 ชื่อนามสกุลภาษาไทย + เพศ/อายุ ในบรรทัดเดียว */
.card-patient-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
    line-height: 1.25;
}

.patient-thai-name {
    font-size: 0.94rem;
    font-weight: 800;
    color: var(--text-main);
}

.patient-demographics-inline {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Card Procedure: 🩻 ชื่อการตรวจ บรรทัดเดียว */
.card-procedure-box {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 1px;
}

.card-procedure-box i {
    color: var(--primary);
    font-size: 0.75rem;
    flex-shrink: 0;
}

.procedure-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-sub);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.meta-phone {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: #15803d;
    text-decoration: none;
    font-size: 0.73rem;
    font-weight: 700;
    background: #dcfce7;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid #bbf7d0;
}

.meta-phone-empty {
    font-size: 0.72rem;
    color: #94a3b8;
    background: #f8fafc;
    padding: 2px 5px;
    border-radius: var(--radius-sm);
    border: 1px solid #e2e8f0;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
    gap: 10px;
}
.empty-state i {
    font-size: 3rem;
    color: #cbd5e1;
}

/* =========================================================================
   📱 5. READ-ONLY MODAL BOTTOM SHEET (PACS Button Removed)
   ========================================================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.modal-sheet {
    background: white;
    width: 100%;
    max-width: 540px;
    max-height: 85dvh;
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-modal);
    animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
}

.modal-title {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-body {
    padding: 14px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.patient-highlight-box {
    background: var(--primary-light);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.patient-highlight-box.notice-box {
    background: #fff1f2;
    border-color: #fecdd3;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.info-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}

.info-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
}

.info-value {
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--text-main);
    margin-top: 2px;
}

.barcodes-container {
    display: flex;
    justify-content: space-around;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
}

.barcode-block {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: #f8fafc;
}

.btn-main {
    flex: 1;
    height: 42px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.92rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    text-decoration: none;
}

.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
}
