:root {
    --bg: #f4f7f8;
    --surface: #ffffff;
    --surface-strong: #eef4f3;
    --text: #13201f;
    --muted: #667775;
    --line: #d9e3e1;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --accent: #b45309;
    --danger: #b42318;
    --success: #15803d;
    --shadow: 0 18px 50px rgba(19, 32, 31, 0.1);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0;
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

.language-switcher {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin: 0;
}

.language-switcher a {
    min-width: 40px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.language-switcher a.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 24px;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    min-height: 72px;
    margin-bottom: 24px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 28px rgba(19, 32, 31, 0.07);
}

.site-brand {
    display: block;
    flex: 0 0 auto;
    line-height: 0;
}

.site-brand img {
    width: 166px;
    height: auto;
    display: block;
}

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

.site-header-actions form {
    margin: 0;
}

.page-heading {
    margin-bottom: 22px;
}

.page-heading h1 {
    margin: 0;
    font-size: 36px;
    line-height: 1.1;
}

.auth-layout {
    min-height: calc(100vh - 150px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 430px;
    gap: 32px;
    align-items: center;
}

.auth-intro h1,
.topbar h1,
.page-heading h1 {
    margin: 0;
    font-size: 42px;
    line-height: 1.06;
}

.auth-intro p {
    max-width: 560px;
    margin: 18px 0 22px;
    color: var(--muted);
    font-size: 18px;
    line-height: 1.55;
}

.brand-logo {
    width: 220px;
    height: auto;
    display: block;
    margin-bottom: 20px;
}

.topbar-logo {
    width: 154px;
    height: auto;
    display: block;
    margin-bottom: 10px;
}

.feature-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--text);
}

.feature-list li {
    padding-left: 20px;
    position: relative;
}

.feature-list li::before {
    content: "";
    width: 7px;
    height: 7px;
    position: absolute;
    top: 8px;
    left: 0;
    border-radius: 50%;
    background: var(--primary);
}

.seo-content {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-top: 28px;
    padding: 24px 0 4px;
    border-top: 1px solid var(--line);
}

.seo-content h2 {
    margin: 0 0 10px;
    font-size: 20px;
    line-height: 1.25;
}

