:root {
    --bg: #f3f5f8;
    --card: #ffffff;
    --text: #172033;
    --muted: #697386;
    --primary: #3157d5;
    --primary-dark: #2445b2;
    --border: #e2e6ee;
    --green: #16845b;
    --red: #c73b45;
    --forecast: #8a95aa;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.login-page {
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: min(100%, 410px);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 32px;
    box-shadow: 0 16px 45px rgba(24, 34, 55, .08);
}

.scale-logo {
    width: 110px;
    margin: 0 auto 10px;
    color: var(--primary);
}

.scale-logo svg { display: block; width: 100%; }

h1, h2, p { margin-top: 0; }
h1 { font-size: 28px; margin-bottom: 5px; text-align: center; }
h2 { font-size: 20px; margin-bottom: 4px; }

.subtitle {
    color: var(--muted);
    text-align: center;
    margin-bottom: 28px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 650;
    margin: 16px 0 7px;
}

input, select, button {
    width: 100%;
    min-height: 48px;
    border-radius: 12px;
    font: inherit;
}

input, select {
    border: 1px solid #ccd2dc;
    background: white;
    padding: 10px 13px;
    color: var(--text);
}

input:focus, select:focus {
    outline: 3px solid rgba(49,87,213,.14);
    border-color: var(--primary);
}

button {
    border: 0;
    cursor: pointer;
    font-weight: 700;
}

.primary {
    background: var(--primary);
    color: white;
    margin-top: 20px;
}

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

.error {
    background: #fff0f1;
    border: 1px solid #ffc8cc;
    color: #a82832;
    border-radius: 12px;
    padding: 11px 13px;
    font-size: 14px;
    margin-bottom: 15px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 15px max(18px, calc((100vw - 1050px) / 2));
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.goal {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

.logout {
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 650;
}

.container {
    width: min(100% - 28px, 1050px);
    margin: 22px auto 50px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 22px;
    margin-bottom: 16px;
    box-shadow: 0 5px 22px rgba(24, 34, 55, .035);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.weight-input {
    position: relative;
}

.weight-input input {
    padding-right: 48px;
}

.weight-input span {
    position: absolute;
    right: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.form-message {
    min-height: 22px;
    margin-top: 10px;
    font-size: 14px;
}

.success { color: var(--green); }
.error-inline { color: var(--red); }

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.muted {
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 0;
}

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

.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.dot.actual { background: var(--primary); }
.dot.forecast { background: var(--forecast); }

.chart-wrap {
    width: 100%;
    overflow: hidden;
    margin-top: 15px;
}

#chart {
    width: 100%;
    height: auto;
    display: block;
}

.grid { stroke: #e9edf3; stroke-width: 1; }
.axis-label { fill: #7b8494; font-size: 13px; }
.goal-line { stroke: #16845b; stroke-width: 2; stroke-dasharray: 7 6; opacity: .75; }
.goal-label { fill: #16845b; font-size: 13px; font-weight: 650; }
.actual-line { fill: none; stroke: #3157d5; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.actual-point { fill: white; stroke: #3157d5; stroke-width: 3; }
.forecast-line { fill: none; stroke: #8a95aa; stroke-width: 3; stroke-dasharray: 8 7; stroke-linecap: round; }
.chart-empty { fill: #697386; font-size: 18px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.stat {
    margin: 0;
}

.stat span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.stat strong {
    font-size: 22px;
}

.stat .down, .down { color: var(--green); }
.stat .up, .up { color: var(--red); }

.highlight {
    border-color: #cad5ff;
    background: #f7f8ff;
}

.motivation {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.motivation-icon {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: #eef1ff;
    color: var(--primary);
    font-size: 20px;
}

.motivation p { margin-bottom: 0; line-height: 1.5; }

.history-list {
    border-top: 1px solid var(--border);
    margin-top: 15px;
}

.history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 48px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.history-row strong { font-size: 15px; }
.empty { color: var(--muted); padding: 15px 0; }

@media (max-width: 700px) {
    .topbar {
        padding-left: 14px;
        padding-right: 14px;
    }

    .container {
        width: min(100% - 20px, 1050px);
        margin-top: 12px;
    }

    .card {
        padding: 17px;
        border-radius: 15px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .section-heading {
        display: block;
    }

    .legend {
        margin-top: 10px;
    }

    .chart-wrap {
        margin-left: -7px;
        width: calc(100% + 14px);
    }
}

@media (max-width: 380px) {
    .login-card { padding: 24px 19px; }
    .stats-grid { grid-template-columns: 1fr; }
}
