:root {
    color-scheme: dark;
    --bg: #0a0d0c;
    --surface: #111513;
    --surface-2: #171c19;
    --surface-3: #202720;
    --text: #f5f7f4;
    --muted: #8d9990;
    --border: rgba(255, 255, 255, .09);
    --accent: #b8f34a;
    --accent-strong: #9dde24;
    --accent-soft: rgba(184, 243, 74, .12);
    --orange: #ff9d57;
    --blue: #65c8ff;
    --danger: #ff6b6b;
    --shadow: 0 24px 64px rgba(0, 0, 0, .28);
    --radius: 22px;
    --sidebar: 248px;
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #eef1eb;
    --surface: #ffffff;
    --surface-2: #f7f9f5;
    --surface-3: #e9eee5;
    --text: #172017;
    --muted: #6d786e;
    --border: rgba(23, 32, 23, .1);
    --accent: #6f9f13;
    --accent-strong: #5c8610;
    --accent-soft: rgba(111, 159, 19, .12);
    --orange: #d96e22;
    --blue: #1688c1;
    --danger: #cf3e3e;
    --shadow: 0 22px 60px rgba(45, 60, 42, .12);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 82% -10%, rgba(184, 243, 74, .08), transparent 28rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

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

svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    display: flex;
    width: var(--sidebar);
    flex-direction: column;
    padding: 28px 20px 20px;
    border-right: 1px solid var(--border);
    background: rgba(10, 13, 12, .86);
    backdrop-filter: blur(20px);
}

[data-theme="light"] .sidebar {
    background: rgba(255, 255, 255, .84);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 0 7px 28px;
}

.brand-mark {
    display: grid;
    width: 39px;
    height: 39px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 13px;
    background: var(--accent);
    color: #172009;
    box-shadow: 0 10px 30px rgba(184, 243, 74, .18);
}

.brand-mark svg {
    width: 23px;
    height: 23px;
}

.brand-copy {
    min-width: 0;
}

.brand-copy strong,
.brand-copy span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-copy strong {
    font-size: 15px;
    letter-spacing: -.02em;
}

.brand-copy span {
    margin-top: 1px;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .12em;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 13px;
    border-radius: 13px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 650;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface-2);
}

.nav-link.active {
    color: var(--text);
    background: var(--accent-soft);
}

.nav-link.active svg {
    color: var(--accent);
}

.sidebar-foot {
    margin-top: auto;
    padding: 18px 6px 0;
}

.mini-goal {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface-2);
}

.mini-goal-label {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 12px;
}

.progress-track {
    height: 6px;
    margin-top: 11px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-3);
}

.progress-bar {
    display: block;
    width: var(--progress, 0%);
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.main {
    min-height: 100vh;
    margin-left: var(--sidebar);
    padding: 30px clamp(24px, 4vw, 58px) 48px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .13em;
}

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

h1 {
    margin-bottom: 0;
    font-size: clamp(26px, 3vw, 38px);
    line-height: 1.08;
    letter-spacing: -.045em;
}

h2 {
    margin-bottom: 5px;
    font-size: 18px;
    letter-spacing: -.025em;
}

.page-subtitle,
.card-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.date-pill {
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

.mobile-brand {
    display: none;
}

.grid {
    display: grid;
    gap: 18px;
}

.grid-summary {
    grid-template-columns: minmax(280px, 1.25fr) repeat(2, minmax(170px, .72fr));
}

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

.grid-charts {
    grid-template-columns: minmax(0, 1.55fr) minmax(280px, .85fr);
}

.card {
    min-width: 0;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .015);
}

.card-accent {
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(130deg, rgba(184, 243, 74, .15), transparent 52%),
        var(--surface);
}

.card-accent::after {
    position: absolute;
    top: -55px;
    right: -45px;
    width: 160px;
    height: 160px;
    border: 1px solid rgba(184, 243, 74, .15);
    border-radius: 50%;
    content: "";
}

.summary-content {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.summary-number {
    margin: 12px 0 4px;
    font-size: clamp(38px, 6vw, 62px);
    font-weight: 760;
    line-height: 1;
    letter-spacing: -.06em;
}

.summary-unit {
    color: var(--muted);
    font-size: 13px;
}

.goal-ring {
    --ring-progress: 0deg;
    position: relative;
    display: grid;
    width: 104px;
    height: 104px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    background: conic-gradient(var(--accent) var(--ring-progress), var(--surface-3) 0);
}

.goal-ring::after {
    position: absolute;
    width: 78px;
    height: 78px;
    border-radius: 50%;
    background: var(--surface);
    content: "";
}

.goal-ring span {
    position: relative;
    z-index: 1;
    font-size: 17px;
    font-weight: 800;
}

.metric-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 156px;
}

.metric-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.metric-icon {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 11px;
    background: var(--accent-soft);
    color: var(--accent);
}

.metric-icon.orange {
    background: rgba(255, 157, 87, .12);
    color: var(--orange);
}

.metric-value {
    margin: 14px 0 0;
    font-size: 27px;
    font-weight: 760;
    letter-spacing: -.04em;
}

.metric-value small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0;
}

