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

:root{
    --bg:#f5f6fa;
    --surface:#fff;
    --text:#1a1a2e;
    --text-muted:#6b7280;
    --primary:#4f46e5;
    --primary-light:#818cf8;
    --primary-bg:rgba(79,70,229,.08);
    --success:#10b981;
    --danger:#ef4444;
    --warning:#f59e0b;
    --border:#e5e7eb;
    --radius:12px;
    --radius-sm:8px;
    --nav-h:64px;
    --header-h:56px;
    --safe-bottom:env(safe-area-inset-bottom,20px);
    --font:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
}

@media(prefers-color-scheme:dark){
    :root{
        --bg:#0f172a;--surface:#1e293b;--text:#e2e8f0;--text-muted:#94a3b8;
        --border:#334155;--primary-bg:rgba(129,140,248,.12);
    }
}

/* ── App container ────────────────────────────────────── */
#tp-app{
    font-family:var(--font);color:var(--text);background:var(--bg);
    min-height:100dvh;display:flex;flex-direction:column;
    margin:0 auto;position:relative;
    -webkit-tap-highlight-color:transparent;
}

/* ── Header ───────────────────────────────────────────── */
.tp-header{
    height:var(--header-h);display:flex;align-items:center;padding:0 16px;
    background:var(--surface);border-bottom:1px solid var(--border);
    position:sticky;top:0;z-index:100;
}
.tp-header__title{font-size:18px;font-weight:700;flex:1}
.tp-header__back{
    background:none;border:none;font-size:22px;color:var(--primary);
    cursor:pointer;padding:8px;margin-right:4px;border-radius:var(--radius-sm);line-height:1;
}
.tp-header__back:active{background:var(--primary-bg)}
.tp-header__right{display:flex;align-items:center;gap:4px}
.tp-header__settings{
    color:var(--text-muted);padding:8px;border-radius:var(--radius-sm);
    text-decoration:none;display:flex;align-items:center;
}
.tp-header__settings:active{background:var(--primary-bg)}
.tp-session-timer{
    font-size:13px;font-weight:700;color:var(--primary);
    background:var(--primary-bg);padding:4px 10px;border-radius:999px;
    font-variant-numeric:tabular-nums;
}

/* ── Rest timer bar ───────────────────────────────────── */
.tp-rest-bar{
    position:sticky;top:var(--header-h);z-index:99;
    background:var(--primary);color:#fff;
    animation:tp-slide-down .25s ease;
}
.tp-rest-bar__inner{
    display:flex;align-items:center;gap:10px;padding:8px 16px;
    margin:0 auto;
}
.tp-rest-bar__ring{width:36px;height:36px;flex-shrink:0}
.tp-rest-bar__time{font-size:20px;font-weight:800;font-variant-numeric:tabular-nums;min-width:48px}
.tp-rest-bar__label{flex:1;font-size:13px;font-weight:500;opacity:.85}
.tp-rest-bar__stop{
    background:rgba(255,255,255,.2);border:none;color:#fff;
    padding:6px 14px;border-radius:999px;font-size:13px;font-weight:600;
    font-family:var(--font);cursor:pointer;
}
.tp-rest-bar__stop:active{background:rgba(255,255,255,.35)}

/* ── Main view ────────────────────────────────────────── */
.tp-main{
    flex:1;padding:16px;
    padding-bottom:calc(var(--nav-h) + var(--safe-bottom) + 16px);
    overflow-y:auto;-webkit-overflow-scrolling:touch;
}

/* ── Bottom nav ───────────────────────────────────────── */
.tp-nav{
    position:fixed;bottom:0;left:50%;transform:translateX(-50%);
    width:100%;
    height:calc(var(--nav-h) + var(--safe-bottom));
    padding-bottom:var(--safe-bottom);
    background:var(--surface);border-top:1px solid var(--border);
    display:flex;z-index:100;
}
.tp-nav__item{
    flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;
    gap:2px;text-decoration:none;color:var(--text-muted);
    font-size:11px;font-weight:500;padding:6px 0;transition:color .15s;
    -webkit-tap-highlight-color:transparent;
}
.tp-nav__item.active{color:var(--primary)}
.tp-nav__item svg{width:22px;height:22px}

