* {
    box-sizing: border-box;
}

:root {
    --color-bg: #f4f6f3;
    --color-surface: #ffffff;
    --color-surface-soft: #f7f9f7;
    --color-text: #102a43;
    --color-muted: #647068;
    --color-border: #d8ded9;
    --color-primary: #166534;
    --color-primary-dark: #0f4f28;
    --color-primary-soft: #edf6ef;
    --color-accent: #166534;
    --color-accent-soft: #edf6ef;
    --bg: var(--color-bg);
    --panel: var(--color-surface);
    --panel-2: var(--color-surface-soft);
    --text: var(--color-text);
    --muted: var(--color-muted);
    --line: var(--color-border);
    --good: #17211b;
    --danger: #dc2626;
    --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
    --text-xs: 13px;
    --text-sm: 14px;
    --text-md: 15px;
    --text-base: 16px;
    --text-lg: 18px;
    --text-xl: 22px;
    --text-2xl: 24px;
    --text-display-mobile: 32px;
    --text-display: 34px;
    --weight-normal: 400;
    --weight-medium: 650;
    --weight-semibold: 700;
    --weight-bold: 800;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.4;
    background: var(--color-bg);
    color: var(--text);
}

.app {
    max-width: 1120px;
    margin: 0 auto;
    padding: 24px 28px 32px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-wrap {
    width: 46px;
    height: 38px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--color-surface);
    box-shadow: inset 3px 0 0 var(--color-primary);
}

.logo-fallback {
    display: inline-grid;
    place-items: center;
    color: var(--color-text);
    font-size: 16px;
    font-weight: var(--weight-bold);
    letter-spacing: -0.04em;
}

h1 {
    margin: 0;
    color: var(--text);
    font-size: 28px;
    font-weight: var(--weight-bold);
    line-height: 1;
    letter-spacing: -0.035em;
}

header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: var(--text-md);
    line-height: 1.3;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

.pill {
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 7px 9px;
    background: transparent;
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    white-space: nowrap;
}

button,
.button-link,
select,
input {
    font-family: inherit;
}

button,
.button-link {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 9px 12px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

button:hover,
.button-link:hover {
    color: var(--text);
}

.ui-icon {
    width: 17px;
    height: 17px;
    display: block;
    flex: 0 0 auto;
    stroke: currentColor;
}

.dashboard-return-link {
    gap: 8px;
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-surface);
    font-weight: var(--weight-bold);
}

.dashboard-return-link:hover,
.dashboard-return-link:focus-visible {
    border-color: var(--color-primary-dark);
    color: #ffffff;
    background: var(--color-primary-dark);
}

.primary-button,
#calculateBtn,
#calculateTimeBtn {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #ffffff;
    font-weight: var(--weight-bold);
}

.primary-button:hover,
#calculateBtn:hover,
#calculateTimeBtn:hover {
    border-color: var(--color-primary-dark);
    background: var(--color-primary-dark);
    color: #ffffff;
}

.secondary-button {
    border-color: var(--line);
    background: transparent;
    color: var(--text);
}

.secondary-button:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
}

button:focus-visible,
.button-link:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

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

.tab-nav {
    display: flex;
    gap: 0;
    overflow-x: auto;
    margin-bottom: 12px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--color-surface);
    box-shadow: none;
}

.tab-button {
    flex: 1;
    min-width: 180px;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
}

.tab-button:last-child {
    border-right: 0;
}

.tab-button:hover,
.tab-button.active {
    border-color: var(--line);
    background: var(--color-primary-soft);
    color: var(--text);
}

.tab-button.active {
    color: var(--color-primary);
    box-shadow: inset 0 -3px 0 var(--color-primary);
}

.tab-panel {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--color-surface);
    box-shadow: none;
}

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

.layout {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 12px;
    align-items: start;
    padding: 14px;
}

.card {
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--panel);
    padding: 16px;
    box-shadow: none;
}

h2 {
    margin: 0 0 14px;
    padding-bottom: 9px;
    border-bottom: 1px solid var(--line);
    color: var(--color-primary);
    font-size: 12px;
    font-weight: var(--weight-bold);
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 13px;
}

