/* =====================================================
   Step Competition — app.css
   Mobile-first, fitness-inspired design
   ===================================================== */

/* ----- Custom properties ----------------------------- */
:root {
    --primary:       #FF6B35;
    --primary-dark:  #e55a25;
    --secondary:     #1A936F;
    --accent:        #4ECDC4;
    --danger:        #FF3B30;
    --warning:       #FF9500;
    --success:       #34C759;

    --bg:            #F2F2F7;
    --surface:       #FFFFFF;
    --surface-2:     #F8F8F8;
    --border:        #E5E5EA;

    --text:          #1C1C1E;
    --text-2:        #636e72;
    --text-3:        #ADB5BD;

    --gold:          #FFD700;
    --silver:        #C0C0C0;
    --bronze:        #CD7F32;

    --radius:        14px;
    --radius-sm:     8px;
    --radius-lg:     20px;

    --shadow:        0 2px 12px rgba(0,0,0,.08);
    --shadow-sm:     0 1px 4px  rgba(0,0,0,.06);
    --shadow-lg:     0 8px 32px rgba(0,0,0,.12);

    --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --bottom-nav-h:  68px;
}

/* ----- Reset ----------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
input, select, textarea { color: var(--text); }

/* ----- App shell ------------------------------------- */
.app-body {
    min-height: 100vh;
    padding-bottom: calc(var(--bottom-nav-h) + 16px);
}

/* ----- Header ---------------------------------------- */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}
.app-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 56px;
    max-width: 1200px;
    margin: 0 auto;
}
.app-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}
.app-brand-name { display: none; }
@media (min-width: 480px) { .app-brand-name { display: inline; } }
.app-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-greeting { font-size: .85rem; color: var(--text-2); display: none; }
@media (min-width: 640px) { .user-greeting { display: inline; } }

/* ----- Bottom nav ------------------------------------ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    z-index: 200;
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-2);
    text-decoration: none;
    font-size: .7rem;
    font-weight: 500;
    transition: color .2s;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-item.active,
.bottom-nav-item:hover { color: var(--primary); }
.bottom-nav-icon { font-size: 1.4rem; line-height: 1; }

@media (min-width: 1024px) {
    .bottom-nav { display: none; }
    .app-body { padding-bottom: 0; }
}

/* ----- Main / container ------------------------------ */
.app-main { padding: 16px 0 8px; }
.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ----- Cards ----------------------------------------- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}
.card--form { max-width: 560px; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.card-header h3, .card-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 12px;
}
.card-footer { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

/* ----- Page header ----------------------------------- */
.page-header { margin-bottom: 20px; }
.page-header h2 { font-size: 1.5rem; font-weight: 800; }
.page-header p  { color: var(--text-2); font-size: .9rem; margin-top: 2px; }

/* ----- Stat cards ------------------------------------ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 12px;
    text-align: center;
}
.stat-card--rank  { border-top: 3px solid var(--gold); }
.stat-card--total { border-top: 3px solid var(--primary); }
.stat-card--today { border-top: 3px solid var(--accent); }
.stat-card--avg   { border-top: 3px solid var(--secondary); }

.stat-icon  { font-size: 1.6rem; margin-bottom: 4px; }
.stat-value { font-size: 1.6rem; font-weight: 900; line-height: 1.1; color: var(--text); }
.stat-label { font-size: .72rem; color: var(--text-2); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }

/* ----- Progress bars --------------------------------- */
.progress-bar-wrap {
    background: var(--border);
    border-radius: 99px;
    height: 10px;
    overflow: hidden;
    margin: 8px 0;
}
.progress-bar-wrap--sm { height: 6px; margin: 4px 0; }
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 99px;
    transition: width .6s ease;
    min-width: 2px;
}
.progress-label { font-size: .8rem; color: var(--text-2); }

