/* ===== Design Tokens ===== */
:root {
    --bg-primary: #050507;
    --bg-secondary: #0c0d12;
    --bg-card: #12141c;
    --bg-card-hover: #181a24;
    --bg-input: #0e1018;
    --border-subtle: rgba(255,255,255,.06);
    --border-focus: #00b4d8;
    --accent: #00b4d8;
    --accent-glow: rgba(0,180,216,.25);
    --accent-gradient: linear-gradient(135deg, #00b4d8, #0096c7);
    --accent-dark: #0096c7;
    --success: #38d97a;
    --danger: #f44;
    --warning: #f5a623;
    --text-primary: #eef1f6;
    --text-secondary: #6b7280;
    --text-muted: #4b5163;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 50%;
    --shadow-card: 0 2px 16px rgba(0,0,0,.45);
    --shadow-glow: 0 0 20px var(--accent-glow);
    --transition: .22s cubic-bezier(.4,0,.2,1);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --nav-height: 68px;
    --header-height: 56px;
}

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

html {
    height: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    min-height: 100%;
    overscroll-behavior-y: contain;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 4px; }

/* ===== Typography ===== */
h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .6rem; }
h3 { font-size: .95rem; font-weight: 600; }

/* ===== Utility ===== */
.text-danger { color: var(--danger); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.w-100 { width: 100%; }
.hidden { display: none !important; }

/* ===== App Header ===== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5,5,7,.82);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 200;
    padding-top: var(--safe-top);
}

/* ===== Main Content ===== */
.app-content {
    padding-top: calc(var(--header-height) + var(--safe-top) + 12px);
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
    padding-left: 16px;
    padding-right: 16px;
    min-height: 100vh;
}

/* ===== Cards ===== */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-card);
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}
.glass-card:active {
    transform: scale(.985);
}

/* ===== Buttons ===== */
.btn {
    font-family: var(--font);
    font-weight: 600;
    font-size: .88rem;
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.btn:active { transform: scale(.96); }

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:active {
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid rgba(0,180,216,.25);
}
.btn-secondary:active {
    background: rgba(0,180,216,.08);
}

.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid rgba(255,68,68,.2);
}
.btn-danger-outline:active {
    background: rgba(255,68,68,.08);
}

.btn-sm { padding: 8px 14px; font-size: .8rem; }
.btn-xs { padding: 6px 10px; font-size: .75rem; border-radius: 6px; }

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
    color: var(--text-secondary);
}
.btn-icon:active { background: rgba(255,255,255,.06); }
.btn-icon.text-danger { color: var(--danger); }

/* ===== Form Controls ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: .82rem;
    font-weight: 500;
}

.input-field {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: .9rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
    appearance: none;
}
.input-field::placeholder { color: var(--text-muted); }
.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Number inputs — small inline */
.input-compact {
    width: 72px;
    text-align: center;
    padding: 8px 6px;
    font-size: .85rem;
    border-radius: 6px;
}

select.input-field {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ===== Workout Type Selector ===== */
.workout-type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 4px;
}
.type-card {
    background: var(--bg-input);
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.type-card .type-icon { font-size: 1.5rem; display: block; margin-bottom: 4px; }
.type-card .type-label { font-size: .72rem; font-weight: 600; color: var(--text-secondary); }
.type-card.selected {
    border-color: var(--accent);
    background: rgba(0,180,216,.08);
    box-shadow: var(--shadow-glow);
}
.type-card.selected .type-label { color: var(--accent); }
.type-card:active { transform: scale(.95); }

/* ===== Exercise Search ===== */
.exercise-search-container { position: relative; }

.search-input-wrapper {
    position: relative;
}
.search-input-wrapper .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: .9rem;
    pointer-events: none;
}
.search-input-wrapper .input-field {
    padding-left: 36px;
}

.dropdown-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    max-height: 240px;
    overflow-y: auto;
    z-index: 150;
    box-shadow: 0 12px 40px rgba(0,0,0,.6);
}