.seo-content p,
.seo-content ul {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.seo-content ul {
    display: grid;
    gap: 8px;
    padding-left: 18px;
}

.auth-panel,
.entry-form,
.account-panel,
.chart-panel,
.history-panel,
.metric-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-panel {
    padding: 22px;
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 4px;
    margin-bottom: 18px;
    background: var(--surface-strong);
    border-radius: 8px;
}

.tab-button {
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.tab-button.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(19, 32, 31, 0.08);
}

.auth-form {
    display: none;
}

.auth-form.is-active,
.entry-form {
    display: grid;
    gap: 16px;
}

.form-copy {
    display: grid;
    gap: 6px;
}

.form-copy strong {
    font-size: 18px;
}

.form-copy p {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

label {
    display: grid;
    gap: 7px;
}

label span {
    color: var(--muted);
    font-size: 14px;
}

input, textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid #0d736b;
    border-radius: 8px;
    background: #faffff;
    color: var(--text);
    padding: 11px 12px;
    outline: none;
}

textarea {
    resize: vertical;
    line-height: 1.45;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.password-field {
    position: relative;
    display: block;
}

.password-field input {
    padding-right: 128px;
}

.password-toggle {
    min-width: 104px;
    min-height: 34px;
    position: absolute;
    top: 6px;
    right: 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface-strong);
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

.field-note {
    margin: -6px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
}

.button-primary {
    background: var(--primary);
    color: #ffffff;
}

.button-primary:hover {
    background: var(--primary-dark);
}

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

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

.link-button {
    width: fit-content;
    min-height: 26px;
    border: 0;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    font-weight: 700;
    padding: 0;
    text-align: left;
}

.alert {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.alert-success {
    border-color: rgba(21, 128, 61, 0.28);
    color: var(--success);
}

.alert-danger {
    border-color: rgba(180, 35, 24, 0.28);
    color: var(--danger);
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 22px;
}

.topbar-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.eyebrow {
    margin-bottom: 5px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric-card {
    display: grid;
    gap: 7px;
    padding: 18px;
    background-color: var(--surface);

    background-repeat: no-repeat;
    background-position: right center;
    background-size: 170px 85px;
    box-shadow: none;
}

.metric-card-last {
    background-image: url("/assets/metric-last.svg");
}

.metric-card-average {
    background-image: url("/assets/metric-average.svg");
}

.metric-card-pulse {
    background-image: url("/assets/metric-pulse.svg");
}

.metric-card-records {
    background-image: url("/assets/metric-records.svg");
}
.metric-card span,
.metric-card small {
    color: var(--muted);
}

.metric-card strong {
    font-size: 28px;
    line-height: 1;
}

.workspace {
    display: block;
    min-width: 0;
}

.dashboard-content {
    display: grid;
    grid-template-columns: 390px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.entry-form-main {
    margin-bottom: 0;
    scroll-margin-top: 16px;
}

.workspace .history-panel {
    max-height: 428px;
    overflow-y: auto;
}

.reset-layout {
    min-height: calc(100vh - 94px);
    display: grid;
    place-items: center;
}

.reset-panel {
    width: min(430px, 100%);
    padding: 22px;
}

.reset-panel h1 {
    margin: 0 0 18px;
    font-size: 30px;
}

.entry-form,
.account-panel,
.chart-panel,
.history-panel {
    padding: 18px;
}

.chart-panel {
    display: grid;
    grid-column: 1 / -1;
    gap: 14px;
    margin-bottom: 0;
}

.segmented-control {
    display: inline-grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
    border-radius: 8px;
    background: var(--surface-strong);
}

.segmented-control button {
    min-height: 34px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    padding: 7px 10px;
    white-space: nowrap;
}

.segmented-control button.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(19, 32, 31, 0.08);
}

.chart-wrap {
    position: relative;
    width: 100%;
    min-height: 320px;
}

.chart-wrap canvas {
    width: 100%;
    height: 320px;
    display: block;
}

.chart-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    pointer-events: none;
}

.chart-empty[hidden] {
    display: none;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    color: var(--muted);
    font-size: 13px;
}

.chart-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chart-legend i {
    width: 10px;
    height: 10px;
    display: inline-block;
    border-radius: 50%;
}

.legend-systolic {
    background: #b42318;
}

.legend-diastolic {
    background: #0f766e;
}

.legend-pulse {
    background: #2563eb;
}

.account-panel {
    display: grid;
    gap: 18px;
}

.account-page-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
}

.account-form {
    display: grid;
    gap: 12px;
}

.section-subheading {
    color: var(--text);
    font-weight: 700;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 2px;
}

.section-heading h2 {
    margin: 0;
    font-size: 20px;
}

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

.full-width {
    grid-column: 1 / -1;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.is-muted {
    background: var(--surface-strong);
    color: var(--muted);
}

.is-normal {
    background: rgba(21, 128, 61, 0.12);
    color: var(--success);
}

.is-raised {
    background: rgba(180, 83, 9, 0.14);
    color: var(--accent);
}

.is-high {
    background: rgba(180, 35, 24, 0.12);
    color: var(--danger);
}

.is-low {
    background: rgba(2, 132, 199, 0.12);
    color: #0369a1;
}

.empty-state {
    padding: 34px 16px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    text-align: center;
}

.empty-state p {
    max-width: 420px;
    margin: 8px auto 0;
    color: var(--muted);
    line-height: 1.45;
}

.history-list {
    display: grid;
    gap: 10px;
}

.history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.edit-measurement-form {
    grid-column: 1 / -1;
    display: grid;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.edit-measurement-form[hidden] {
    display: none;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.history-main {
    min-width: 0;
}

.history-main time {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
}

.history-main strong {
    display: block;
    font-size: 20px;
}

.history-main strong span {
    color: var(--muted);
    font-size: 14px;
    font-weight: 400;
}

.history-main p {
    margin: 8px 0 0;
    color: var(--muted);
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.history-actions {
    display: flex;
    align-items: start;
    gap: 8px;
}

.icon-button {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
}

.icon-button:hover {
    color: var(--danger);
    border-color: rgba(180, 35, 24, 0.3);
}

.edit-button:hover {
    color: var(--primary);
    border-color: rgba(15, 118, 110, 0.3);
}

@media (max-width: 920px) {
    .auth-layout,
    .workspace,
    .account-page-grid {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .workspace .history-panel {
        max-height: none;
        overflow-y: visible;
    }

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

@media (max-width: 800px) {
    .site-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px 8px;
        min-height: 62px;
        margin-bottom: 18px;
        padding: 8px 10px;
    }

    .site-brand img {
        width: 138px;
    }

    .site-header-tools {
        display: contents;
    }

    .language-switcher {
        grid-column: 2;
    }

    .language-switcher a {
        min-width: 34px;
        min-height: 32px;
        padding: 0 6px;
    }

    .site-header-actions {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
    }

    .site-header-actions .button,
    .site-header-actions form,
    .site-header-actions form .button {
        width: 100%;
    }

    .site-header-dashboard .site-header-actions > .button:first-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 640px) {
    .app-shell {
        padding: 16px;
    }

    .auth-layout {
        min-height: auto;
        align-items: start;
    }

    .auth-intro h1,
    .topbar h1,
    .page-heading h1 {
        font-size: 30px;
    }

    .brand-logo {
        width: 190px;
    }

    .topbar-logo {
        width: 136px;
    }

    .auth-intro p {
        font-size: 16px;
    }

    .topbar {
        align-items: start;
        flex-direction: column;
    }

    .topbar-actions {
        width: 100%;
        justify-content: stretch;
    }

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

    .topbar-actions form .button {
        width: 100%;
    }

    .chart-panel .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .segmented-control {
        width: 100%;
    }

    .segmented-control button {
        padding-left: 6px;
        padding-right: 6px;
    }

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

    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .metric-card {
        min-height: 118px;
        padding: 14px;
        background-position: calc(100% + 18px) center;
        background-size: 145px 73px;
    }

    .metric-card strong {
        font-size: 24px;
    }

    .metric-card small {
        overflow: hidden;
        font-size: 12px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

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

    .history-actions {
        justify-content: space-between;
    }
}

.offline-layout {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

.offline-panel {
    width: min(440px, 100%);
}

.offline-panel h1 {
    margin: 0 0 12px;
    font-size: 30px;
}

.offline-panel p {
    margin: 0 0 20px;
    color: var(--muted);
    line-height: 1.55;
}

.history-toggle {
    display: none;
    width: 100%;
    margin-top: 12px;
}

@media (max-width: 920px) {
    .history-list:not(.is-expanded) .history-item:nth-child(n + 4) {
        display: none;
    }

    .history-toggle {
        display: inline-flex;
    }
}