/* ----- Quick actions --------------------------------- */
.quick-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* ----- Buttons --------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: .5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: .875rem;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary  { background: var(--primary);  color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline  { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-ghost    { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-danger   { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: .85; }
.btn-sm       { padding: .3rem .65rem; font-size: .8rem; border-radius: 6px; }
.btn-full     { width: 100%; }
.btn-large    { padding: .75rem 1.5rem; font-size: 1rem; border-radius: var(--radius); }

/* ----- Alerts ---------------------------------------- */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success { background: #d4edda; color: #155724; border-left: 4px solid var(--success); }
.alert-error   { background: #f8d7da; color: #721c24; border-left: 4px solid var(--danger); }

/* ----- Badges ---------------------------------------- */
.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 99px;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.badge--active    { background: #d4edda; color: #155724; }
.badge--planned   { background: #fff3cd; color: #856404; }
.badge--completed { background: #e2e3e5; color: #383d41; }
.badge--inactive  { background: #f8d7da; color: #721c24; }
.badge--admin     { background: #cfe2ff; color: #084298; }
.badge--user      { background: var(--bg); color: var(--text-2); }

/* ----- Forms ----------------------------------------- */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text);
}
.form-group input:not([type=checkbox]):not([type=radio]),
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .6rem .75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: .95rem;
    transition: border-color .15s;
    -webkit-appearance: none;
    appearance: none;
}
.form-group input:not([type=checkbox]):not([type=radio]):focus,
.form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(255,107,53,.15); }
.form-group input[type=checkbox],
.form-group input[type=radio] { width: auto; accent-color: var(--primary); cursor: pointer; }
.form-hint { font-size: .78rem; color: var(--text-2); margin-top: 4px; display: block; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 20px; }
.inline-form { display: inline; }
.radio-group { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.radio-label { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: border-color .15s; }
.radio-label:hover { border-color: var(--primary); }
.radio-label input[type=radio] { margin-top: 2px; accent-color: var(--primary); flex-shrink: 0; }
.radio-label small { display: block; color: var(--text-2); font-size: .8rem; margin-top: 2px; }

/* ----- Tables ---------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
    text-align: left;
    padding: 10px 12px;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-2);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg); }
.actions-cell { white-space: nowrap; display: flex; gap: 6px; align-items: center; }

/* ----- Leaderboard ----------------------------------- */
.live-badge {
    display: inline-block;
    font-size: .7rem;
    font-weight: 800;
    color: var(--danger);
    letter-spacing: .08em;
    animation: pulse 2s infinite;
    margin-left: 8px;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.podium {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 8px;
    margin: 16px 0 24px;
}
.podium-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
    max-width: 120px;
}
.podium-slot--me .podium-name { color: var(--primary); font-weight: 800; }
.podium-medal  { font-size: 1.8rem; }
.podium-name   { font-size: .78rem; font-weight: 700; text-align: center; }
.podium-steps  { font-size: .72rem; color: var(--text-2); }
.podium-bar {
    width: 100%;
    border-radius: 8px 8px 0 0;
    margin-top: 4px;
}
.podium-slot--1 .podium-bar { background: var(--gold); }
.podium-slot--2 .podium-bar { background: var(--silver); }
.podium-slot--3 .podium-bar { background: var(--bronze); }

.leaderboard-list { display: flex; flex-direction: column; gap: 8px; }
.leaderboard-item {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: transform .1s;
}
.leaderboard-item:hover { transform: translateX(2px); }
.leaderboard-item--me {
    border: 2px solid var(--primary);
    background: linear-gradient(135deg, #fff8f5 0%, #fff 100%);
}
.lb-rank { font-size: 1.4rem; min-width: 36px; text-align: center; }
.lb-info { flex: 1; min-width: 0; }
.lb-name { font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-meta { font-size: .72rem; color: var(--text-2); margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.lb-steps { text-align: right; }
.lb-total { font-size: 1.05rem; font-weight: 900; }
.lb-diff  { font-size: .72rem; color: var(--text-2); }
.you-badge {
    display: inline-block;
    font-size: .6rem;
    font-weight: 800;
    background: var(--primary);
    color: #fff;
    padding: 1px 5px;
    border-radius: 99px;
    margin-left: 4px;
    vertical-align: middle;
}

/* ----- Dashboard challenges teaser ------------------- */
.challenge-dash-list { list-style: none; margin: 8px 0 0; padding: 0; }
.challenge-dash-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: .9rem;
}
.challenge-dash-item:last-child { border-bottom: none; }
.challenge-dash-name-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.challenge-dash-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.challenge-dash-dates { font-size: .75rem; color: var(--text-2); white-space: nowrap; }
.challenge-dash-leader { color: var(--text-2); font-size: .85rem; white-space: nowrap; }
.challenge-dash-leader--empty { font-style: italic; }

/* ----- Dashboard quick links / empty state ---------- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-2);
}
.empty-state--small { padding: 20px; }
.empty-icon { font-size: 2.5rem; display: block; margin-bottom: 8px; }

/* ----- Steps edit inline ----------------------------- */
.steps-edit-input { width: 90px; }
.hidden { display: none !important; }
.steps-cell { display: flex; align-items: center; gap: 8px; }
.inline-edit-form { display: flex; align-items: center; gap: 6px; }
.input-inline {
    width: 80px;
    padding: .25rem .4rem;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: .85rem;
}

/* ----- Pagination ------------------------------------ */
.pagination { display: flex; gap: 6px; justify-content: center; padding: 16px 0 4px; flex-wrap: wrap; }
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-2);
    border: 1.5px solid var(--border);
    background: var(--surface);
    text-decoration: none;
}
.page-btn.active,
.page-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ----- Auth layout ----------------------------------- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #FF6B35 0%, #FF8E6E 50%, #4ECDC4 100%);
    padding: 24px 16px;
}
.auth-container {
    width: 100%;
    max-width: 400px;
}
.auth-logo {
    text-align: center;
    margin-bottom: 24px;
    color: #fff;
}
.auth-logo-icon { font-size: 3rem; display: block; margin-bottom: 8px; }
.auth-logo h1   { font-size: 1.6rem; font-weight: 900; }
.auth-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 28px 24px;
}
.auth-card h2 { font-size: 1.3rem; font-weight: 800; margin-bottom: 20px; }
.auth-form .btn { margin-top: 8px; }
.auth-switch { margin-top: 20px; text-align: center; font-size: 0.9rem; color: var(--text-muted); }
.auth-switch a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* ----- Admin layout ---------------------------------- */
.admin-body { background: #F0F2F5; min-height: 100vh; }
.admin-layout { display: flex; min-height: 100vh; }

.admin-sidebar {
    width: 220px;
    background: #1C1C2E;
    color: #fff;
    display: none;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
@media (min-width: 768px) { .admin-sidebar { display: flex; } }

.admin-sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.admin-sidebar-header .app-brand { color: #fff; }

.admin-nav { padding: 12px 8px; flex: 1; }
.admin-nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    color: rgba(255,255,255,.7);
    font-size: .9rem;
    font-weight: 500;
    margin-bottom: 2px;
    text-decoration: none;
    transition: all .15s;
}
.admin-nav-item:hover,
.admin-nav-item.active { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.admin-nav-divider { border: none; border-top: 1px solid rgba(255,255,255,.1); margin: 10px 0; }

.admin-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}
.admin-page-title { font-size: 1.1rem; font-weight: 800; }
.admin-user { font-size: .85rem; color: var(--text-2); }
.admin-main { padding: 20px; flex: 1; }

/* Admin-specific overrides */
.stat-grid--admin { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) { .stat-grid--admin { grid-template-columns: repeat(2, 1fr); } }

.admin-grid { display: grid; gap: 16px; }
@media (min-width: 900px) { .admin-grid { grid-template-columns: 2fr 1fr; } }

.card-header-standalone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-header-standalone h2 { font-size: 1.25rem; font-weight: 800; }

.quick-links { display: flex; flex-direction: column; gap: 8px; }
.quick-link-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-weight: 600;
    font-size: .9rem;
    text-decoration: none;
    transition: background .15s;
}
.quick-link-item:hover { background: var(--border); text-decoration: none; }

/* ----- Lang switcher --------------------------------- */
.lang-switcher { display: flex; gap: 4px; }
.lang-btn {
    padding: .2rem .45rem;
    border-radius: 6px;
    font-size: .72rem;
    font-weight: 700;
    color: var(--text-2);
    background: transparent;
    border: 1.5px solid var(--border);
    text-decoration: none;
    transition: all .15s;
}
.lang-btn.active,
.lang-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ----- Utilities ------------------------------------- */
.text-muted  { color: var(--text-2); }
.text-center { text-align: center; }

/* ----- Rival widget ---------------------------------- */
.rival-widget {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-weight: 600;
}
.rival-widget--chasing {
    background: linear-gradient(135deg, #fff5f0 0%, #fff 100%);
    border: 2px solid var(--primary);
}
.rival-widget--leading {
    background: linear-gradient(135deg, #fffbea 0%, #fff 100%);
    border: 2px solid var(--gold);
}
.rival-emoji {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
}
.rival-text { flex: 1; min-width: 0; }
.rival-headline {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}
.rival-widget--leading .rival-headline { color: #b8860b; }
.rival-sub {
    font-size: 0.82rem;
    color: var(--text-2);
    margin-top: 2px;
}
.rival-sub strong { color: var(--text); }
.rival-gap-badge {
    flex-shrink: 0;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: 800;
    background: var(--gold);
    color: #7a5900;
    letter-spacing: -.5px;
}
.rival-gap-badge--behind {
    background: var(--primary);
    color: #fff;
}

/* ----- Leaderboard diff variants --------------------- */
.lb-diff { font-size: .72rem; color: var(--text-2); margin-top: 2px; }
.lb-diff--lead { color: var(--secondary); font-weight: 700; }

/* ----- Chart ----------------------------------------- */
.chart-wrap { position: relative; width: 100%; padding-top: 8px; }

/* ----- Goal row (profile/steps) ---------------------- */
.goal-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: .85rem;
}
.goal-pct { font-weight: 700; color: var(--primary); }
.progress-bar--goal { background: var(--secondary); }

/* ----- User greeting link ---------------------------- */
a.user-greeting {
    color: var(--text);
    font-weight: 600;
    font-size: .9rem;
    text-decoration: none;
}
a.user-greeting:hover { color: var(--primary); text-decoration: none; }

/* ----- Responsive breakpoints ----------------------- */
@media (min-width: 640px) {
    .container { padding: 0 24px; }
    .card { padding: 20px; }
    .stat-value { font-size: 1.9rem; }
}
@media (min-width: 1024px) {
    .app-main { padding: 24px 0; }
    .container { max-width: 900px; }
}
