/* CSS Variables */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-panel: #1f2940;
    --bg-card: #243352;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent: #4ecca3;
    --accent-hover: #3db892;
    --accent-dim: rgba(78, 204, 163, 0.15);
    --orange: #f39c12;
    --orange-dim: rgba(243, 156, 18, 0.15);
    --red: #e74c3c;
    --red-dim: rgba(231, 76, 60, 0.15);
    --blue: #3498db;
    --blue-dim: rgba(52, 152, 219, 0.15);
    --purple: #9b59b6;
    --success: #2ecc71;
    --success-dim: rgba(46, 204, 113, 0.15);
    --border: rgba(255, 255, 255, 0.08);
    --shadow: rgba(0, 0, 0, 0.3);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header h1 {
    font-size: 1.5rem;
    color: #333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.back-button {
    background: linear-gradient(45deg, #4ecca3, #3db892);
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.back-button:hover {
    background: linear-gradient(45deg, #3db892, #4ecca3);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(78, 204, 163, 0.4);
}

/* Container */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px;
    border-radius: 12px;
    margin-bottom: 24px;
}

.tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.tab.active {
    background: var(--accent);
    color: #1a1a2e;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

/* Day Selector */
.day-selector {
    text-align: center;
}

.day-selector h2 {
    margin-bottom: 20px;
    font-size: 1.4rem;
}

.day-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.day-btn {
    background: var(--bg-panel);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 30px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.day-btn:hover {
    border-color: var(--accent);
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(78, 204, 163, 0.2);
}

.day-btn .day-label {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--accent);
}

.day-btn .day-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Workout Session */
.workout-session {
    animation: fadeIn 0.3s ease;
}

.session-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.session-header h2 {
    font-size: 1.4rem;
}

.session-date {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

.session-actions {
    display: flex;
    gap: 8px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--accent);
    color: #1a1a2e;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 15px rgba(78, 204, 163, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

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

.btn-danger:hover {
    background: #c0392b;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

/* Exercise List */
.exercise-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.exercise-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    transition: all 0.3s ease;
}

.exercise-card.completed {
    border-color: var(--accent);
    background: linear-gradient(135deg, var(--bg-panel), rgba(78, 204, 163, 0.05));
}

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

.exercise-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.exercise-guide {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--orange);
    text-decoration: none;
    background: var(--orange-dim);
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
    transition: all 0.2s ease;
}

.exercise-guide:hover {
    background: var(--orange);
    color: #1a1a2e;
    transform: translateY(-1px);
}

.exercise-badge {
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
}

.badge-priority {
    background: var(--orange-dim);
    color: var(--orange);
}

.badge-optional {
    background: var(--blue-dim);
    color: var(--blue);
}

.exercise-prescription {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 14px;
}

.exercise-note {
    color: var(--orange);
    font-size: 0.8rem;
    font-style: italic;
    margin-bottom: 10px;
}

/* Sets Table */
.sets-table {
    width: 100%;
    border-collapse: collapse;
}

.sets-table th {
    text-align: left;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

.sets-table td {
    padding: 6px 8px;
}

.sets-table tr:not(:last-child) td {
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.set-number {
    font-weight: 700;
    color: var(--accent);
    font-size: 0.85rem;
    width: 40px;
}

.set-input {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    width: 80px;
    text-align: center;
    transition: border-color 0.2s;
}

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

.set-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

.set-check {
    width: 24px;
    height: 24px;
    appearance: none;
    -webkit-appearance: none;
    background: rgba(0, 0, 0, 0.25);
    border: 2px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.set-check:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.set-check:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #1a1a2e;
    font-size: 14px;
    font-weight: bold;
}

.set-previous {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Plan Tab */
.plan-header {
    text-align: center;
    margin-bottom: 24px;
}

.plan-header h2 {
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.plan-header p {
    color: var(--text-secondary);
}

.plan-info-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 30px;
}

.info-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}

.info-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.info-card h4 {
    color: var(--accent);
    margin-bottom: 6px;
    font-size: 0.95rem;
}

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

.plan-days {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.plan-day {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
}

.plan-day-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--accent);
}

.plan-exercise {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

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

.plan-exercise-name .priority-tag {
    font-size: 0.7rem;
    background: var(--orange-dim);
    color: var(--orange);
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    font-weight: 600;
}

.plan-exercise-sets {
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
}

.plan-exercise-note {
    font-size: 0.8rem;
    color: var(--orange);
    font-style: italic;
    margin-top: 2px;
}

/* History Tab */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.history-filters {
    display: flex;
    gap: 8px;
    align-items: center;
}

.history-filters select {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.history-filters select:focus {
    outline: none;
    border-color: var(--accent);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-card:hover {
    border-color: rgba(78, 204, 163, 0.3);
    transform: translateX(4px);
}

.history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.history-day-tag {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
}

.tag-A {
    background: var(--orange-dim);
    color: var(--orange);
}

.tag-B {
    background: var(--blue-dim);
    color: var(--blue);
}

.tag-C {
    background: var(--accent-dim);
    color: var(--accent);
}

.history-date {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.history-summary {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.history-stat {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.history-stat strong {
    color: var(--text-primary);
}

/* History Detail (expanded) */
.history-detail {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: none;
}

.history-detail.open {
    display: block;
    animation: fadeIn 0.2s ease;
}

.history-exercise-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 6px 0;
    font-size: 0.85rem;
}

.history-exercise-row .ex-name {
    font-weight: 600;
}

.history-exercise-row .ex-sets {
    color: var(--text-secondary);
}

.history-card .delete-workout {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
    margin-top: 10px;
}

.history-card .delete-workout:hover {
    background: var(--red-dim);
}

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

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

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

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

.stats-section {
    margin-bottom: 30px;
}

.stats-section h3 {
    font-size: 1.1rem;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.pr-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 10px;
}

.pr-item {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pr-item .pr-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.pr-item .pr-value {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.95rem;
}

/* Frequency Chart */
.frequency-chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 140px;
    padding: 16px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.freq-bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
    gap: 4px;
}

.freq-bar {
    width: 100%;
    max-width: 40px;
    background: var(--accent);
    border-radius: 6px 6px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
}

.freq-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
}

.freq-count {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 700;
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-state-inline {
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 20px;
    text-align: center;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--accent);
    color: #1a1a2e;
    padding: 14px 28px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    z-index: 9999;
    opacity: 0;
    transition: all 0.4s ease;
    box-shadow: 0 8px 30px rgba(78, 204, 163, 0.3);
}

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

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .tab {
        flex: 1 1 45%;
        padding: 10px 8px;
        font-size: 0.85rem;
    }

    .day-buttons {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .day-btn {
        padding: 20px;
    }

    .plan-info-cards {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .session-header {
        flex-direction: column;
    }

    .session-actions {
        width: 100%;
    }

    .session-actions .btn {
        flex: 1;
    }

    .history-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .set-input {
        width: 60px;
        padding: 6px;
        font-size: 0.85rem;
    }

    .sets-table th,
    .sets-table td {
        padding: 4px 4px;
    }

    .pr-list {
        grid-template-columns: 1fr;
    }

    .frequency-chart {
        height: 120px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.2rem;
    }

    .back-button {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .exercise-name {
        font-size: 1rem;
    }
}
