/* Gym App – klassischer iOS-Stil (iOS 16–18), ohne Blur und Transparenz-Ebenen. */

:root {
    color-scheme: light dark;

    --bg: #F2F2F7;
    --cell: #FFFFFF;
    --cell-pressed: #D1D1D6;
    --text: #000000;
    --text-secondary: rgba(60, 60, 67, 0.6);
    --text-tertiary: rgba(60, 60, 67, 0.3);
    --separator: rgba(60, 60, 67, 0.29);
    --accent: #007AFF;
    --success: #34C759;
    --success-fill: #E9F9EE;
    --destructive: #FF3B30;
    --tabbar: #F9F9F9;
    --inactive: #999999;

    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
    --radius: 10px;
    --gutter: 16px;
    --hairline: 0.5px solid var(--separator);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --cell: #1C1C1E;
        --cell-pressed: #3A3A3C;
        --text: #FFFFFF;
        --text-secondary: rgba(235, 235, 245, 0.6);
        --text-tertiary: rgba(235, 235, 245, 0.3);
        --separator: rgba(84, 84, 88, 0.65);
        --accent: #0A84FF;
        --success: #30D158;
        --success-fill: #0F2A17;
        --destructive: #FF453A;
        --tabbar: #121212;
        --inactive: #8E8E93;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.3;
    letter-spacing: -0.41px;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

a { color: var(--accent); text-decoration: none; }
button, input { font: inherit; letter-spacing: inherit; color: inherit; }
code { font-size: 15px; }

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

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Navigationsleiste mit Large Title */

.navbar {
    padding-top: env(safe-area-inset-top);
    background: var(--bg);
}

.navbar-row {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 8px;
}

.navbar-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    min-width: 44px;
    padding: 0 8px 0 0;
    font-size: 17px;
}

.chevron-left {
    width: 12px;
    height: 12px;
    border-left: 3px solid currentColor;
    border-bottom: 3px solid currentColor;
    border-radius: 1px;
    transform: rotate(45deg);
    margin: 0 2px 0 6px;
}

.large-title {
    margin: 0;
    padding: 2px var(--gutter) 8px;
    font-size: 34px;
    font-weight: 700;
    line-height: 41px;
    letter-spacing: 0.37px;
}

/* Inhalt */

.content {
    padding: 8px var(--gutter) calc(32px + env(safe-area-inset-bottom));
    max-width: 680px;
    margin: 0 auto;
}

.has-tabs .content {
    padding-bottom: calc(49px + 32px + env(safe-area-inset-bottom));
}

.message {
    margin: 16px 4px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* Inset-Grouped-Listen */

.list {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
    background: var(--cell);
    border-radius: var(--radius);
    overflow: hidden;
}

.list-spacer { margin-top: 35px; }
.list + .list { margin-top: 35px; }

.cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    padding: 11px var(--gutter);
    color: var(--text);
    background: var(--cell);
}

/* Haarlinie zwischen Zeilen, links eingerückt wie bei iOS */
.list > li { position: relative; }
.list > li + li::before {
    content: "";
    position: absolute;
    z-index: 1;
    top: 0;
    left: var(--gutter);
    right: 0;
    border-top: var(--hairline);
}

.cell-link { padding-right: 34px; }
.cell-link::after {
    content: "";
    position: absolute;
    right: 18px;
    top: 50%;
    width: 8px;
    height: 8px;
    margin-top: -4px;
    border-top: 2px solid var(--text-tertiary);
    border-right: 2px solid var(--text-tertiary);
    transform: rotate(45deg);
}

a.cell:active, button.cell:active, label.cell:active { background: var(--cell-pressed); }

.cell-value {
    color: var(--text-secondary);
    text-align: right;
}

.cell-button {
    width: 100%;
    border: 0;
    margin: 0;
    text-align: left;
    cursor: pointer;
    justify-content: flex-start;
}

.cell-accent { color: var(--accent); }
.cell-destructive { color: var(--destructive); }
.text-secondary { color: var(--text-secondary); }

.cell-wrap { word-break: break-all; }
.link-text { font-size: 15px; color: var(--text-secondary); }

.cell-input label {
    flex: 0 0 auto;
    min-width: 90px;
}

.cell-input input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    margin: -11px 0;
    border: 0;
    background: transparent;
    text-align: right;
    outline: none;
}

.cell-input input::placeholder { color: var(--text-tertiary); }

.cell-choice { cursor: pointer; }
.cell-choice input { position: absolute; opacity: 0; pointer-events: none; }
.cell-choice .checkmark {
    width: 8px;
    height: 15px;
    margin-right: 6px;
    border-right: 2.5px solid var(--accent);
    border-bottom: 2.5px solid var(--accent);
    transform: rotate(45deg) translate(-2px, -2px);
    visibility: hidden;
}
.cell-choice input:checked ~ .checkmark { visibility: visible; }
.cell-choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }

