/* Reset and Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --bg-card: #2d3748;
    --text-primary: #f7fafc;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --accent: #4299e1;
    --accent-light: #63b3ed;
    --accent-dark: #3182ce;
    --success: #48bb78;
    --success-light: #68d391;
    --warning: #ed8936;
    --danger: #fc8181;
    --border: #4a5568;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

html {
    font-size: 16px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* Header */
.header {
    background: var(--bg-secondary);
    padding: calc(16px + var(--safe-top)) 16px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 600px;
    margin: 0 auto;
}

.date-info h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.date-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.position-widget {
    background: var(--bg-tertiary);
    padding: 12px 16px;
    border-radius: var(--radius);
    text-align: center;
    min-width: 110px;
}

.position-label {
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.position-status {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--accent);
}

.position-timer {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.position-switch {
    margin-top: 8px;
    padding: 6px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.position-switch:hover {
    background: var(--accent-dark);
}

/* Navigation */
.nav {
    display: flex;
    background: var(--bg-secondary);
    padding: 8px 16px 12px;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.nav::-webkit-scrollbar {
    display: none;
}

.nav-btn {
    flex: 1;
    min-width: 70px;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-btn:hover {
    background: var(--border);
}

.nav-btn.active {
    background: var(--accent);
    color: white;
}

/* Main Content */
.main {
    flex: 1;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Routine Badge */
.routine-badge {
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    text-align: center;
}

.routine-type {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.routine-focus {
    font-size: 0.875rem;
    opacity: 0.9;
}

.routine-badge.routine-b {
    background: linear-gradient(135deg, #276749, var(--success));
}

/* Section Cards */
.section-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.section-header:hover {
    background: var(--bg-tertiary);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.section-icon {
    font-size: 1.25rem;
}

.section-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-duration {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.section-progress {
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.section-progress.complete {
    background: var(--success);
    color: white;
}

.section-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.section-body.open {
    max-height: 2000px;
}

/* Exercise Items */
.exercise-item {
    display: flex;
    align-items: flex-start;
    padding: 14px 16px;
    border-top: 1px solid var(--bg-tertiary);
    cursor: pointer;
    transition: all 0.2s;
}

.exercise-item:hover {
    background: rgba(255, 255, 255, 0.02);
}

.exercise-item.completed {
    opacity: 0.5;
}

.exercise-item.completed .exercise-name {
    text-decoration: line-through;
}

.exercise-item.static {
    cursor: default;
}

.exercise-checkbox {
    width: 22px;
    height: 22px;
    border: 2px solid var(--border);
    border-radius: 6px;
    margin-right: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-top: 1px;
}

.exercise-item.completed .exercise-checkbox {
    background: var(--success);
    border-color: var(--success);
}

.exercise-checkbox::after {
    content: '✓';
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    opacity: 0;
    transform: scale(0);
    transition: all 0.2s;
}

.exercise-item.completed .exercise-checkbox::after {
    opacity: 1;
    transform: scale(1);
}

.exercise-content {
    flex: 1;
    min-width: 0;
}

.exercise-name {
    font-weight: 500;
    margin-bottom: 2px;
}

.exercise-details {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.exercise-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 6px;
    padding-left: 36px;
    border-left: 2px solid var(--border);
    margin-left: 0;
}

.exercise-reps {
    font-size: 0.875rem;
    color: var(--accent);
    font-weight: 500;
    margin-left: 12px;
    white-space: nowrap;
}

/* Exercise Groups */
.exercise-group {
    padding: 12px 16px 4px;
    border-top: 1px solid var(--bg-tertiary);
}

.exercise-group-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 8px;
}

.exercise-group .exercise-item {
    border-top: none;
    padding: 10px 0;
}

.exercise-group .exercise-item:not(:last-child) {
    border-bottom: 1px solid var(--bg-tertiary);
}

/* Breaks Tab */
.breaks-hero {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    padding: 32px 24px;
    border-radius: var(--radius);
    text-align: center;
    margin-bottom: 16px;
}

.breaks-count {
    font-size: 4rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.breaks-label {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

.breaks-target {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.breaks-btn {
    margin-top: 20px;
    padding: 14px 32px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.breaks-btn:hover {
    background: var(--success-light);
    transform: translateY(-1px);
}

.breaks-btn:active {
    transform: translateY(0);
}

.breaks-btn-icon {
    font-size: 1.25rem;
}

/* Info Card */
.info-card {
    background: rgba(66, 153, 225, 0.1);
    border: 1px solid rgba(66, 153, 225, 0.2);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin: 8px 16px 16px;
}

.info-card p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.info-card p:last-child {
    margin-bottom: 0;
}

.info-card strong {
    color: var(--accent);
}

.info-warning {
    color: var(--warning) !important;
    margin-top: 12px !important;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* History List */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-top: 1px solid var(--bg-tertiary);
}

.history-item:first-child {
    border-top: none;
}

.history-date {
    font-size: 0.875rem;
}

.history-date small {
    color: var(--text-muted);
    display: block;
    font-size: 0.75rem;
}

.history-badges {
    display: flex;
    gap: 6px;
}

.history-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.6875rem;
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.history-badge.done {
    background: var(--success);
    color: white;
}

.history-badge.partial {
    background: var(--warning);
    color: white;
}

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

/* Settings */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-top: 1px solid var(--bg-tertiary);
}

.setting-row:first-child {
    border-top: none;
}

.setting-label {
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.setting-input-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.setting-input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 0.9375rem;
    width: 70px;
    text-align: center;
}

.setting-input.time {
    width: 110px;
}

.setting-input:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-unit {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.setting-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    transition: 0.3s;
    border-radius: 28px;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
    background: var(--success);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

/* Buttons */
.btn {
    display: block;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.btn:first-child {
    margin-top: 0;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

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

/* App Info */
.app-info {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: calc(24px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.9375rem;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
}

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

/* Responsive */
@media (max-width: 400px) {
    .header-content {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .position-widget {
        width: 100%;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Desktop improvements */
@media (min-width: 768px) {
    .main {
        padding: 24px;
    }
    
    .section-card {
        margin-bottom: 16px;
    }
    
    .exercise-item {
        padding: 16px 20px;
    }
}
