/* MyTrainer design system - shared by every page (loaded last, see _head.html).
   Phone first: a sticky app bar on top, a tab bar at the bottom. From 1024px
   the tab bar turns into a left sidebar. */

:root {
    --brand: #17a98c;
    --brand-600: #0f8f76;
    --brand-700: #0b6e5c;
    --brand-50: #e9f8f3;
    --brand-100: #d2f0e6;
    --brand-ink: #ffffff;
    --deep: #0e3b39;          /* logo / hero backgrounds */
    --peach: #ff8a65;
    --peach-50: #fff1eb;
    --sky: #3ea8e0;
    --violet: #8b7cf6;
    --amber: #f5a524;
    --danger: #e5484d;
    --danger-50: #fdecec;

    --bg: #f3f7f6;
    --card: #ffffff;
    --card-2: #f6f9f8;
    --ink: #10302d;
    --text: #22312f;
    --muted: #6d7d7a;
    --line: #e4ecea;

    --radius: 20px;
    --radius-sm: 14px;
    --shadow: 0 1px 2px rgba(16, 48, 45, 0.04), 0 8px 24px rgba(16, 48, 45, 0.06);
    --shadow-lg: 0 18px 48px rgba(16, 48, 45, 0.16);
    --gutter: 16px;
    --tabbar-h: 64px;
    --rail-w: 248px;
    --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100dvh;
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(1200px 520px at 100% -10%, rgba(255, 173, 140, 0.18), transparent 60%),
        radial-gradient(900px 480px at -10% -5%, rgba(23, 169, 140, 0.14), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font-family: inherit; }
a { color: var(--brand-600); }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Page body: leaves room for the tab bar (mobile) or the sidebar (desktop) */
.container {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 var(--gutter) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
}

/* ---------- App bar ---------- */
.appbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 calc(-1 * var(--gutter)) 12px;
    padding: calc(env(safe-area-inset-top) + 14px) var(--gutter) 12px;
    background: rgba(243, 247, 246, 0.82);
    backdrop-filter: saturate(1.6) blur(14px);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    text-align: left;
}

.appbar-text { flex: 1; min-width: 0; }

.appbar h1 {
    margin: 0;
    font-size: 1.6rem;
    line-height: 1.2;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.appbar-kicker {
    margin: 0 0 2px;
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.appbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.icon-action {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    box-shadow: var(--shadow);
}

.icon-action svg { width: 20px; height: 20px; }

.avatar-chip {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand), var(--brand-700));
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(23, 169, 140, 0.35);
    flex: none;
}

/* ---------- Tab bar (mobile) / sidebar (desktop) ---------- */
.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    padding: 0 6px env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(1.6) blur(16px);
    -webkit-backdrop-filter: saturate(1.6) blur(16px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 24px rgba(16, 48, 45, 0.06);
}

.tabbar-brand,
.tabbar-extra { display: none; }

.tabbar-links {
    display: flex;
    height: var(--tabbar-h);
    max-width: 560px;
    margin: 0 auto;
}

.tab {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: #8a9896;
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.1;
    border-radius: 14px;
    position: relative;
    transition: color 0.15s;
}