.steps { counter-reset: step; }
.steps .cell { justify-content: flex-start; }
.steps .cell::after {
    counter-increment: step;
    content: counter(step);
    order: -1;
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 12px;
    background: var(--accent);
    color: #FFFFFF;
    font-size: 15px;
    font-weight: 600;
    line-height: 24px;
    text-align: center;
}

.section-header {
    margin: 35px var(--gutter) 7px;
    font-size: 13px;
    line-height: 18px;
    letter-spacing: -0.08px;
    color: var(--text-secondary);
}

.content > .section-header:first-child,
.content > form:first-child > .section-header:first-child,
.content > form:first-child > input[type="hidden"]:first-child + .section-header { margin-top: 16px; }

.section-footer {
    margin: 0 var(--gutter) 0;
    padding-top: 0;
    font-size: 13px;
    line-height: 18px;
    letter-spacing: -0.08px;
    color: var(--text-secondary);
}

/* Hinweise */

.banner {
    margin: 0 0 16px;
    padding: 12px var(--gutter);
    border-radius: var(--radius);
    background: var(--cell);
    font-size: 15px;
}
.banner-error { color: var(--destructive); }
.banner-success { color: var(--success); }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}

/* Buttons */

.button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 50px;
    margin-top: 24px;
    padding: 0 var(--gutter);
    border: 0;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
}

.button-primary { background: var(--accent); color: #FFFFFF; }
.button-primary:active { opacity: 0.7; }
.button:disabled { opacity: 0.4; }

/* PIN */

.pin-input {
    text-align: center !important;
    font-size: 28px;
    letter-spacing: 8px;
}

.pin-input::placeholder {
    font-size: 17px;
    letter-spacing: -0.41px;
}

/* Navigationsleiste: Aktion rechts */

.navbar-action {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0 8px;
    justify-content: flex-end;
}
.navbar-action.is-bold { font-weight: 600; }

/* Zellen mit zwei Zeilen */

.cell-stack {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 2px;
}

.cell-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
}

.align-left { text-align: left !important; }

.cell-textarea textarea {
    width: 100%;
    min-height: 66px;
    border: 0;
    padding: 0;
    background: transparent;
    font: inherit;
    resize: vertical;
    outline: none;
}
.cell-textarea textarea::placeholder { color: var(--text-tertiary); }

.is-disabled { opacity: 0.45; cursor: default; }
.is-disabled:active { background: var(--cell) !important; }

/* Suchfeld */

.search { margin: 0 0 12px; }
.search input {
    width: 100%;
    height: 36px;
    padding: 0 10px 0 32px;
    border: 0;
    border-radius: 10px;
    background: rgba(118, 118, 128, 0.12) no-repeat 10px center / 15px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='6.5' cy='6.5' r='5' fill='none' stroke='%238E8E93' stroke-width='1.8'/%3E%3Cpath d='M10.3 10.3l4.2 4.2' stroke='%238E8E93' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
    font-size: 17px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.search input::placeholder { color: var(--text-secondary); }
@media (prefers-color-scheme: dark) {
    .search input { background-color: rgba(118, 118, 128, 0.24); }
}

/* Schalter (iOS-Switch) */

.cell-switch { cursor: pointer; }
.cell-switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
    position: relative;
    flex: 0 0 auto;
    width: 51px;
    height: 31px;
    border-radius: 16px;
    background: rgba(120, 120, 128, 0.16);
    transition: background 0.2s;
}
.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
    transition: transform 0.2s;
}
.cell-switch input:checked + .switch { background: var(--success); }
.cell-switch input:checked + .switch::after { transform: translateX(20px); }
.cell-switch:has(input:focus-visible) .switch { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-color-scheme: dark) {
    .switch { background: rgba(120, 120, 128, 0.32); }
}

/* Segmented Control */

.cell-muscle { flex-wrap: wrap; row-gap: 6px; }

.segmented {
    display: flex;
    flex: 0 0 auto;
    padding: 2px;
    border-radius: 9px;
    background: rgba(118, 118, 128, 0.12);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 58px;
    min-height: 32px;
    padding: 0 8px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}
