:root {
    /* Light Mode (Apple style) */
    --bg-color: #f5f5f7;
    --surface-color: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --border-color: #e5e5ea;
    
    --primary-color: #0071e3;
    --primary-hover: #0077ed;
    --danger-color: #ff3b30;
    
    /* Slot Colors */
    --slot-free: #e8f5e9;
    --slot-free-text: #2e7d32;
    --slot-free-hover: #c8e6c9;
    
    --slot-taken: #ffebee;
    --slot-taken-text: #c62828;
    
    --slot-fixed: #f5f5f5;
    --slot-fixed-text: #616161;
    
    --slot-mine: #e3f2fd;
    --slot-mine-text: #1565c0;
    
    --shadow: 0 4px 6px rgba(0,0,0,0.05), 0 1px 3px rgba(0,0,0,0.03);
    --border-radius: 12px;
    --transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

[data-theme="dark"] {
    --bg-color: #000000;
    --surface-color: #1c1c1e;
    --text-primary: #f5f5f7;
    --text-secondary: #86868b;
    --border-color: #38383a;
    
    --primary-color: #0a84ff;
    --primary-hover: #0071e3;
    
    --slot-free: #1b3320;
    --slot-free-text: #81c784;
    --slot-free-hover: #2e4d34;
    
    --slot-taken: #3a1d1d;
    --slot-taken-text: #e57373;
    
    --slot-fixed: #2c2c2e;
    --slot-fixed-text: #a1a1a6;
    
    --slot-mine: #1a365d;
    --slot-mine-text: #90caf9;
    
    --shadow: 0 4px 6px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Rubik', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* Header */
.app-header {
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}
.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-content h1 { font-size: 1.25rem; font-weight: 600; }
.header-controls { display: flex; align-items: center; gap: 15px; }

/* Buttons & Inputs */
.primary-btn {
    background-color: var(--primary-color); color: white;
    border: none; border-radius: 8px; padding: 10px 20px;
    font-size: 1rem; font-family: inherit; font-weight: 500;
    cursor: pointer; transition: var(--transition);
}
.primary-btn:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
.secondary-btn {
    background-color: transparent; color: var(--text-primary);
    border: 1px solid var(--border-color); border-radius: 8px;
    padding: 10px 20px; cursor: pointer; transition: var(--transition);
}
.secondary-btn:hover { background-color: var(--bg-color); }
.danger-btn {
    background-color: var(--danger-color); color: white;
    border: none; border-radius: 8px; padding: 10px 20px; cursor: pointer;
}
.icon-btn {
    background: none; border: none; font-size: 1.25rem;
    cursor: pointer; color: var(--text-primary); padding: 5px;
    border-radius: 50%; transition: var(--transition);
}
.icon-btn:hover { background-color: var(--border-color); }

/* Login Screen */
.screen {
    min-height: calc(100vh - 60px);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.login-card {
    background-color: var(--surface-color); padding: 40px;
    border-radius: var(--border-radius); box-shadow: var(--shadow);
    width: 100%; max-width: 400px; text-align: center;
}
.login-card input {
    width: 100%; padding: 12px; margin: 20px 0;
    border: 1px solid var(--border-color); border-radius: 8px;
    background-color: var(--bg-color); color: var(--text-primary);
    font-size: 1.1rem; text-align: center; font-family: inherit;
}
.login-card input:focus { outline: 2px solid var(--primary-color); border-color: transparent; }
.login-card button { width: 100%; }

.error-msg { color: var(--danger-color); margin-top: 15px; font-size: 0.9rem; }

/* Schedule Screen */
#schedule-screen { justify-content: flex-start; padding: 20px; max-width: 1400px; margin: 0 auto; }
.toolbar {
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; margin-bottom: 20px; flex-wrap: wrap; gap: 15px;
}
.schedule-controls { display: flex; align-items: center; gap: 15px; }
.current-week-display h2 { font-size: 1.2rem; font-weight: 500; }
.hidden-date-picker {
    position: absolute; opacity: 0; width: 0; height: 0;
}

/* Toggle */
.toggle-switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: relative; width: 44px; height: 24px; background-color: var(--border-color);
    border-radius: 24px; transition: .4s; margin-left: 10px;
}
.slider:before {
    position: absolute; content: ""; height: 18px; width: 18px;
    left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: .4s;
}
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(20px); }
.toggle-label { font-size: 0.9rem; color: var(--text-secondary); }

/* Grid */
.schedule-container {
    width: 100%; background: var(--surface-color);
    border-radius: var(--border-radius); box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}
#schedule-grid { 
    max-height: 70vh; /* Allow internal vertical scroll */
    overflow: auto; 
}
.grid-header {
    display: flex; border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-color); 
    position: sticky; top: 0; z-index: 20;
}
.header-cell {
    flex: 1; min-width: 120px; padding: 15px 10px; text-align: center;
    font-weight: 600; color: var(--text-secondary); border-left: 1px solid var(--border-color);
}
.header-cell.time-col { 
    min-width: 80px; flex: 0 0 80px; 
    position: sticky; right: 0; z-index: 21; /* Stick above other columns */
    background-color: var(--bg-color);
}
.grid-header .header-cell:last-child { border-left: none; }

.grid-row { display: flex; border-bottom: 1px solid var(--border-color); position: relative; }
.grid-row:last-child { border-bottom: none; }
.time-cell {
    flex: 0 0 80px; padding: 15px 10px; text-align: center;
    font-weight: 500; color: var(--text-secondary);
    border-left: 1px solid var(--border-color); 
    background-color: var(--bg-color);
    position: sticky; right: 0; z-index: 10;
}
.slot-cell {
    flex: 1; min-width: 120px; border-left: 1px solid var(--border-color);
    padding: 5px; position: relative; cursor: pointer; transition: background-color 0.2s;
}
.slot-cell:last-child { border-left: none; }

