:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #d9e0ea;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #b42318;
    --danger-bg: #fee4e2;
    --success: #067647;
    --success-bg: #dcfae6;
    --shadow: 0 20px 45px rgba(23, 32, 51, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--primary);
    font-weight: 700;
}

button,
input {
    font: inherit;
}

button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    cursor: pointer;
    font-weight: 700;
    padding: 0.75rem 1rem;
}

button:hover,
button:focus-visible {
    background: var(--primary-dark);
}

button.secondary {
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--text);
}

button.secondary:hover,
button.secondary:focus-visible {
    background: #eef3ff;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-shell {
    width: min(100%, 520px);
}

.panel,
.card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.panel {
    padding: clamp(1.25rem, 5vw, 2rem);
}

.brand,
.app-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.brand {
    margin-bottom: 1.5rem;
}

.brand h1,
.hero h1 {
    margin: 0;
    line-height: 1.1;
}

.brand h1 {
    overflow-wrap: anywhere;
}

.brand > div {
    min-width: 0;
}

.brand p,
.hero p,
.card p,
.muted {
    color: var(--muted);
}

.brand p,
.muted {
    margin: 0.35rem 0 0;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 800;
}

.form {
    display: grid;
    gap: 1rem;
}

.form label {
    display: grid;
    gap: 0.4rem;
    color: #344054;
    font-weight: 700;
}

.form input {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 0.7rem 0.8rem;
}

.form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
    outline: 0;
}

.alert {
    border-radius: 8px;
    margin-bottom: 1rem;
    padding: 0.75rem 0.9rem;
    font-weight: 700;
}

.alert.error {
    background: var(--danger-bg);
    color: var(--danger);
}

.alert.success {
    background: var(--success-bg);
    color: var(--success);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    padding: 0.9rem clamp(1rem, 4vw, 2rem);
}

.app-title {
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 800;
    text-decoration: none;
    min-width: 0;
}

.app-title span:last-child {
    overflow-wrap: anywhere;
}

.container {
    width: min(100% - 2rem, 1080px);
    margin: 0 auto;
    padding: clamp(1.5rem, 5vw, 3rem) 0;
}

.hero {
    margin-bottom: 1.5rem;
}

.eyebrow {
    margin: 0 0 0.5rem;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.card {
    min-height: 150px;
    padding: 1.25rem;
}

.card h2 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
}

.info-dot {
    display: inline-grid;
    place-items: center;
    width: 0.9rem;
    height: 0.9rem;
    min-height: 0.9rem;
    margin-left: 0.25rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #ffffff;
    color: var(--muted);
    font-size: 0.28rem;
    font-weight: 800;
    line-height: 1;
    padding: 0;
}

.info-dot:hover,
.info-dot:focus-visible {
    border-color: var(--primary);
    color: var(--primary);
    background: #eef3ff;
}

@media (max-width: 760px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar form,
    .topbar button {
        width: 100%;
    }

    .grid {
        grid-template-columns: 1fr;
    }
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.stats-grid,
.workspace-grid {
    display: grid;
    gap: 1rem;
}

.stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 1rem;
}

.stat-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.stat-card strong {
    display: block;
    margin-top: 0.35rem;
    font-size: clamp(1.35rem, 3vw, 2rem);
    line-height: 1.1;
}

.workspace-grid {
    align-items: start;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

.weight-form-panel h2,
.history-panel h2 {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
}

.weight-form-panel .form {
    margin-top: 1rem;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 560px;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 0.75rem;
    text-align: left;
    vertical-align: middle;
}

th {
    color: #344054;
    font-size: 0.85rem;
    font-weight: 800;
}

td {
    color: var(--text);
}

td.actions {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}

button.danger {
    min-height: 38px;
    background: var(--danger-bg);
    color: var(--danger);
    padding: 0.5rem 0.75rem;
}

button.danger:hover,
button.danger:focus-visible {
    background: #fecdca;
}

@media (max-width: 860px) {
    .stats-grid,
    .workspace-grid {
        grid-template-columns: 1fr;
    }
}

select {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 0.7rem 0.8rem;
    font: inherit;
}

select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
    outline: 0;
}

.section-block {
    margin-bottom: clamp(1.5rem, 4vw, 2.5rem);
}

.section-block > .section-heading h2 {
    margin: 0 0 0.25rem;
    font-size: 1.35rem;
}

button.compact {
    min-height: 38px;
    padding: 0.45rem 0.7rem;
}

.meal-stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.meal-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}

.meal-form-panel,
.template-panel {
    padding: 1.1rem;
}

.meal-list-panel {
    padding: 1.1rem;
    grid-row: span 2;
}

.compact-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.compact-form .full-row {
    grid-column: 1 / -1;
}

.compact-heading {
    margin-bottom: 0.5rem;
}

.meal-list,
.template-list {
    display: grid;
    gap: 0.6rem;
}

.meal-row,
.template-row {
    display: grid;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 0.75rem;
}

.meal-row {
    grid-template-columns: minmax(0, 1.2fr) minmax(220px, 1fr) auto;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: flex-end;
}


.template-row {
    grid-template-columns: minmax(0, 1fr) auto;
}

.meal-row strong,
.template-row strong {
    display: block;
    overflow-wrap: anywhere;
}

.meal-row span,
.template-row span {
    color: var(--muted);
    font-size: 0.9rem;
}

.meal-macros {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.meal-macros span {
    border-radius: 999px;
    background: #eef3ff;
    color: #344054;
    padding: 0.2rem 0.45rem;
    font-size: 0.82rem;
    font-weight: 700;
}

.icon-action {
    justify-self: end;
}

.inline-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    margin: 0.75rem 0;
}