.dropdown-item {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    font-size: .85rem;
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:active { background: rgba(0,180,216,.1); }
.dropdown-item .muscle-tag {
    font-size: .7rem;
    color: var(--accent);
    margin-left: 6px;
    opacity: .7;
}

/* ===== Exercise Card ===== */
.exercise-card {
    margin-bottom: 12px;
    padding: 14px;
    position: relative;
}

.exercise-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-subtle);
}
.exercise-title {
    font-size: .88rem;
    font-weight: 600;
    flex: 1;
    margin-right: 8px;
}
.exercise-actions {
    display: flex;
    gap: 2px;
}

/* ===== Set Rows ===== */
.sets-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 0 6px 0;
    margin-bottom: 6px;
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}
.sets-header span:first-child { width: 24px; text-align: center; }
.sets-header .sh-weight { flex: 1; text-align: center; }
.sets-header .sh-reps { flex: 1; text-align: center; }
.sets-header .sh-del { width: 28px; }

.set-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    animation: slideUp .25s ease-out;
}
.set-number {
    width: 24px;
    height: 24px;
    background: rgba(0,180,216,.12);
    color: var(--accent);
    font-weight: 700;
    font-size: .75rem;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.set-row .input-field {
    flex: 1;
}

.multiplier { display: none; }

.set-unit {
    font-size: .7rem;
    color: var(--text-muted);
    flex-shrink: 0;
    width: 22px;
}

.add-set-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* ===== Bottom Nav ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(5,5,7,.88);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 200;
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-family: var(--font);
    transition: color var(--transition), transform var(--transition);
    flex: 1;
    padding: 6px 0;
    -webkit-tap-highlight-color: transparent;
    gap: 2px;
}
.nav-item .icon { font-size: 1.25rem; }
.nav-item .label { font-size: .62rem; font-weight: 600; letter-spacing: .02em; }
.nav-item.active { color: var(--accent); }
.nav-item:active { transform: scale(.92); }

.nav-item-center {
    flex: 1;
    display: flex;
    justify-content: center;
    position: relative;
    top: -14px;
}

.btn-new-workout {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    border: none;
    color: #fff;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 18px var(--accent-glow);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    -webkit-tap-highlight-color: transparent;
}
.btn-new-workout:active {
    transform: scale(.92);
    box-shadow: 0 2px 10px var(--accent-glow);
}
.btn-new-workout.active {
    box-shadow: 0 6px 24px rgba(0,180,216,.45);
}

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

.stat-box {
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
}
.stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-top: 4px;
}
.stat-label {
    font-size: .72rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* ===== Chart Container ===== */
.chart-container {
    padding: 16px;
}
.chart-container canvas {
    max-height: 220px;
}

/* ===== Workout History Card ===== */
.workout-history-card {
    margin-bottom: 12px;
    cursor: pointer;
}
.workout-history-card .wh-date {
    font-size: .78rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.workout-history-card .wh-exercises {
    list-style: none;
}
.workout-history-card .wh-exercises li {
    font-size: .82rem;
    color: var(--text-secondary);
    padding: 3px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.workout-history-card .wh-exercises li::before {
    content: '';
    width: 4px;
    height: 4px;
    background: var(--accent);
    border-radius: var(--radius-full);
    flex-shrink: 0;
    opacity: .5;
}
.workout-history-card .wh-summary {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-subtle);
    font-size: .72rem;
    color: var(--text-muted);
    display: flex;
    gap: 16px;
}

/* ===== Filters Bar ===== */
.filters-bar {
    display: flex;
    gap: 8px;
}
.filters-bar .input-field { flex: 1; font-size: .82rem; padding: 10px; }

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: .88rem; }

/* ===== Loading Skeleton ===== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
    height: 16px;
    margin-bottom: 8px;
}
.skeleton.skeleton-lg { height: 80px; }

/* ===== Animations ===== */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.view-animate { animation: slideUp .35s ease-out; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: .82rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
    z-index: 500;
    opacity: 0;
    transition: transform .35s ease, opacity .35s ease;
    pointer-events: none;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }

/* ===== Access Denied ===== */
.access-denied {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    color: var(--text-muted);
    font-size: 1rem;
    text-align: center;
    padding: 24px;
    background: var(--bg-primary);
}
.access-denied .lock-icon { font-size: 3rem; margin-bottom: 16px; opacity: .5; }