/* Slot states */
.slot-content {
    height: 100%; min-height: 50px; border-radius: 6px; padding: 8px;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center; font-size: 0.9rem; transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.slot-cell:active .slot-content { transform: scale(0.95); }

.slot-free .slot-content { background-color: var(--slot-free); color: var(--slot-free-text); border: 1px dashed rgba(46, 125, 50, 0.3); }
.slot-free:hover .slot-content { background-color: var(--slot-free-hover); }

.slot-taken .slot-content { background-color: var(--slot-taken); color: var(--slot-taken-text); }
.slot-fixed .slot-content { background-color: var(--slot-fixed); color: var(--slot-fixed-text); cursor: not-allowed;}
.slot-mine .slot-content { background-color: var(--slot-mine); color: var(--slot-mine-text); border: 1px solid rgba(21, 101, 192, 0.3); }

/* Live Time Line */
.live-time-indicator {
    position: absolute;
    width: 100%;
    height: 2px;
    background-color: var(--danger-color);
    z-index: 5;
    pointer-events: none;
    box-shadow: 0 0 4px rgba(255,59,48,0.5);
}
.live-time-indicator::before {
    content: ''; position: absolute; right: -4px; top: -3px;
    width: 8px; height: 8px; border-radius: 50%; background-color: var(--danger-color);
}

/* Modals */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
    display: flex; justify-content: center; align-items: center; z-index: 1000;
}
.modal-content {
    background: var(--surface-color); padding: 25px; border-radius: 16px;
    width: 90%; max-width: 400px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
    transform: translateY(0); transition: var(--transition);
}
.modal.hidden { opacity: 0; pointer-events: none; }
.modal.hidden .modal-content { transform: translateY(20px); }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;}
.modal-header h3 { margin: 0; }

.modal input[type="text"] {
    width: 100%; padding: 12px; margin: 15px 0;
    border: 1px solid var(--border-color); border-radius: 8px;
    background-color: var(--bg-color); color: var(--text-primary); font-family: inherit;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px;}
.modal-actions.full-width { flex-direction: column; gap: 10px; }
.modal-actions.full-width button { width: 100%; }

/* Owner Info inside modal */
.owner-info { display: flex; align-items: center; gap: 15px; margin-bottom: 20px; }
.owner-avatar {
    width: 50px; height: 50px; border-radius: 50%; background: var(--primary-color);
    color: white; display: flex; justify-content: center; align-items: center;
    font-size: 1.5rem; font-weight: bold;
}
.owner-note { color: var(--text-secondary); font-size: 0.9rem; margin-top: 5px; }

/* Contact Actions */
.contact-actions { display: flex; gap: 10px; margin-bottom: 20px; }
.action-btn {
    flex: 1; padding: 10px; border-radius: 8px; text-align: center;
    text-decoration: none; font-size: 0.9rem; font-weight: 500; color: white;
}
.whatsapp-btn { background-color: #25D366; }
.phone-btn { background-color: #007aff; }
.email-btn { background-color: #ff9500; }

/* Toast */
.toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    background: #323232; color: white; padding: 12px 24px;
    border-radius: 24px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex; align-items: center; gap: 15px; z-index: 2000;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
}
.toast.hidden { transform: translate(-50%, 100px); opacity: 0; }
.undo-btn {
    background: transparent; border: none; color: #90caf9;
    font-weight: 600; cursor: pointer; text-transform: uppercase;
}

/* Skeletons */
.skeletons { padding: 20px; }
.skeleton-header { height: 40px; background: var(--border-color); border-radius: 8px; margin-bottom: 10px; animation: pulse 1.5s infinite; }
.skeleton-grid { height: 300px; background: var(--border-color); border-radius: 8px; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 0.8; } 100% { opacity: 0.5; } }

/* Settings Screen */
.settings-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;}
.settings-card {
    background-color: var(--surface-color); padding: 20px;
    border-radius: var(--border-radius); box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.users-table { width: 100%; border-collapse: collapse; margin-top: 15px; }
.users-table th, .users-table td { 
    text-align: right; padding: 12px; border-bottom: 1px solid var(--border-color); 
}
.users-table th { color: var(--text-secondary); font-weight: 600; }
.role-badge { 
    padding: 4px 8px; border-radius: 4px; font-size: 0.85rem; font-weight: 500;
}
.role-super_admin { background: #ffebee; color: #c62828; }
.role-admin { background: #fff3e0; color: #e65100; }
.role-coordinator { background: #e8f5e9; color: #2e7d32; }

/* Utils */
.hidden { display: none !important; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--primary-color);
    color: white; display: inline-flex; justify-content: center; align-items: center;
    font-size: 0.9rem; font-weight: bold;
}
#user-info { display: flex; align-items: center; gap: 10px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-secondary); }
.empty-icon { font-size: 3rem; margin-bottom: 10px; }

@media (max-width: 768px) {
    .hide-mobile { display: none; }
    .header-content { padding: 10px; }
    .slot-content { font-size: 0.8rem; padding: 4px; min-height: 60px; /* Touch target size */ }
    .header-cell, .slot-cell { min-width: 100px; }
    #schedule-grid { scroll-snap-type: x mandatory; }
    .slot-cell { scroll-snap-align: start; }
}
