:root {
    --primary-color: #dc2626;
    --primary-dark: #b91c1c;
    --primary-light: #fef2f2;
    --success-color: #22c55e;
    --success-light: #dcfce7;
    --error-color: #ef4444;
    --error-light: #fee2e2;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --light-bg: #f8fafc;
    --white: #ffffff;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --superset-color-1: #3b82f6;
    --superset-color-2: #8b5cf6;
    --superset-color-3: #f59e0b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

body {
    background-color: var(--light-bg);
    color: var(--text-color);
    line-height: 1.6;
    -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* Auth */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
    overflow: hidden;
}

.auth-tabs {
    display: flex;
    background: var(--primary-dark);
}

.auth-tab {
    flex: 1;
    padding: 1rem;
    background: none;
    border: none;
    color: var(--white);
    font-weight: 600;
    cursor: pointer;
}

.auth-tab.active { background: var(--primary-color); }

.auth-form {
    padding: 1.5rem;
    display: none;
}

.auth-form.active { display: block; }

.auth-form h2 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
    text-align: center;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--white);
    color: var(--text-color);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.error-message {
    color: var(--error-color);
    margin: 0.5rem 0;
    font-size: 0.9rem;
    min-height: 1.5rem;
}

.auth-form button[type="submit"] {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.5rem;
}

.auth-form button[type="submit"]:hover { background: var(--primary-dark); }

/* App Layout */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    background: var(--white);
    min-height: 100vh;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.app-interface {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: var(--white);
    padding: 1rem 1rem 0.75rem;
    text-align: center;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

#username-display { font-weight: 600; opacity: 0.9; }

.logout-btn {
    background: rgba(255,255,255,0.15);
    color: var(--white);
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    cursor: pointer;
}

.logout-btn:hover { background: rgba(255,255,255,0.25); }

header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

nav {
    display: flex;
    background: rgba(0,0,0,0.15);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    gap: 0.25rem;
}

.nav-btn {
    flex: 1;
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    padding: 0.5rem 0.25rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
}

.nav-btn:hover { color: var(--white); background: rgba(255,255,255,0.1); }

.nav-btn.active {
    background: var(--white);
    color: var(--primary-dark);
    font-weight: 600;
}

main {
    flex: 1;
    padding: 1rem;
    padding-bottom: 5rem;
}

.view { display: none; }
.view.active { display: block; }

h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
    font-weight: 600;
}

/* Date Selector */
.date-selector {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, var(--primary-light), #fff5f5);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(220,38,38,0.1);
}

.date-selector button {
    background: var(--white);
    border: none;
    font-size: 1rem;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.date-selector button:hover {
    background: var(--primary-color);
    color: var(--white);
}

#current-date {
    font-weight: 600;
    color: var(--primary-dark);
    font-size: 0.95rem;
    text-align: center;
    flex: 1;
}

/* Workout Type Toggle */
.workout-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.workout-type-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--white);
    cursor: pointer;
    transition: all 0.2s;
}

.workout-type-btn:hover { border-color: var(--primary-color); }

.workout-type-btn.active {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.workout-letter {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-color);
    line-height: 1;
}

.workout-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    text-align: center;
}

.workout-type-btn.active .workout-label { color: var(--primary-dark); }

/* Exercise Form */
.exercise-form { margin-bottom: 1rem; }

.exercise-group {
    margin-bottom: 0.75rem;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.exercise-group.superset {
    border-left: 4px solid var(--superset-color-1);
}

.exercise-group.superset-2 { border-left-color: var(--superset-color-2); }
.exercise-group.superset-3 { border-left-color: var(--superset-color-3); }

.superset-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    padding: 0.4rem 0.75rem;
    background: #f1f5f9;
    color: var(--text-muted);
}

.exercise-card {
    padding: 0.75rem;
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
}

.exercise-card:last-child { border-bottom: none; }

.exercise-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.exercise-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.weight-unit-badge {
    font-size: 0.7rem;
    background: #f1f5f9;
    color: var(--text-muted);
    padding: 0.15rem 0.5rem;
    border-radius: 100px;
    font-weight: 500;
}

.exercise-inputs {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.exercise-inputs .input-group {
    flex: 1;
}

.exercise-inputs .input-group label {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.2rem;
}

.exercise-inputs input {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    text-align: center;
    min-height: 44px;
}

.exercise-inputs input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.exercise-inputs .notes-input {
    flex: 1.5;
}

.exercise-inputs .notes-input input {
    text-align: left;
    font-size: 0.85rem;
}

.last-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    font-style: italic;
}

/* Session Meta */
.session-meta {
    background: var(--light-bg);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.session-meta .form-group:last-child { margin-bottom: 0; }

/* Save Bar */
.save-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    padding: 0.75rem 1rem;
    background: var(--white);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.save-btn {
    width: 100%;
    padding: 0.85rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 50px;
    transition: all 0.2s;
}

.save-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.save-btn:active { transform: translateY(0); }

.save-btn.saving {
    opacity: 0.7;
    pointer-events: none;
}

.save-btn.saved {
    background: linear-gradient(135deg, var(--success-color), #16a34a);
}

/* History */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-card {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.history-info .history-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.history-actions {
    display: flex;
    gap: 0.5rem;
}

.delete-btn {
    background: var(--error-light);
    color: var(--error-color);
    border: none;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}

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

.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.pagination button {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--white);
    cursor: pointer;
    font-weight: 500;
}

.pagination button:hover { border-color: var(--primary-color); }
.pagination button:disabled { opacity: 0.5; cursor: default; }

/* Trends */
.trends-controls {
    margin-bottom: 1rem;
}

.time-range-btns {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.range-btn {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--white);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
}

.range-btn:hover { border-color: var(--primary-color); }

.range-btn.active {
    background: var(--primary-color);
    color: var(--white);
    border-color: var(--primary-color);
}

.chart-container {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
    min-height: 250px;
}

.analyze-btn {
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 1rem;
}

.analyze-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.analyze-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

.analysis-result {
    background: linear-gradient(135deg, #faf5ff, #f5f3ff);
    border: 1px solid #e9d5ff;
    border-radius: var(--radius-md);
    padding: 1rem;
    font-size: 0.9rem;
    line-height: 1.7;
    white-space: pre-wrap;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: var(--white);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Responsive */
@media (max-width: 480px) {
    header h1 { font-size: 1.2rem; }
    .nav-btn { font-size: 0.8rem; padding: 0.4rem 0.2rem; }
    .workout-letter { font-size: 1.3rem; }
}