.section-space {
    margin-top: 18px;
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 20px;
}

.card-icon-title {
    display: flex;
    gap: 13px;
}

.action-icon {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 13px;
    background: var(--accent-soft);
    color: var(--accent);
}

.action-icon.orange {
    background: rgba(255, 157, 87, .11);
    color: var(--orange);
}

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

.field {
    min-width: 0;
}

.field-grow {
    flex: 1;
}

label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 47px;
    padding: 0 14px;
    border: 1px solid var(--border);
    outline: 0;
    border-radius: 13px;
    background: var(--surface-2);
    color: var(--text);
    transition: border .18s ease, box-shadow .18s ease;
}

input:focus,
select:focus {
    border-color: rgba(184, 243, 74, .55);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

input::placeholder {
    color: color-mix(in srgb, var(--muted) 72%, transparent);
}

input[type="number"] {
    font-variant-numeric: tabular-nums;
}

.input-unit {
    position: relative;
}

.input-unit input {
    padding-right: 60px;
}

.input-unit span {
    position: absolute;
    top: 50%;
    right: 14px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    transform: translateY(-50%);
}

.btn {
    display: inline-flex;
    min-height: 47px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 18px;
    border: 0;
    border-radius: 13px;
    background: var(--accent);
    color: #18200d;
    cursor: pointer;
    font-weight: 800;
    transition: background .18s ease, transform .18s ease;
}

.btn:hover {
    background: var(--accent-strong);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--surface-3);
}

.btn-danger {
    border: 1px solid rgba(255, 107, 107, .2);
    background: rgba(255, 107, 107, .08);
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(255, 107, 107, .16);
}

.btn-icon {
    width: 39px;
    min-height: 39px;
    padding: 0;
    border-radius: 11px;
}

.btn-icon svg {
    width: 17px;
    height: 17px;
}

.chart-wrap {
    position: relative;
    height: 270px;
}

.chart-wrap.compact {
    height: 220px;
}

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

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

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

.legend i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.legend i.orange {
    background: var(--orange);
}

.legend i.blue {
    background: var(--blue);
}

.tabs {
    display: flex;
    gap: 6px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface-2);
}

.tab {
    padding: 7px 11px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    font-weight: 750;
}

.tab.active {
    background: var(--surface-3);
    color: var(--text);
}

.flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
    padding: 13px 16px;
    border: 1px solid rgba(184, 243, 74, .2);
    border-radius: 14px;
    background: var(--accent-soft);
    color: var(--text);
    font-size: 13px;
}

.flash.error {
    border-color: rgba(255, 107, 107, .2);
    background: rgba(255, 107, 107, .09);
}

.flash-close {
    border: 0;
    background: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

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

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

.entry-row {
    display: grid;
    grid-template-columns: minmax(110px, .65fr) minmax(175px, 1fr) auto;
    gap: 10px;
    align-items: end;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--surface-2);
}

.entry-row.weight-row {
    grid-template-columns: minmax(110px, .65fr) minmax(145px, 1fr) auto;
}

.entry-actions {
    display: flex;
    gap: 7px;
    padding-bottom: 4px;
}

.empty-state {
    padding: 40px 20px;
    color: var(--muted);
    text-align: center;
}