/* ── Cards ────────────────────────────────────────────── */
.tp-card{
    background:var(--surface);border-radius:var(--radius);padding:16px;
    margin-bottom:12px;border:1px solid var(--border);
}
.tp-card__title{font-size:16px;font-weight:600;margin-bottom:8px}
.tp-card__subtitle{font-size:13px;color:var(--text-muted);margin-bottom:12px}

/* ── Buttons ──────────────────────────────────────────── */
.tp-btn{
    display:inline-flex;align-items:center;justify-content:center;gap:6px;
    min-height:48px;padding:12px 20px;border:none;border-radius:var(--radius-sm);
    font-size:15px;font-weight:600;font-family:var(--font);
    cursor:pointer;transition:opacity .15s,transform .1s;
    -webkit-tap-highlight-color:transparent;
}
.tp-btn:active{transform:scale(.97)}
.tp-btn:disabled{opacity:.5;pointer-events:none}
.tp-btn--primary{background:var(--primary);color:#fff}
.tp-btn--primary:hover{opacity:.9}
.tp-btn--outline{background:transparent;border:2px solid var(--primary);color:var(--primary)}
.tp-btn--danger{background:var(--danger);color:#fff}
.tp-btn--warning{background:var(--warning);color:#fff}
.tp-btn--sm{min-height:36px;padding:6px 14px;font-size:13px}
.tp-btn--block{width:100%}
.tp-btn--ghost{background:transparent;color:var(--primary);padding:8px}

/* ── Form fields ──────────────────────────────────────── */
.tp-input{
    width:100%;min-height:48px;padding:12px;
    border:1px solid var(--border);border-radius:var(--radius-sm);
    font-size:16px;font-family:var(--font);
    background:var(--surface);color:var(--text);-webkit-appearance:none;
}
.tp-input:focus{outline:2px solid var(--primary);outline-offset:-1px}
.tp-input--sm{min-height:40px;padding:8px 10px;font-size:16px}

textarea.tp-input{
    min-height:120px;resize:vertical;
    font-family:"SF Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
    font-size:13px;line-height:1.5;
}

select.tp-input{padding-right:32px}

.tp-label{display:block;font-size:13px;font-weight:600;color:var(--text-muted);margin-bottom:6px}

/* ── Toggle chips ─────────────────────────────────────── */
.tp-chips{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:16px}
.tp-chip{
    min-height:44px;min-width:44px;padding:8px 16px;
    border:2px solid var(--border);border-radius:999px;
    background:var(--surface);color:var(--text);
    font-size:14px;font-weight:600;font-family:var(--font);
    cursor:pointer;transition:all .15s;text-align:center;
}
.tp-chip.active{background:var(--primary);color:#fff;border-color:var(--primary)}

/* ── Checkbox chips (equipment) ───────────────────────── */
.tp-check-chip{
    display:inline-flex;align-items:center;gap:6px;
    padding:8px 14px;border:2px solid var(--border);border-radius:var(--radius-sm);
    background:var(--surface);color:var(--text);
    font-size:13px;font-weight:500;font-family:var(--font);
    cursor:pointer;transition:all .15s;
}
.tp-check-chip.active{border-color:var(--primary);background:var(--primary-bg);color:var(--primary)}

/* ── Exercise row ─────────────────────────────────────── */
.tp-exercise{
    display:flex;align-items:center;gap:12px;padding:12px 0;
    border-bottom:1px solid var(--border);
}
.tp-exercise:last-child{border-bottom:none}
.tp-exercise__info{flex:1;min-width:0}
.tp-exercise__name{font-weight:600;font-size:15px}
.tp-exercise__meta{font-size:12px;color:var(--text-muted)}
.tp-exercise__actions{display:flex;gap:4px}
.tp-exercise__timer{font-size:11px;color:var(--primary);font-weight:600;font-variant-numeric:tabular-nums}
.tp-exercise__note-indicator{
    width:6px;height:6px;border-radius:50%;background:var(--warning);
    display:inline-block;margin-left:4px;vertical-align:middle;
}

/* ── Set row (logger) ─────────────────────────────────── */
.tp-set-row{
    display:flex;flex-direction:column;gap:8px;padding:12px 0;
    border-bottom:1px solid var(--border);
}
.tp-set-row:last-child{border-bottom:none}
.tp-set-row__header{display:flex;align-items:center;gap:8px}
.tp-set-row__num{font-weight:700;font-size:14px;color:var(--text-muted);min-width:32px;text-align:center}
.tp-set-row__kg{display:flex;align-items:center;gap:6px;flex:1;justify-content:flex-end}
.tp-set-row__kg label{font-size:13px;font-weight:600;color:var(--text-muted);white-space:nowrap}
.tp-set-row__kg input,.tp-set-row__kg select{width:90px}
.tp-reps{display:flex;flex-wrap:wrap;gap:6px;padding-left:40px}
.tp-rep{
    width:40px;height:40px;border-radius:50%;
    border:2px solid var(--border);background:var(--surface);
    color:var(--text-muted);font-size:13px;font-weight:700;
    font-family:var(--font);display:flex;align-items:center;justify-content:center;
    cursor:pointer;transition:all .12s;-webkit-tap-highlight-color:transparent;
}
.tp-rep.checked{background:var(--primary);border-color:var(--primary);color:#fff}
.tp-rep.tp-rep--extra{border-style:dashed;font-size:16px}
.tp-rep.tp-rep--extra.checked{border-style:solid}
.tp-rep:active{transform:scale(.9)}

/* ── Badge / streak ───────────────────────────────────── */
.tp-badge{display:inline-flex;align-items:center;gap:4px;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:700}
.tp-badge--success{background:rgba(16,185,129,.12);color:var(--success)}
.tp-badge--danger{background:rgba(239,68,68,.12);color:var(--danger)}
.tp-badge--warning{background:rgba(245,158,11,.12);color:var(--warning)}

/* ── Progress chart ───────────────────────────────────── */
.tp-chart-container{width:100%;aspect-ratio:16/9;margin-top:8px}
.tp-chart-container canvas{width:100%!important;height:100%!important;border-radius:var(--radius-sm)}

/* ── Empty state ──────────────────────────────────────── */
.tp-empty{text-align:center;padding:40px 20px;color:var(--text-muted)}
.tp-empty__icon{font-size:48px;margin-bottom:12px;opacity:.4}
.tp-empty__text{font-size:15px;margin-bottom:16px}

/* ── Toast ────────────────────────────────────────────── */
.tp-toast{
    position:fixed;top:calc(var(--header-h) + 8px);left:50%;transform:translateX(-50%);
    max-width:440px;width:calc(100% - 32px);padding:12px 16px;
    border-radius:var(--radius-sm);background:var(--primary);color:#fff;
    font-size:14px;font-weight:500;text-align:center;z-index:200;
    animation:tp-slide-down .25s ease;
}
@keyframes tp-slide-down{
    from{opacity:0;transform:translateX(-50%) translateY(-12px)}
    to{opacity:1;transform:translateX(-50%) translateY(0)}
}

/* ── Modal overlay ────────────────────────────────────── */
.tp-modal-overlay{
    position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:300;
    display:flex;align-items:center;justify-content:center;padding:16px;
    animation:tp-fade-in .2s ease;
}
@keyframes tp-fade-in{from{opacity:0}to{opacity:1}}
.tp-modal{
    background:var(--surface);border-radius:var(--radius);padding:24px;
    width:100%;max-width:400px;max-height:80vh;overflow-y:auto;
}
.tp-modal__title{font-size:18px;font-weight:700;margin-bottom:16px}

/* ── Tabs ─────────────────────────────────────────────── */
.tp-tabs{display:flex;gap:0;margin-bottom:16px;border-bottom:2px solid var(--border)}
.tp-tab{
    flex:1;padding:10px 0;text-align:center;font-size:14px;font-weight:600;
    color:var(--text-muted);cursor:pointer;border-bottom:2px solid transparent;
    margin-bottom:-2px;transition:all .15s;background:none;border-top:none;
    border-left:none;border-right:none;font-family:var(--font);
}
.tp-tab.active{color:var(--primary);border-bottom-color:var(--primary)}

/* ── Auth form ────────────────────────────────────────── */
.tp-auth{
    max-width:380px;margin:40px auto;padding:0 16px;
}

/* ── Friend list ──────────────────────────────────────── */
.tp-friend{
    display:flex;align-items:center;gap:12px;padding:12px 0;
    border-bottom:1px solid var(--border);
}
.tp-friend:last-child{border-bottom:none}
.tp-friend__avatar{
    width:40px;height:40px;border-radius:50%;background:var(--primary-bg);
    display:flex;align-items:center;justify-content:center;
    font-weight:700;color:var(--primary);font-size:16px;flex-shrink:0;
}
.tp-friend__info{flex:1;min-width:0}
.tp-friend__name{font-weight:600;font-size:14px}
.tp-friend__status{font-size:12px;color:var(--text-muted)}

/* ── AI chat ──────────────────────────────────────────── */
.tp-ai-msg{
    padding:12px;margin-bottom:8px;border-radius:var(--radius-sm);
    font-size:14px;line-height:1.5;white-space:pre-wrap;
}
.tp-ai-msg--user{background:var(--primary);color:#fff;margin-left:40px;border-radius:var(--radius-sm) var(--radius-sm) 4px var(--radius-sm)}
.tp-ai-msg--ai{background:var(--surface);border:1px solid var(--border);margin-right:40px;border-radius:var(--radius-sm) var(--radius-sm) var(--radius-sm) 4px}

/* ── AI suggestion shimmer ────────────────────────────── */
@keyframes tp-shimmer{0%{background-position:-200px 0}100%{background-position:calc(200px + 100%) 0}}
.tp-ai-loading{
    background:linear-gradient(90deg,var(--border) 25%,var(--primary-bg) 50%,var(--border) 75%);
    background-size:200px 100%;animation:tp-shimmer 1.5s ease-in-out infinite;
    border-radius:var(--radius-sm);height:60px;
}

/* ── Notes panel ──────────────────────────────────────── */
.tp-notes-panel{
    background:var(--bg);border:1px solid var(--border);border-radius:var(--radius-sm);
    padding:12px;margin-top:8px;
}
.tp-note-item{
    display:flex;gap:8px;padding:8px 0;border-bottom:1px solid var(--border);
    font-size:13px;
}
.tp-note-item:last-child{border-bottom:none}
.tp-note-item img{width:48px;height:48px;border-radius:var(--radius-sm);object-fit:cover}

/* ── Login prompt ─────────────────────────────────────── */
.tp-login-prompt{text-align:center;padding:60px 20px;font-family:var(--font)}
.tp-login-prompt p{margin-bottom:16px;font-size:16px}

/* ── Utility ──────────────────────────────────────────── */
.tp-mt-4{margin-top:4px}
.tp-mt-8{margin-top:8px}
.tp-mt-16{margin-top:16px}
.tp-mb-4{margin-bottom:4px}
.tp-mb-8{margin-bottom:8px}
.tp-mb-16{margin-bottom:16px}
.tp-flex{display:flex}
.tp-flex-between{display:flex;justify-content:space-between;align-items:center}
.tp-flex-wrap{flex-wrap:wrap}
.tp-gap-4{gap:4px}
.tp-gap-8{gap:8px}
.tp-gap-12{gap:12px}
.tp-text-center{text-align:center}
.tp-text-muted{color:var(--text-muted)}
.tp-text-sm{font-size:13px}
.tp-text-xs{font-size:11px}
.tp-text-success{color:var(--success)}
.tp-text-danger{color:var(--danger)}
.tp-text-warning{color:var(--warning)}
.tp-fw-600{font-weight:600}
.tp-hidden{display:none!important}

/* ── Spinner ──────────────────────────────────────────── */
.tp-spinner{
    width:32px;height:32px;border:3px solid var(--border);border-top-color:var(--primary);
    border-radius:50%;animation:tp-spin .6s linear infinite;margin:40px auto;
}
@keyframes tp-spin{to{transform:rotate(360deg)}}

/* ── Responsive ───────────────────────────────────────── */
@media(min-width:481px){
    #tp-app{border-left:1px solid var(--border);border-right:1px solid var(--border)}
}