.inline-form input {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.6rem 0.7rem;
    font: inherit;
}

.template-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: flex-end;
}

.empty-state {
    margin: 0;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 0.9rem;
}

@media (max-width: 980px) {
    .meal-grid,
    .meal-stats-grid {
        grid-template-columns: 1fr;
    }

    .meal-list-panel {
        grid-row: auto;
    }
}

@media (max-width: 620px) {
    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .admin-backup-grid {
        grid-template-columns: 1fr;
    }

    .section-heading > button {
        width: 100%;
    }

    .compact-form,
    .meal-row,
    .template-row,
    .inline-form {
        grid-template-columns: 1fr;
    }

    .row-actions,
    .row-actions button,
    .icon-action,
    .template-actions,
    .template-actions button {
        width: 100%;
    }

    .template-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}

.workout-stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.workout-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}

.workout-form-panel,
.workout-template-panel {
    padding: 1.1rem;
}

.workout-list-panel {
    padding: 1.1rem;
    grid-row: span 2;
}

.workout-list {
    display: grid;
    gap: 0.6rem;
}

.workout-row {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(180px, 0.8fr) auto;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 0.75rem;
}

.workout-row .row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: flex-end;
}


.workout-row strong {
    display: block;
    overflow-wrap: anywhere;
}

.workout-row span {
    color: var(--muted);
    font-size: 0.9rem;
}

.workout-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.workout-metrics span {
    border-radius: 999px;
    background: #eef3ff;
    color: #344054;
    padding: 0.2rem 0.45rem;
    font-size: 0.82rem;
    font-weight: 700;
}

@media (max-width: 980px) {
    .workout-grid,
    .workout-stats-grid {
        grid-template-columns: 1fr;
    }

    .workout-list-panel {
        grid-row: auto;
    }
}

@media (max-width: 620px) {
    .workout-row {
        grid-template-columns: 1fr;
    }
}

.target-stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.profile-panel {
    padding: 1.1rem;
}

.profile-panel h2 {
    margin: 0 0 0.75rem;
    font-size: 1.15rem;
}

.profile-form {
    align-items: end;
}

@media (max-width: 980px) {
    .target-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 620px) {
    .target-stats-grid {
        grid-template-columns: 1fr;
    }
}

.topnav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.secondary-link {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    font-weight: 700;
    min-height: 38px;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
}

.admin-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}

.admin-panel {
    padding: 1.1rem;
}

.admin-panel h2 {
    margin: 0 0 0.75rem;
    font-size: 1.15rem;
}

.admin-users-panel table {
    min-width: 860px;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 0.5rem !important;
}

.checkbox-label input {
    width: auto;
    min-height: auto;
}

.inline-admin-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 0.5rem;
}

.admin-delete-form {
    display: grid;
    gap: 0.5rem;
    align-items: start;
}

.admin-delete-confirm {
    align-items: flex-start;
}

.admin-delete-confirm input {
    margin-top: 0.2rem;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}


.admin-backup-panel {
    grid-column: 1 / -1;
}

.admin-backup-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.admin-backup-form {
    display: grid;
    gap: 0.75rem;
    align-content: start;
}

.admin-backup-form button {
    width: fit-content;
}

.backup-note {
    margin: 0.75rem 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}
@media (max-width: 900px) {
    .admin-grid,
    .topnav,
    .admin-backup-grid {
        grid-template-columns: 1fr;
    }

    .admin-grid {
        display: grid;
    }

    .topnav {
        align-items: stretch;
        flex-direction: column;
    }
}

.stats-filter {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.stats-filter label {
    display: grid;
    gap: 0.25rem;
    min-width: 142px;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.chart-panel {
    padding: 1rem;
}

.chart-panel h2 {
    margin: 0 0 0.45rem;
    font-size: 1.05rem;
}

.chart-panel p.muted {
    margin: 0 0 0.75rem;
}

.chart-panel-wide {
    grid-column: 1 / -1;
}

.chart-panel canvas {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

@media (max-width: 980px) {
    .chart-grid {
        grid-template-columns: 1fr;
    }

    .chart-panel-wide {
        grid-column: auto;
    }
}

.reminder-panel {
    padding: 1.1rem;
}

.push-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbff;
    margin-bottom: 1rem;
    padding: 0.9rem;
}

.push-box h3 {
    margin: 0 0 0.25rem;
    font-size: 1rem;
}

.push-actions {
    display: grid;
    gap: 0.35rem;
    justify-items: start;
}

.reminder-form {
    align-items: end;
}

.weekday-fieldset {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 0;
    padding: 0.8rem;
}

.weekday-fieldset legend {
    color: #344054;
    font-weight: 800;
    padding: 0 0.25rem;
}

.app-tabs {
    display: flex;
    gap: 0.5rem;
    margin: 0 0 1rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    scrollbar-width: thin;
}

.app-tabs button {
    flex: 0 0 auto;
    min-height: 40px;
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--text);
    padding: 0.55rem 0.8rem;
}

.app-tabs button.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.quick-actions button {
    min-height: 54px;
}

@media (max-width: 700px) {
    .quick-actions {
        grid-template-columns: 1fr 1fr;
    }

    .app-tabs {
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
    }
}


@media (max-width: 620px) {
    .push-box {
        align-items: stretch;
        flex-direction: column;
    }

    .push-actions {
        justify-items: stretch;
    }
}
