* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --secondary: #764ba2;
    --success: #48bb78;
    --danger: #f56565;
    --bg: #f5f5f5;
    --card-bg: #fff;
    --text: #333;
    --text-muted: #888;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.header {
    text-align: center;
    padding: 15px 10px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.8rem;
    letter-spacing: 2px;
}

.header .stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 8px;
    font-size: 1.15rem;
}

.header .stat {
    display: flex;
    align-items: center;
    gap: 5px;
}

.header .stat-num {
    font-weight: bold;
    font-size: 1.4rem;
}

/* Tabs */
.tabs {
    display: flex;
    background: linear-gradient(135deg, var(--primary-dark) 0%, #6b46c1 100%);
    flex-shrink: 0;
}

.tab {
    flex: 1;
    min-width: 0;
    padding: 12px 5px;
    text-align: center;
    color: rgba(255,255,255,0.7);
    font-size: 1.05rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}

.tab:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.tab.active {
    color: #fff;
    background: rgba(255,255,255,0.2);
    border-bottom-color: #ffd700;
}

.tab .day-short { display: block; }
.tab .day-full { display: none; }

@media (min-width: 400px) {
    .tab {
        font-size: 1.15rem;
        padding: 14px 8px;
    }
    .tab .day-short { display: none; }
    .tab .day-full { display: block; }
}

/* Main content */
.main-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.view {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.view.active {
    display: flex;
}

/* Schedule view */
#schedule-content {
    flex: 1;
    overflow-y: auto;
    background: var(--card-bg);
}

.time-slot {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #eee;
    gap: 10px;
}

.time-slot.checked-in {
    background: linear-gradient(90deg, rgba(72, 187, 120, 0.1) 0%, transparent 100%);
}

.time {
    font-weight: bold;
    color: var(--text);
    font-size: 1.25rem;
    min-width: 60px;
}

.class-name {
    flex: 1;
    color: #444;
    font-size: 1.25rem;
}

.class-name.empty {
    color: #ccc;
    font-style: italic;
}

.checkin-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: white;
    color: var(--primary);
    font-size: 1.4rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkin-btn:hover {
    background: var(--primary);
    color: white;
}

.checkin-btn.checked {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

/* History view */
#history-view {
    background: var(--card-bg);
}

#history-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state p {
    margin: 10px 0;
}

.history-month h3 {
    background: var(--bg);
    padding: 10px 12px;
    margin: 0 -10px;
    font-size: 1.2rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.history-item {
    display: flex;
    align-items: center;
    padding: 12px 5px;
    border-bottom: 1px solid #eee;
    gap: 10px;
}

.history-date {
    font-size: 1.1rem;
    color: var(--text-muted);
    min-width: 75px;
}

.history-class {
    flex: 1;
    font-size: 1.2rem;
}

.history-time {
    font-size: 1.15rem;
    color: var(--text-muted);
}

.delete-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #fee;
    color: var(--danger);
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-btn:hover {
    background: var(--danger);
    color: white;
}

/* Export buttons */
.export-section {
    padding: 10px;
    background: var(--bg);
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-shrink: 0;
    border-bottom: 1px solid #ddd;
}

.export-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    background: var(--primary);
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.export-btn:hover {
    background: var(--primary-dark);
}

.import-btn {
    cursor: pointer;
}

/* Bottom navigation */
.bottom-nav {
    display: flex;
    background: white;
    border-top: 1px solid #ddd;
    flex-shrink: 0;
}

.nav-item {
    flex: 1;
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 1.05rem;
    cursor: pointer;
    border: none;
    background: none;
    transition: all 0.2s;
}

.nav-item .icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 3px;
}

.nav-item.active {
    color: var(--primary);
}

/* Footer */
.footer {
    padding: 10px;
    background: #f0f0f0;
    text-align: center;
    font-size: 1.05rem;
    color: #666;
    border-top: 1px solid #ddd;
    flex-shrink: 0;
}

.footer a {
    color: #333;
    text-decoration: none;
    margin: 0 6px;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: white;
    padding: 14px 28px;
    border-radius: 25px;
    font-size: 1.1rem;
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Desktop styles */
@media (min-width: 768px) {
    body {
        max-width: 500px;
        margin: 0 auto;
        box-shadow: 0 0 30px rgba(0,0,0,0.1);
    }
}

/* Safe area for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Active Workout Banner */
.active-workout-banner {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 15px;
    background: linear-gradient(90deg, #48bb78 0%, #38a169 100%);
    color: white;
    font-size: 1.2rem;
    flex-shrink: 0;
    animation: pulse 2s infinite;
}

.active-workout-banner.active {
    display: flex;
}

.banner-icon {
    font-size: 1.4rem;
}

.banner-time {
    font-weight: bold;
    font-size: 1.3rem;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

/* Free Workout Card */
.free-workout-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    margin: 10px;
    background: linear-gradient(135deg, #f6f8fb 0%, #e9ecef 100%);
    border-radius: 12px;
    border: 2px dashed var(--primary);
}

.free-workout-card.active {
    background: linear-gradient(135deg, #e6ffed 0%, #c6f6d5 100%);
    border: 2px solid var(--success);
}

.free-workout-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.free-workout-info .emoji {
    font-size: 1.8rem;
}

.free-workout-info .title {
    font-weight: 600;
    color: var(--text);
    font-size: 1.2rem;
}

.free-workout-info .timer {
    font-weight: bold;
    color: var(--success);
    background: white;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 1.2rem;
}

.free-workout-btn {
    padding: 12px 18px;
    border: none;
    border-radius: 8px;
    font-size: 1.15rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.free-workout-btn.checkin {
    background: var(--primary);
    color: white;
}

.free-workout-btn.checkin:hover {
    background: var(--primary-dark);
}

.free-workout-btn.checkout {
    background: var(--danger);
    color: white;
}

.free-workout-btn.checkout:hover {
    background: #e53e3e;
}

/* History Summary */
.history-summary {
    display: flex;
    gap: 10px;
    padding: 15px 10px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    margin: -10px -10px 10px -10px;
    border-radius: 0;
}

.summary-item {
    flex: 1;
    text-align: center;
    color: white;
}

.summary-label {
    display: block;
    font-size: 1rem;
    opacity: 0.8;
    margin-bottom: 4px;
}

.summary-value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
}

/* History item for free workout */
.history-item.free-workout {
    background: linear-gradient(90deg, rgba(72, 187, 120, 0.08) 0%, transparent 100%);
}

.history-duration {
    display: inline-block;
    background: var(--success);
    color: white;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 1.05rem;
    margin-left: 6px;
}

.auto-badge {
    display: inline-block;
    background: #fbd38d;
    color: #744210;
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 0.95rem;
    margin-left: 4px;
    text-transform: uppercase;
}

/* Duration Dialog */
.dialog-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.dialog-overlay.active {
    display: flex;
}

.dialog {
    background: white;
    padding: 25px;
    border-radius: 16px;
    text-align: center;
    min-width: 280px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.dialog h3 {
    margin-bottom: 15px;
    color: var(--text);
    font-size: 1.3rem;
}

.dialog-duration {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--primary);
    margin: 20px 0;
}

.dialog-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 20px;
}

.dialog-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: white;
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.dialog-btn:hover, .dialog-btn:active {
    background: var(--primary);
    color: white;
}

.dialog-close {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
}

.dialog-close:hover {
    background: var(--primary-dark);
}
