/* ==========================================================================
   GymTracker Pro – Premium Dark Theme
   ========================================================================== */

/* --- CSS Custom Properties --- */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --bg-input: #1a1a25;
    --bg-modal: #16161fee;
    --border: #2a2a3a;
    --border-light: #22222e;
    --accent: #c9a84c;
    --accent-hover: #d4b85c;
    --accent-glow: rgba(201, 168, 76, 0.15);
    --accent-glow-strong: rgba(201, 168, 76, 0.3);
    --danger: #e74c5a;
    --danger-hover: #f05a68;
    --success: #34c77b;
    --warning: #f0a840;
    --info: #4a9eff;
    --text-primary: #e8e8ec;
    --text-secondary: #9898a8;
    --text-muted: #686878;
    --text-accent: var(--accent);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.6);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --nav-height: 70px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    min-height: 100dvh;
    padding-bottom: calc(var(--nav-height) + 16px);
}

/* --- Typography --- */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.2; color: var(--text-primary); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { color: var(--text-secondary); }
a { color: var(--accent); text-decoration: none; }

/* --- Loading Screen --- */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    gap: 16px;
}
.loading-screen h2 { color: var(--accent); font-size: 1.5rem; font-weight: 800; letter-spacing: 1px; }
.loading-logo svg { animation: pulse 1.5s ease-in-out infinite; }
.loading-bar { width: 120px; height: 3px; background: var(--border); border-radius: 4px; overflow: hidden; }
.loading-bar-inner { width: 40%; height: 100%; background: var(--accent); border-radius: 4px; animation: loadSlide 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.7;transform:scale(0.95)} }
@keyframes loadSlide { 0%{transform:translateX(-100%)} 100%{transform:translateX(350%)} }

/* --- Connection Status --- */
.connection-status {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 6px; font-size: 0.75rem; font-weight: 600;
    background: var(--danger); color: white;
    transition: transform var(--transition);
}
.connection-status.online { background: var(--success); }
.connection-status .status-dot { width: 6px; height: 6px; border-radius: 50%; background: white; animation: blink 1.5s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }
.hidden { display: none !important; }