label {
    color: var(--muted);
    font-size: 12px;
    font-weight: var(--weight-bold);
    line-height: 1.2;
    letter-spacing: 0.025em;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    min-height: 44px;
    border-radius: 4px;
    padding: 9px 10px;
    background: var(--color-surface);
    color: var(--text);
    font-size: var(--text-base);
    line-height: 1.25;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--color-primary);
    box-shadow: none;
}

select option {
    background: var(--color-surface);
    color: var(--text);
}

.custom-distance,
.custom-pace-box {
    margin-top: 4px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--color-surface-soft);
}

.button-row,
.time-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 13px;
}

.button-row button,
.time-actions button,
#customPaceBtn,
#sendResultBtn,
.pace-toggle-button {
    flex: 1 1 auto;
}

#customPaceBtn,
#sendResultBtn {
    width: 100%;
}

.hidden {
    display: none !important;
}

.error {
    min-height: 19px;
    margin: 12px 0 0;
    color: var(--danger);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.pace-card {
    border-color: var(--line);
    background: var(--color-surface);
}

.pace-box {
    display: grid;
    gap: 10px;
}

.pace-box p,
.results-summary {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

.pace-toggle-button {
    width: 100%;
    margin-top: 14px;
}

.pace-reminder {
    margin: 0 0 14px;
    color: var(--color-accent);
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
}

.pace-distance-row {
    display: grid;
    grid-template-columns: 1fr 130px;
    gap: 12px;
}

.pace-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
}

.pace-item:last-child {
    border-bottom: 0;
}

.pace-label {
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
}

.pace-value {
    color: var(--good);
    font-size: 16px;
    font-weight: var(--weight-bold);
}

.results-card {
    margin: 0 14px 14px;
}

#results:empty::before {
    content: "Calculate a workout or race to see split output.";
    display: block;
    padding: 18px 8px;
    border: 0;
    border-left: 3px solid var(--line);
    border-radius: 0;
    background: var(--color-surface-soft);
    color: var(--muted);
    text-align: center;
}

.time-card {
    margin: 14px;
    max-width: 760px;
}

.time-rows {
    display: grid;
    gap: 8px;
}

.time-row {
    display: grid;
    grid-template-columns: 150px 1fr 112px;
    gap: 10px;
    align-items: center;
}

.time-row select,
.time-row input,
.remove-time-row {
    margin: 0;
}

.remove-time-row {
    border-color: var(--line);
    background: var(--color-surface);
    color: var(--muted);
}

.remove-time-row:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-soft);
    color: var(--text);
}

.time-result {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    margin: 14px 0 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--color-primary);
    border-radius: 3px;
    background: var(--color-accent-soft);
}

.time-result-label {
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

.time-result-value {
    color: var(--good);
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
}

table {
    width: 100%;
    overflow: hidden;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--color-surface);
}

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

tr:last-child td {
    border-bottom: 0;
}

th {
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
}

td {
    color: var(--good);
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
}

@media (max-width: 800px) {
    .app {
        padding: 10px;
    }

    header,
    .layout,
    .time-row,
    .pace-distance-row {
        display: block;
    }

    header {
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    .brand {
        gap: 10px;
    }

    .logo-wrap {
        width: 42px;
        height: 34px;
    }

    .header-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
        margin-top: 10px;
        gap: 7px;
    }

    .dashboard-return-link {
        justify-content: flex-start;
        min-width: 0;
        white-space: normal;
    }

    .header-actions .pill { display: none; }

    .tab-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        border-radius: 4px;
    }

    .tab-button {
        min-width: 0;
        width: 100%;
        min-height: 44px;
        padding: 8px 7px;
        font-size: 13px;
    }

    .layout,
    .time-card {
        padding: 10px;
    }

    .input-card,
    .pace-card {
        margin-bottom: 10px;
    }

    .results-card,
    .time-card {
        margin: 0 10px 10px;
    }

    .time-row select,
    .time-row input,
    .remove-time-row {
        margin-bottom: 10px;
        width: 100%;
    }

    .button-row,
    .time-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 24px;
    }

    header p {
        margin-top: 3px;
        font-size: 13px;
    }

    .card {
        padding: 13px;
    }

    h2 {
        margin-bottom: 11px;
        padding-bottom: 7px;
    }

    .form-row {
        margin-bottom: 11px;
    }

    .time-actions {
        gap: 8px;
    }

    table {
        display: table;
        min-width: 0;
    }

    th,
    td {
        padding: 8px;
        font-size: 13px;
    }
}