.empty-state svg {
    width: 34px;
    height: 34px;
    margin-bottom: 8px;
    color: var(--accent);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 18px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.pagination .btn {
    min-height: 38px;
    padding: 0 13px;
    font-size: 12px;
}

.settings-form {
    display: grid;
    gap: 24px;
}

.form-section {
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.form-section:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.form-section-title {
    margin-bottom: 16px;
}

.form-section-title h3 {
    margin-bottom: 3px;
    font-size: 15px;
}

.form-section-title p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

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

.form-actions {
    display: flex;
    justify-content: flex-end;
}

.login-page {
    display: grid;
    min-height: 100vh;
    grid-template-columns: minmax(300px, .78fr) minmax(440px, 1.22fr);
}

.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 34px;
    background: var(--surface);
}

.login-box {
    width: 100%;
    max-width: 390px;
}

.login-box .brand {
    padding: 0 0 42px;
}

.login-box h1 {
    margin-bottom: 9px;
    font-size: 32px;
}

.login-box > p {
    margin-bottom: 30px;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 16px;
}

.login-form .btn {
    width: 100%;
    margin-top: 5px;
}

.captcha-box {
    position: relative;
    display: flex;
    min-height: 72px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #111513;
}

.captcha-box img {
    display: block;
    width: min(210px, calc(100% - 54px));
    height: 72px;
    object-fit: contain;
}

.captcha-refresh {
    position: absolute;
    top: 50%;
    right: 10px;
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 10px;
    background: rgba(255, 255, 255, .07);
    color: #f5f7f4;
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    transform: translateY(-50%);
}

.captcha-refresh:hover {
    background: rgba(255, 255, 255, .13);
}

.captcha-input {
    letter-spacing: .16em;
    text-align: center;
}

.login-note {
    margin-top: 24px;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
}

.login-visual {
    position: relative;
    display: flex;
    overflow: hidden;
    align-items: flex-end;
    padding: clamp(35px, 7vw, 90px);
    background:
        linear-gradient(150deg, rgba(184, 243, 74, .04), rgba(184, 243, 74, .18)),
        #0d120d;
}

.login-visual::before,
.login-visual::after {
    position: absolute;
    border: 1px solid rgba(184, 243, 74, .16);
    border-radius: 50%;
    content: "";
}

.login-visual::before {
    top: -20vw;
    right: -16vw;
    width: 55vw;
    height: 55vw;
}

.login-visual::after {
    top: 12%;
    right: 8%;
    width: 28vw;
    height: 28vw;
}

.visual-copy {
    position: relative;
    z-index: 1;
    max-width: 570px;
}

.visual-copy p {
    margin-bottom: 13px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .16em;
}

.visual-copy h2 {
    margin: 0;
    font-size: clamp(38px, 5vw, 72px);
    line-height: .98;
    letter-spacing: -.06em;
}

.installer-page {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 30px 18px;
}

.installer-card {
    width: min(720px, 100%);
    padding: clamp(24px, 5vw, 44px);
    border: 1px solid var(--border);
    border-radius: 28px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.installer-head {
    margin-bottom: 30px;
}

.installer-head .brand {
    padding: 0 0 28px;
}

.installer-head h1 {
    font-size: clamp(28px, 5vw, 42px);
}

.installer-head p {
    margin: 10px 0 0;
    color: var(--muted);
}

.footer-note {
    margin: 28px 0 0;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
}

@media (max-width: 1050px) {
    :root {
        --sidebar: 220px;
    }

    .grid-summary {
        grid-template-columns: minmax(270px, 1.2fr) repeat(2, minmax(145px, .7fr));
    }

    .grid-charts {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 800px) {
    body {
        padding-bottom: 72px;
    }

    .sidebar {
        inset: auto 0 0;
        width: auto;
        height: 68px;
        flex-direction: row;
        padding: 7px max(10px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
        border-top: 1px solid var(--border);
        border-right: 0;
    }

    .sidebar .brand,
    .sidebar-foot {
        display: none;
    }

    .nav {
        width: 100%;
        grid-template-columns: repeat(4, 1fr);
        gap: 3px;
    }

    .nav-link {
        min-width: 0;
        flex-direction: column;
        gap: 2px;
        justify-content: center;
        padding: 6px 3px;
        font-size: 9px;
    }

    .nav-link svg {
        width: 20px;
        height: 20px;
    }

    .main {
        margin-left: 0;
        padding: 20px 16px 34px;
    }

    .mobile-brand {
        display: flex;
        align-items: center;
        gap: 9px;
        margin-bottom: 24px;
        font-size: 13px;
        font-weight: 750;
    }

    .mobile-brand .brand-mark {
        width: 32px;
        height: 32px;
        border-radius: 10px;
    }

    .mobile-brand .brand-mark svg {
        width: 19px;
        height: 19px;
    }

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

    .grid-summary .card-accent {
        grid-column: 1 / -1;
    }

    .metric-card {
        min-height: 135px;
    }

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

    .login-page {
        grid-template-columns: 1fr;
    }

    .login-panel {
        min-height: 100vh;
        padding: 28px 20px;
    }

    .login-visual {
        display: none;
    }
}

@media (max-width: 560px) {
    .topbar {
        margin-bottom: 22px;
    }

    .date-pill {
        display: none;
    }

    .card {
        padding: 18px;
        border-radius: 19px;
    }

    .summary-content {
        align-items: flex-end;
    }

    .goal-ring {
        width: 88px;
        height: 88px;
    }

    .goal-ring::after {
        width: 65px;
        height: 65px;
    }

    .goal-ring span {
        font-size: 15px;
    }

    .summary-number {
        font-size: 46px;
    }

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

    .quick-form .btn {
        width: 100%;
    }

    .card-header {
        align-items: flex-start;
    }

    .chart-wrap {
        height: 230px;
    }

    .entry-row,
    .entry-row.weight-row {
        grid-template-columns: 1fr 1fr;
    }

    .entry-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

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

    .form-actions .btn {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
    }
}