.segmented input:checked + span {
    background: var(--cell);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
    font-weight: 600;
}
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
@media (prefers-color-scheme: dark) {
    .segmented { background: rgba(118, 118, 128, 0.24); }
    .segmented input:checked + span { background: #636366; }
}

/* Stepper: grosse Plus/Minus-Knöpfe */

.cell-stepper { padding-top: 6px; padding-bottom: 6px; }
.set-label { flex: 0 0 auto; min-width: 56px; }

.stepper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.stepper input {
    width: 72px;
    height: 44px;
    border: 0;
    border-radius: 8px;
    background: var(--bg);
    font-size: 22px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
    outline: none;
}
.stepper input:focus { box-shadow: inset 0 0 0 2px var(--accent); }

.stepper-button {
    width: 48px;
    height: 44px;
    border: 0;
    border-radius: 8px;
    background: var(--bg);
    color: var(--accent);
    font-size: 26px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
}
.stepper-button:active { background: var(--cell-pressed); }

.remove-button,
.reorder button {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 22px;
    cursor: pointer;
}
.remove-button { color: var(--destructive); margin-right: -10px; }
.remove-button:disabled { visibility: hidden; }

.reorder { display: flex; gap: 4px; margin: -6px -8px -6px 0; }
.reorder button { color: var(--accent); background: var(--bg); }
.reorder button:disabled { color: var(--text-tertiary); }

.inline-button {
    min-height: 44px;
    min-width: 44px;
    margin: -11px -8px -11px 8px;
    padding: 0 8px;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.cell form { display: flex; align-items: center; }

/* Training */

.workout-meta {
    margin: -4px 4px 0;
    font-size: 15px;
    color: var(--text-secondary);
}

.last-sets { display: flex; flex-wrap: wrap; gap: 6px; }
.last-set {
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--bg);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.set-row {
    padding: 10px var(--gutter) 12px;
    background: var(--cell);
}
.set-row.is-saved { background: var(--success-fill); }

.set-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}
.set-title { font-weight: 600; }
.set-hint {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--text-secondary);
}
.set-status { font-size: 13px; color: var(--text-secondary); text-align: right; }
.set-status.is-error { color: var(--destructive); }

.save-button {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 2px solid var(--separator);
    border-radius: 50%;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
}
.set-row.is-dirty .save-button,
.set-row:not(.is-saved) .save-button { border-color: var(--accent); color: var(--accent); }
.set-row.is-saved .save-button {
    border-color: var(--success);
    background: var(--success);
    color: #FFFFFF;
}
.set-row.is-saving .save-button { opacity: 0.5; }

.set-inputs {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}
.set-field { flex: 1; min-width: 0; }
.set-field-label {
    display: block;
    margin: 0 0 4px 2px;
    font-size: 13px;
    color: var(--text-secondary);
}

.stepper-compact { gap: 4px; margin-left: 0; }
.stepper-compact input { width: 100%; min-width: 0; flex: 1; }
.stepper-compact .stepper-button { flex: 0 0 44px; width: 44px; }
.set-row.is-saved .stepper input,
.set-row.is-saved .stepper-button { background: var(--cell); }

/* Status in der Übungsliste */

.cell-status { justify-content: flex-start; }
.status-icon {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--text-tertiary);
}
.status-current { border-color: var(--accent); position: relative; }
.status-current::after {
    content: "";
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: var(--accent);
}
.status-done {
    border-color: var(--success);
    background: var(--success);
    position: relative;
}
.status-done::after {
    content: "";
    position: absolute;
    left: 7px;
    top: 3px;
    width: 6px;
    height: 11px;
    border-right: 2.5px solid #FFFFFF;
    border-bottom: 2.5px solid #FFFFFF;
    transform: rotate(45deg);
}

/* Feste Leiste unten (Pausen-Timer) */

.has-toolbar .content {
    padding-bottom: calc(56px + 32px + env(safe-area-inset-bottom));
}

.toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 0 calc(var(--gutter) + env(safe-area-inset-right)) env(safe-area-inset-bottom) calc(var(--gutter) + env(safe-area-inset-left));
    background: var(--tabbar);
    border-top: var(--hairline);
}
.toolbar-label { color: var(--text-secondary); font-size: 15px; }
.timer {
    font-size: 22px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.toolbar-link {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

.stale-footer { margin-top: 8px; }

/* Rekorde in der Übersicht */

.section-header-record { color: var(--success); font-weight: 600; }
.cell-record { justify-content: flex-start; background: var(--success-fill); }
.record-badge {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--success);
    color: #FFFFFF;
    font-size: 15px;
    line-height: 28px;
    text-align: center;
}
.record-text { font-size: 15px; color: var(--success); font-weight: 600; }
.record-tag {
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--success);
    color: #FFFFFF;
    font-size: 12px;
    font-weight: 600;
    vertical-align: 2px;
}

/* Tab-Bar: solid, Haarlinie oben */

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: var(--tabbar);
    border-top: var(--hairline);
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 49px;
    padding-top: 2px;
    color: var(--inactive);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.1px;
}

.tab svg { width: 28px; height: 28px; fill: currentColor; }
.tab.is-active { color: var(--accent); }