/* --- Sync Indicator --- */
.sync-indicator {
    position: fixed; top: 8px; right: 8px; z-index: 999;
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: 20px;
    background: var(--bg-card); border: 1px solid var(--accent);
    font-size: 0.7rem; color: var(--accent); font-weight: 500;
}
.sync-spinner {
    width: 14px; height: 14px; border: 2px solid var(--accent);
    border-top-color: transparent; border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Toast Notifications --- */
.toast-container { position: fixed; top: 40px; right: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 12px 20px; border-radius: var(--radius-md);
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-primary); font-size: 0.85rem; font-weight: 500;
    box-shadow: var(--shadow); max-width: 320px;
    animation: toastIn 0.3s ease-out;
    transition: all 0.3s ease;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
.toast-exit { opacity: 0; transform: translateX(100%); }
@keyframes toastIn { from { opacity: 0; transform: translateX(80px); } to { opacity: 1; transform: translateX(0); } }

/* --- Bottom Navigation --- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 900;
    display: flex; align-items: center; justify-content: space-around;
    height: var(--nav-height);
    background: linear-gradient(180deg, rgba(17,17,24,0.95) 0%, #111118 100%);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-light);
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 8px 12px; color: var(--text-muted); text-decoration: none;
    font-size: 0.65rem; font-weight: 500; transition: color var(--transition);
    position: relative;
}
.nav-item svg { transition: all var(--transition); }
.nav-item.active { color: var(--accent); }
.nav-item.active svg { stroke: var(--accent); filter: drop-shadow(0 0 6px var(--accent-glow)); }
.nav-item-main { margin-top: -20px; }
.nav-item-circle {
    width: 52px; height: 52px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a88a3a);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(201,168,76,0.4);
    transition: all var(--transition);
}
.nav-item-main.active .nav-item-circle { box-shadow: 0 4px 28px rgba(201,168,76,0.6); transform: scale(1.05); }
.nav-item-circle svg { stroke: #1a1a25; }

/* --- Page Container --- */
.page { padding: 20px 16px; animation: fadeIn 0.25s ease-out; }
.page-header { margin-bottom: 24px; }
.page-header h1 { margin-bottom: 4px; }
.page-header p { font-size: 0.85rem; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* --- Cards --- */
.card {
    background: var(--bg-card); border: 1px solid var(--border-light);
    border-radius: var(--radius-lg); padding: 20px;
    transition: all var(--transition); position: relative; overflow: hidden;
}
.card:hover { background: var(--bg-card-hover); border-color: var(--border); }
.card-accent { border-left: 3px solid var(--accent); }
.card + .card { margin-top: 12px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-header h3 { font-size: 1rem; }
.card-meta { display: flex; gap: 12px; font-size: 0.75rem; color: var(--text-muted); margin-top: 8px; }
.card-meta span { display: flex; align-items: center; gap: 4px; }
.card-actions { display: flex; gap: 8px; }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 24px; border-radius: var(--radius-md);
    font-family: var(--font); font-size: 0.875rem; font-weight: 600;
    border: none; cursor: pointer; transition: all var(--transition);
    text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: linear-gradient(135deg, var(--accent), #a88a3a);
    color: #1a1a25; box-shadow: 0 4px 16px rgba(201,168,76,0.3);
}
.btn-primary:hover { box-shadow: 0 4px 24px rgba(201,168,76,0.5); }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-outline { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--text-secondary); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 8px 14px; font-size: 0.75rem; border-radius: var(--radius-sm); }
.btn-icon {
    width: 36px; height: 36px; padding: 0; border-radius: var(--radius-sm);
    background: var(--bg-card); border: 1px solid var(--border); color: var(--text-secondary); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; transition: all var(--transition);
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 12px 16px;
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    font-family: var(--font); font-size: 0.9rem;
    transition: border-color var(--transition);
    outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-input::placeholder { color: var(--text-muted); }
.form-textarea { min-height: 80px; resize: vertical; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239898a8'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.form-check input[type="checkbox"] {
    width: 20px; height: 20px; border-radius: 4px;
    border: 2px solid var(--border); background: var(--bg-input);
    appearance: none; cursor: pointer; position: relative;
    transition: all var(--transition);
}
.form-check input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.form-check input[type="checkbox"]:checked::after {
    content: '✓'; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%); color: #1a1a25; font-size: 12px; font-weight: 800;
}
.form-check label { font-size: 0.85rem; color: var(--text-secondary); cursor: pointer; }

/* --- Badge & Tags --- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 20px;
    font-size: 0.7rem; font-weight: 600;
    background: var(--accent-glow); color: var(--accent);
}
.badge-strength { background: rgba(74, 158, 255, 0.15); color: var(--info); }
.badge-cardio { background: rgba(52, 199, 123, 0.15); color: var(--success); }

/* --- Modal --- */
.modal {
    position: fixed; inset: 0; z-index: 5000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px; animation: modalFadeIn 0.2s ease;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.modal-content {
    position: relative; width: 100%; max-width: 400px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: 28px;
    box-shadow: var(--shadow-lg); z-index: 1;
}
.modal-content h3 { margin-bottom: 12px; text-align: center; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- Timer --- */
.timer-modal-content { text-align: center; }
.timer-display { position: relative; width: 160px; height: 160px; margin: 20px auto; }
.timer-ring { transform: rotate(-90deg); }
.timer-ring-bg { fill: none; stroke: var(--border); stroke-width: 6; }
.timer-ring-progress { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 339.292; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear; }
.timer-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.timer-controls { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }

/* --- Stats Grid --- */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 24px; }
.stat-card {
    background: var(--bg-card); border: 1px solid var(--border-light);
    border-radius: var(--radius-lg); padding: 16px; text-align: center;
}
.stat-value { font-size: 1.5rem; font-weight: 800; color: var(--accent); margin-bottom: 2px; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }

/* --- Exercise List in Workout --- */
.exercise-item {
    background: var(--bg-card); border: 1px solid var(--border-light);
    border-radius: var(--radius-lg); padding: 16px; margin-bottom: 10px;
    transition: all var(--transition); cursor: pointer;
}
.exercise-item:hover { border-color: var(--border); }
.exercise-item.active { border-color: var(--accent); background: var(--bg-card-hover); box-shadow: 0 0 0 3px var(--accent-glow); }
.exercise-item.completed { opacity: 0.6; }
.exercise-item.completed::after { content: '✓'; position: absolute; top: 8px; right: 12px; color: var(--success); font-weight: 800; }
.exercise-item { position: relative; }
.exercise-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.exercise-params { display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.75rem; color: var(--text-muted); }
.exercise-params span { display: flex; align-items: center; gap: 4px; }
.exercise-photo { width: 48px; height: 48px; border-radius: var(--radius-sm); object-fit: cover; border: 1px solid var(--border); }

/* --- Workout Session --- */
.workout-current { text-align: center; padding: 20px 0; }
.workout-current .exercise-name { font-size: 1.25rem; margin-bottom: 8px; }
.workout-sets { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.set-badge {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 700;
    background: var(--bg-input); border: 2px solid var(--border);
    transition: all var(--transition);
}
.set-badge.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }
.set-badge.done { background: var(--accent); color: #1a1a25; border-color: var(--accent); }
.workout-input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 300px; margin: 16px auto; }
.workout-input-grid .form-group { margin-bottom: 0; }

/* --- Progress Chart --- */
.chart-container { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 16px; }
.chart-container canvas { width: 100% !important; }

/* --- History Table --- */
.history-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.history-table th { text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
.history-table td { padding: 10px 12px; border-bottom: 1px solid var(--border-light); color: var(--text-secondary); }
.history-table tr:hover td { background: var(--bg-card-hover); }

/* --- Auth Pages --- */
.auth-page {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-height: 100dvh; padding: 40px 20px;
}
.auth-logo { margin-bottom: 32px; text-align: center; }
.auth-logo svg { margin-bottom: 12px; }
.auth-logo h1 { font-size: 1.5rem; color: var(--accent); font-weight: 800; letter-spacing: 1px; }
.auth-logo p { font-size: 0.85rem; color: var(--text-muted); }
.auth-form { width: 100%; max-width: 380px; }
.auth-form .btn-primary { margin-top: 8px; }
.auth-switch { text-align: center; margin-top: 20px; font-size: 0.85rem; color: var(--text-muted); }
.auth-switch a { color: var(--accent); font-weight: 600; }

/* --- Empty State --- */
.empty-state {
    text-align: center; padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state svg { margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 0.85rem; margin-bottom: 20px; }

/* --- Profile Page --- */
.profile-header { text-align: center; padding: 20px 0 30px; }
.profile-avatar {
    width: 80px; height: 80px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a88a3a);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 12px; font-size: 2rem; font-weight: 800; color: #1a1a25;
}
.profile-name { font-size: 1.2rem; font-weight: 700; }
.profile-email { font-size: 0.8rem; color: var(--text-muted); }
.profile-menu .card { cursor: pointer; display: flex; align-items: center; gap: 12px; }
.profile-menu .card svg { color: var(--text-muted); flex-shrink: 0; }
.profile-menu .card:hover svg { color: var(--accent); }

/* --- Photo Gallery --- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-thumb { aspect-ratio: 1; border-radius: var(--radius-sm); object-fit: cover; border: 1px solid var(--border); cursor: pointer; transition: all var(--transition); }
.photo-thumb:hover { border-color: var(--accent); transform: scale(1.02); }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Responsive --- */
@media (min-width: 768px) {
    .page { max-width: 600px; margin: 0 auto; padding: 28px 20px; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
    .form-row { grid-template-columns: 1fr 1fr 1fr; }
}
@media (min-width: 1024px) {
    .page { max-width: 720px; }
}

/* Select fix */
.form-select option { background: var(--bg-card); color: var(--text-primary); }