.tab-icon {
    width: 48px;
    height: 30px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

.tab svg { width: 22px; height: 22px; }
.tab-label { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tab:active .tab-icon { transform: scale(0.92); }
.tab.active { color: var(--brand-600); font-weight: 700; }
.tab.active .tab-icon { background: var(--brand-50); }
.tab.active svg { stroke-width: 2.2; }

.tabbar-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tabbar-user-text { min-width: 0; display: flex; flex-direction: column; }
.tabbar-user-name { font-weight: 600; font-size: 0.9rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabbar-user-mail { font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabbar-extra form { margin: 0; }
.tabbar-extra .btn { width: 100%; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* Brand mark (logo tile + wordmark) */
.brand-mark {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--ink);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.01em;
}

.brand-mark img { width: 38px; height: 38px; border-radius: 11px; display: block; }
.brand-mark b { color: var(--brand); font-weight: 800; }

@media (min-width: 1024px) {
    :root { --gutter: 28px; }

    .has-tabbar { padding-left: var(--rail-w); }

    .tabbar {
        top: 0;
        right: auto;
        width: var(--rail-w);
        padding: 22px 14px 18px;
        display: flex;
        flex-direction: column;
        gap: 22px;
        border-top: none;
        border-right: 1px solid var(--line);
        box-shadow: none;
        background: rgba(255, 255, 255, 0.78);
    }

    .tabbar-brand { display: block; padding: 0 8px; }

    .tabbar-links {
        flex-direction: column;
        height: auto;
        max-width: none;
        margin: 0;
        gap: 4px;
    }

    .tab {
        flex: none;
        flex-direction: row;
        justify-content: flex-start;
        gap: 12px;
        padding: 10px 12px;
        font-size: 0.95rem;
        color: var(--muted);
    }

    .tab-icon { width: 36px; height: 36px; border-radius: 12px; }
    .tab:hover { background: var(--card-2); color: var(--ink); }
    .tab.active { background: var(--brand-50); }
    .tab.active .tab-icon { background: var(--brand); color: #fff; }

    .tabbar-extra {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-top: auto;
        padding-top: 16px;
        border-top: 1px solid var(--line);
    }

    .tabbar-extra .tab { padding: 8px 12px; }

    .appbar { padding-top: 22px; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; position: static; margin-bottom: 18px; }
    .appbar h1 { font-size: 1.9rem; }
    .container { padding-bottom: 40px; }
}

/* ---------- Cards, buttons, chips ---------- */
.card-surface,
.ui-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid rgba(228, 236, 234, 0.7);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 0 12px;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--ink);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 18px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--ink);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn:hover { border-color: var(--brand); }
.btn:active { transform: scale(0.98); }

.btn.primary-btn,
.btn-brand {
    background: linear-gradient(135deg, var(--brand), var(--brand-600));
    border-color: transparent;
    color: var(--brand-ink);
    box-shadow: 0 6px 16px rgba(23, 169, 140, 0.3);
}

.btn.primary-btn:hover,
.btn-brand:hover { background: linear-gradient(135deg, var(--brand-600), var(--brand-700)); }

.btn.secondary-btn { background: var(--danger-50); border-color: transparent; color: var(--danger); }
.btn.secondary-btn:hover { background: var(--danger); color: #fff; }

.btn:disabled,
.btn:disabled:hover {
    background: var(--card-2);
    border-color: var(--line);
    color: #a9b5b3;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.hidden { display: none !important; }

/* Form grades (video analysis, history) */
.grade-a { background-color: #1fa971 !important; color: #fff !important; }
.grade-b { background-color: var(--sky) !important; color: #fff !important; }
.grade-c { background-color: #f2c84b !important; color: #3b2f00 !important; }
.grade-d { background-color: #f08a3c !important; color: #fff !important; }
.grade-f { background-color: var(--danger) !important; color: #fff !important; }

/* ---------- Flash messages ---------- */
.flash-list { list-style: none; margin: 0 0 16px; padding: 0; }

.flash {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 0.92rem;
    word-break: break-word;
}

.flash-error { background: var(--danger-50); color: #b42318; }
.flash-success { background: var(--brand-50); color: var(--brand-700); }
.flash-warning { background: #fff5e0; color: #8a5a00; }
.flash-info { background: #e8f3fb; color: #1f5f8b; }

/* ---------- Auth pages ---------- */
.auth-wrap {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: calc(env(safe-area-inset-top) + 24px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border-radius: 28px;
    box-shadow: var(--shadow-lg);
    padding: 30px 24px;
}

.auth-card h1 { font-size: 1.5rem; margin: 0 0 6px; color: var(--ink); text-align: center; }
.auth-card .auth-sub { color: var(--muted); text-align: center; margin: 0 0 18px; }
.auth-card label { display: block; font-weight: 600; font-size: 0.9rem; margin: 14px 0 6px; color: var(--ink); }

.auth-card input[type="text"],
.auth-card input[type="email"],
.auth-card input[type="password"] {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--card-2);
    font-size: 1rem;
    color: var(--text);
}

.auth-card input:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 4px var(--brand-50); }

.auth-card .remember { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-weight: 500; }
.auth-card .remember input { accent-color: var(--brand); width: 18px; height: 18px; }

.auth-card button[type="submit"] {
    width: 100%;
    margin-top: 22px;
    padding: 14px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--brand), var(--brand-600));
    box-shadow: 0 8px 20px rgba(23, 169, 140, 0.32);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.auth-card button[type="submit"]:hover { background: linear-gradient(135deg, var(--brand-600), var(--brand-700)); }
.auth-card .auth-alt { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: 0.95rem; }
.auth-card .auth-alt a { color: var(--brand-600); font-weight: 600; }
.auth-card .auth-icon { font-size: 2.6rem; text-align: center; margin-bottom: 8px; }
.auth-card .auth-text { color: var(--text); line-height: 1.55; text-align: center; }

.auth-brand { text-align: center; }
.auth-brand .brand-mark { font-size: 1.5rem; }
.auth-brand .brand-mark img { width: 52px; height: 52px; border-radius: 15px; }
.auth-tagline { margin: 8px auto 0; max-width: 340px; color: var(--muted); font-size: 0.95rem; line-height: 1.4; text-wrap: balance; }

/* ---------- Admin ---------- */
.admin-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.admin-summary .pill {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    box-shadow: var(--shadow);
    font-size: 0.85rem;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.admin-summary .pill strong { color: var(--ink); font-size: 1.4rem; }

/* Site-wide switch (e.g. "Phê duyệt tài khoản mới") */
.admin-setting {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
}

.admin-setting-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.admin-setting-text strong { color: var(--ink); font-size: 0.95rem; }
.admin-setting-text small { color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.admin-setting form { margin: 0; flex: none; }

.switch-btn {
    position: relative;
    width: 52px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: #d6e0de;
    cursor: pointer;
    transition: background 0.2s;
}

.switch-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
    transition: transform 0.2s;
}

.switch-btn.is-on { background: var(--brand); }
.switch-btn.is-on .switch-knob { transform: translateX(20px); }

.admin-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 14px;
}

.admin-toolbar a {
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 500;
}

.admin-toolbar a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.admin-toolbar form { margin-left: auto; display: flex; gap: 6px; }

.admin-toolbar input {
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    min-width: 240px;
    font-size: 0.9rem;
}

.admin-table-wrap {
    overflow-x: auto;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    -webkit-overflow-scrolling: touch;
}

.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.admin-table th, .admin-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-table th { background: var(--card-2); color: var(--muted); font-weight: 600; white-space: nowrap; font-size: 0.82rem; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table .muted { color: var(--muted); font-size: 0.85rem; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-actions form { margin: 0; }

.admin-actions button {
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
    color: var(--text);
}

.admin-actions button:hover { border-color: var(--brand); color: var(--brand-600); }
.admin-actions button.ok { border-color: var(--brand-100); background: var(--brand-50); color: var(--brand-700); }
.admin-actions button.ok:hover { background: var(--brand); color: #fff; }
.admin-actions button.danger { color: var(--danger); }
.admin-actions button.danger:hover { border-color: var(--danger); background: var(--danger); color: #fff; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-pending { background: #fff5e0; color: #9a6200; }
.badge-active { background: var(--brand-50); color: var(--brand-700); }
.badge-disabled { background: #eef1f1; color: #6d7d7a; }
.badge-admin { background: #ecebff; color: #4f46b8; }

/* ---------- API token (profile) ---------- */
.token-box {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--card-2);
    border: 1px dashed #b9c9c6;
    border-radius: var(--radius-sm);
    padding: 12px;
    word-break: break-all;
    margin: 10px 0;
    font-size: 0.88rem;
}

.token-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.token-actions .btn { flex: 1 1 auto; }
.token-meta { color: var(--muted); font-size: 0.86rem; margin-top: 6px; line-height: 1.5; }
.token-meta code { background: var(--card-2); padding: 1px 6px; border-radius: 6px; font-size: 0.82rem; }

/* ---------- Error / offline page ---------- */
.error-page {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 20px;
}

.error-page .error-mark { width: 72px; height: 72px; border-radius: 20px; margin-bottom: 20px; box-shadow: var(--shadow-lg); }
.error-page h1 { font-size: 3rem; margin: 0; color: var(--ink); }
.error-page .error-title { font-size: 1.6rem; }
.error-page p { color: var(--muted); margin: 10px 0 24px; max-width: 360px; line-height: 1.5; }
.error-page .btn { min-width: 180px; }

/* ---------- Install banner (PWA) ---------- */
.install-hint {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--deep), #145b55);
    color: #fff;
    box-shadow: var(--shadow);
}

.install-hint img { width: 40px; height: 40px; border-radius: 11px; flex: none; }
.install-hint-text { flex: 1; min-width: 0; font-size: 0.86rem; line-height: 1.35; }
.install-hint-text strong { display: block; font-size: 0.95rem; }
.inline-icon { display: inline-flex; vertical-align: -3px; }
.inline-icon svg { width: 1.1em; height: 1.1em; }
.install-hint .btn { padding: 9px 14px; font-size: 0.85rem; background: #fff; color: var(--deep); border: none; }

/* Tooltip under the logo: "tap to install" (phones and tablets, see pwa.js) */
.install-tip {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 5;
    width: max-content;
    max-width: min(260px, calc(100vw - 32px));
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 10px 10px 12px;
    border-radius: 14px;
    background: var(--deep);
    color: #fff;
    font-size: 0.82rem;
    line-height: 1.4;
    box-shadow: var(--shadow-lg);
    animation: tip-in 0.3s ease-out 0.6s both;
}

.install-tip::before {
    content: "";
    position: absolute;
    top: -6px;
    right: 15px;
    width: 12px;
    height: 12px;
    background: var(--deep);
    transform: rotate(45deg);
    border-radius: 2px;
}

.install-tip strong { color: #7ff0d2; }

.install-tip-close {
    flex: none;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 0.7rem;
    cursor: pointer;
}

@keyframes tip-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Step-by-step install sheet (iOS / browsers without an install prompt) */
.install-sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.install-sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 30, 28, 0.5); }

.install-sheet-card {
    position: relative;
    width: 100%;
    max-width: 480px;
    padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px);
    border-radius: 26px 26px 0 0;
    background: var(--card);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    animation: tip-in 0.2s ease-out;
}

.install-sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.install-sheet-head img { width: 48px; height: 48px; border-radius: 14px; flex: none; }
.install-sheet-head h2 { margin: 0 0 2px; font-size: 1.1rem; color: var(--ink); }
.install-sheet-head p { margin: 0; font-size: 0.85rem; color: var(--muted); line-height: 1.4; }

.install-sheet-x {
    margin-left: auto;
    flex: none;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--card-2);
    color: var(--muted);
    cursor: pointer;
}

.install-steps { margin: 0 0 16px; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; font-size: 0.92rem; line-height: 1.45; }
.install-sheet-ok { width: 100%; }

@media (min-width: 640px) {
    .install-sheet { align-items: center; padding: 24px; }
    .install-sheet-card { border-radius: 24px; padding-bottom: 20px; }
}

@media (max-width: 600px) {
    .admin-toolbar form { margin-left: 0; width: 100%; }
    .admin-toolbar input { flex: 1; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
