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

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-card-hover: #1c2a4e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #6a6a80;
    --accent: #6c63ff;
    --accent-hover: #5a52d5;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --border: #2a2a4a;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

html { font-size: 16px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100dvh;
    -webkit-text-size-adjust: 100%;
}

/* === Header === */
#app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

#app-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--accent);
}

#app-header nav { display: flex; gap: 8px; }

.nav-btn {
    flex: 1;
    padding: 10px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* === Main === */
main {
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 40px;
}

/* === Views === */
.view { display: block; }
.view:not(.active) { display: none; }
.hidden { display: none !important; }

/* === Workout Tabs (A / B / C) === */
.workout-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 12px 0;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-btn + .tab-btn { border-left: 1px solid var(--border); }

.tab-btn.active {
    background: var(--accent);
    color: #fff;
}

/* === Exercise Counter === */
.exercise-counter {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* =============================================
   EXERCISE CARD  (Solinca-style)
   ============================================= */
.ex-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.ex-card:active { transform: scale(0.985); }

.ex-card-body { padding: 20px 16px 16px; }

.ex-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}

.ex-card-img {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    object-fit: cover;
    background: #fff;
    flex-shrink: 0;
}

.ex-card-img--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    background: var(--bg-secondary);
}

.ex-card-info { flex: 1; min-width: 0; }

.ex-card-name {
    font-size: 1.05rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}

.ex-card-category {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0;
}

/* Weight display */
.ex-card-weight {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 14px;
}

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

.ex-card-weight .unit {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.ex-card-weight .no-data {
    font-size: 0.95rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Stats row (Séries | Reps | Descanso) */
.ex-card-stats {
    display: flex;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.ex-card-stat {
    flex: 1;
    text-align: center;
}

.ex-card-stat + .ex-card-stat { border-left: 1px solid var(--border); }

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

.ex-card-stat .num {
    font-size: 1.15rem;
    font-weight: 700;
}

/* Last note badge */
.ex-card-note {
    font-size: 0.78rem;
    color: var(--warning);
    margin-top: 10px;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* "Done today" indicator */
.ex-card.done { border-color: var(--success); }

.ex-card.done .ex-card-name::after {
    content: ' \2713';
    color: var(--success);
    font-size: 0.9rem;
}

/* Tap hint text at bottom */
.ex-card-hint {
    font-size: 0.72rem;
    text-align: center;
    color: var(--text-muted);
    padding: 6px 0 2px;
    opacity: 0.6;
}

/* =============================================
   EDIT MODAL
   ============================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    width: 100%;
    max-width: 480px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px 20px calc(env(safe-area-inset-bottom, 12px) + 12px);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.open .modal-card { transform: translateY(0); }

.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.modal-card h3 {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 20px;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 20px;
}

.modal-form label {
    font-size: 0.78rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-top: 6px;
}

.modal-form input,
.modal-form select {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
}

.modal-form input:focus,
.modal-form select:focus {
    border-color: var(--accent);
    outline: none;
}

.modal-form input::placeholder { color: var(--text-muted); }

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* === Buttons === */
.btn-action {
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    transition: background 0.2s;
    width: 100%;
    text-align: center;
}

.btn-action:hover { background: var(--accent-hover); }

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    width: 100%;
    text-align: center;
    transition: background 0.2s;
}

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

/* === Filters === */
.filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.filters input,
.filters select {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.filters .btn-action { grid-column: 1 / -1; }

/* === History List === */
.history-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.history-item:hover { border-color: var(--accent); }

.history-item .date {
    font-weight: 600;
    font-size: 0.95rem;
}

.history-item .stats {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
    margin-left: 8px;
}

/* Workout detail */
#workout-detail h3 { margin-bottom: 12px; }

.detail-exercise {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 8px;
}

.detail-exercise h4 { font-size: 0.95rem; margin-bottom: 8px; }

.detail-set {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 4px 0;
}

.detail-set .num {
    color: var(--text-primary);
    font-weight: 600;
}

/* === Exercises Management === */
.exercises-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.exercises-header h2 { font-size: 1.1rem; }

#new-exercise-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
}

#new-exercise-form input,
#new-exercise-form select {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

#new-exercise-form .btn-action { grid-column: 1 / -1; }

.exercise-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}

.exercise-list-item.inactive { opacity: 0.5; }

.exercise-list-item .info { flex: 1; }

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

.exercise-list-item .category {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.btn-toggle {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    min-height: 36px;
}

/* === Flash feedback === */
.flash {
    animation: flash-green 0.5s ease-out;
}

@keyframes flash-green {
    0%   { box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.6); }
    100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

/* === Login Screen === */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 16px;
}

.login-screen.hidden { display: none !important; }

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
}

.login-card h2 {
    font-size: 1.5rem;
    color: var(--accent);
    margin-bottom: 4px;
}

.login-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-card input {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
}

.login-card input::placeholder { color: var(--text-secondary); }

.login-card .btn-action { margin-top: 4px; }

.login-error {
    margin-top: 12px;
    padding: 10px;
    background: rgba(244, 67, 54, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 0.9rem;
}

/* === Spinner / Loading === */
.loading-text {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 0;
    font-size: 0.9rem;
}
