:root {
    --bg: #f3f6fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #7b8497;
    --line: #e7ebf2;
    --track: #edf0f5;

    --orange: #ff7a20;
    --green: #16b45b;
    --blue: #4b69ff;
    --red: #ef4444;

    --radius-xl: 24px;
    --radius-lg: 18px;
    --shadow: 0 14px 35px rgba(26, 39, 74, .08);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(75, 105, 255, .08), transparent 28%),
        var(--bg);
    color: var(--text);
}

button, input {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    width: min(1480px, calc(100% - 40px));
    margin: 0 auto;
    padding: 28px 0 50px;
}

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

.eyebrow,
.card-kicker {
    display: block;
    margin: 0 0 6px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .14em;
    color: var(--muted);
}

h1, h2, p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(28px, 4vw, 42px);
    letter-spacing: -.04em;
}

h2 {
    margin-bottom: 0;
    font-size: 20px;
    letter-spacing: -.02em;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.datetime-card {
    min-width: 270px;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, .8);
    backdrop-filter: blur(14px);
    box-shadow: 0 8px 24px rgba(26, 39, 74, .05);
}

.datetime-card span,
.datetime-card strong,
.datetime-card small {
    display: block;
}

.datetime-card span {
    color: var(--muted);
    font-size: 13px;
}

.datetime-card strong {
    margin-top: 2px;
    font-size: 21px;
    letter-spacing: .04em;
}

.datetime-card small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

.btn {
    border: 0;
    border-radius: 14px;
    padding: 13px 18px;
    font-weight: 800;
    transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    color: white;
    background: linear-gradient(135deg, #516eff, #3955e8);
    box-shadow: 0 10px 20px rgba(75, 105, 255, .22);
}

.btn-full {
    width: 100%;
    margin-top: 8px;
}

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

.card {
    background: rgba(255, 255, 255, .95);
    border: 1px solid rgba(222, 228, 239, .95);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.gauge-card,
.weight-card {
    min-height: 430px;
    padding: 24px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 99px;
    margin-top: 7px;
    box-shadow: 0 0 0 5px rgba(0,0,0,.03);
}

.status-orange { background: var(--orange); }
.status-green { background: var(--green); }
.status-blue { background: var(--blue); }

.gauge {
    --progress: 0deg;
    --gauge-color: var(--blue);
    width: 230px;
    aspect-ratio: 1;
    margin: 30px auto 20px;
    border-radius: 50%;
    position: relative;
    display: grid;
    place-items: center;
    background:
        conic-gradient(
            from -90deg,
            var(--gauge-color) 0deg,
            var(--gauge-color) var(--progress),
            var(--track) var(--progress),
            var(--track) 360deg
        );
    box-shadow:
        inset 0 0 0 1px rgba(30, 40, 70, .03),
        0 16px 34px rgba(25, 35, 65, .09);
}

.gauge::before {
    content: "";
    position: absolute;
    inset: 20px;
    background: white;
    border-radius: 50%;
    border: 1px solid var(--line);
    box-shadow: inset 0 0 0 7px rgba(247,249,252,.9);
}

.gauge-center {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.gauge-value {
    font-size: 40px;
    font-weight: 900;
    letter-spacing: -.05em;
}

.gauge-unit {
    margin-top: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.gauge-caption {
    margin-top: 10px;
    border-radius: 999px;
    padding: 6px 9px;
    background: #f5f7fa;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.gauge-orange { --gauge-color: var(--orange); }
.gauge-green { --gauge-color: var(--green); }
.gauge-blue { --gauge-color: var(--blue); }

.gauge-small {
    width: 178px;
    margin: 18px 0 0 auto;
}

.gauge-small::before {
    inset: 16px;
}

.gauge-small .gauge-value {
    font-size: 30px;
}

.goal-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    color: var(--muted);
}

.goal-row strong {
    color: var(--text);
}

.weight-layout {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 14px;
    margin-top: 24px;
}

.weight-numbers {
    display: grid;
    gap: 22px;
}

.weight-numbers span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.weight-numbers strong {
    font-size: 30px;
    letter-spacing: -.04em;
}

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

.chart-card {
    margin-top: 20px;
    padding: 24px;
}

.chart-header {
    align-items: center;
}

.chart-legend {
    display: flex;
    gap: 18px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

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

.legend-line,
.legend-goal {
    display: inline-block;
    width: 22px;
    height: 3px;
    border-radius: 99px;
    background: var(--blue);
}

.legend-goal {
    background: transparent;
    border-top: 2px dashed #a1a8b6;
}

.chart-wrap {
    position: relative;
    margin-top: 12px;
    min-height: 340px;
}

#weightChart {
    display: block;
    width: 100%;
    height: 340px;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    text-align: center;
}

.hidden {
    display: none !important;
}

.history-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.history-grid .card {
    padding: 24px;
}

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

.history-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fbfcfe;
}

.history-main strong,
.history-main span {
    display: block;
}

.history-main span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.history-value {
    font-weight: 900;
}

.delete-btn {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 9px;
    color: var(--red);
    background: #fff1f1;
    font-weight: 900;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(20, 28, 45, .28);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}

.drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    width: min(440px, 100%);
    padding: 26px;
    background: white;
    box-shadow: -24px 0 50px rgba(24, 35, 70, .15);
    transform: translateX(105%);
    transition: transform .25s ease;
    overflow-y: auto;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: white;
    color: var(--text);
    font-size: 24px;
    line-height: 1;
}

.tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin: 26px 0 18px;
    padding: 5px;
    border-radius: 14px;
    background: #f3f5f9;
}

.tab {
    border: 0;
    border-radius: 10px;
    padding: 10px 8px;
    background: transparent;
    color: var(--muted);
    font-weight: 800;
}

.tab.active {
    background: white;
    color: var(--text);
    box-shadow: 0 4px 12px rgba(24, 35, 70, .07);
}

.tab-panel {
    display: none;
}

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

form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-size: 13px;
    font-weight: 800;
}

input {
    width: 100%;
    border: 1px solid #dfe4ec;
    border-radius: 13px;
    padding: 12px 13px;
    outline: 0;
    background: #fff;
    color: var(--text);
    transition: border-color .16s ease, box-shadow .16s ease;
}

input:focus {
    border-color: #7890ff;
    box-shadow: 0 0 0 4px rgba(75, 105, 255, .10);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 80;
    transform: translate(-50%, 20px);
    min-width: min(420px, calc(100% - 32px));
    padding: 13px 16px;
    border-radius: 13px;
    color: white;
    background: #1d2638;
    box-shadow: 0 16px 30px rgba(20, 28, 45, .2);
    opacity: 0;
    pointer-events: none;
    transition: .2s ease;
    text-align: center;
    font-weight: 700;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.toast.error {
    background: #b42318;
}

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

    .weight-card {
        grid-column: 1 / -1;
        min-height: auto;
    }

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

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 24px, 1480px);
        padding-top: 18px;
    }

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

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

    .datetime-card {
        min-width: 0;
    }

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

    .weight-card {
        grid-column: auto;
    }

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

    .gauge-small {
        margin: 8px auto 0;
    }

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

    .chart-legend {
        margin-top: 8px;
    }

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