:root {
    --bg: #f6f3ed;
    --panel: #ffffff;
    --panel-soft: #fbfaf7;
    --ink: #232521;
    --muted: #71746e;
    --line: #ded9cf;
    --accent: #1f7a6d;
    --accent-dark: #15594f;
    --income: #126c4e;
    --expense: #b2432d;
    --shadow: 0 18px 45px rgba(36, 32, 24, 0.1);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(31, 122, 109, 0.08), transparent 34%),
        linear-gradient(225deg, rgba(178, 67, 45, 0.08), transparent 30%),
        var(--bg);
    color: var(--ink);
    font-family: "Inter", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    min-height: 42px;
    padding: 0 16px;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.18s ease;
}

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

button:active {
    transform: translateY(1px);
}

input {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 9px 11px;
    outline: none;
}

input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(31, 122, 109, 0.14);
}

label span,
.panel-heading span,
.summary-grid span,
.eyebrow {
    color: var(--muted);
    font-size: 12px;
}

.hidden {
    display: none !important;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid rgba(222, 217, 207, 0.85);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
    display: grid;
    gap: 18px;
}

.login-panel h1,
.topbar h1,
.panel-heading h2 {
    margin: 0;
}

.eyebrow {
    margin: 0 0 6px;
    text-transform: uppercase;
    letter-spacing: 0;
    font-weight: 700;
}

.form-error {
    min-height: 20px;
    margin: 0;
    color: var(--expense);
    font-size: 13px;
}

.app-shell {
    width: min(1480px, 100%);
    max-width: 100%;
    margin: 0 auto;
    padding: 22px;
    overflow-x: hidden;
}

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

.topbar h1 {
    font-size: 28px;
}

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

.top-actions input {
    width: 160px;
}

.month-select-wrap {
    position: relative;
}

.month-picker-button {
    min-width: 150px;
}

.month-picker-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 25;
    width: min(720px, calc(100vw - 44px));
    display: grid;
    grid-template-columns: 108px minmax(0, 1fr);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.picker-shortcuts {
    display: grid;
    align-content: start;
    gap: 2px;
    border-right: 1px solid var(--line);
    padding: 12px 8px;
    background: #fbfaf7;
}

.picker-shortcuts button,
.picker-nav button,
.picker-day {
    min-height: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    padding: 0;
}

.picker-shortcuts button {
    min-height: 30px;
    text-align: left;
    padding: 0 4px;
}

.picker-shortcuts button:hover,
.picker-nav button:hover,
.picker-day:hover {
    background: #eef7f4;
    color: var(--accent-dark);
}

.picker-calendars {
    position: relative;
    padding: 18px 16px 16px;
}

.picker-nav {
    position: absolute;
    inset: 14px 14px auto 14px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

.picker-nav button {
    width: 28px;
    height: 28px;
    pointer-events: auto;
    font-size: 20px;
}

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

.picker-month + .picker-month {
    border-left: 1px solid var(--line);
    padding-left: 22px;
}

.picker-month-title {
    color: #595d5a;
    font-size: 18px;
    line-height: 28px;
    margin-bottom: 12px;
    text-align: center;
}

.picker-weekdays,
.picker-days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.picker-weekdays span {
    height: 28px;
    display: grid;
    place-items: center;
    color: #60655f;
    font-size: 14px;
}

.picker-day {
    width: 100%;
    height: 32px;
    color: #60655f;
    font-size: 14px;
}

.picker-day.muted {
    color: #b7bcb5;
}

.picker-day.in-range {
    background: #8f9290;
    color: #fff;
}

.picker-day.today,
.picker-day.selected {
    background: #606261;
    color: #fff;
    border-radius: 999px;
    font-weight: 700;
}

.ghost-button {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
}

.ghost-button:hover {
    background: var(--panel-soft);
    color: var(--accent-dark);
}

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

.summary-grid article {
    min-height: 116px;
    background: var(--panel);
    border: 1px solid rgba(222, 217, 207, 0.88);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(36, 32, 24, 0.07);
    padding: 18px;
    display: grid;
    align-content: space-between;
}

.summary-grid strong {
    display: block;
    margin: 6px 0;
    font-size: 28px;
    line-height: 1.12;
}

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

.year-panel {
    max-width: 100%;
    min-width: 0;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(222, 217, 207, 0.9);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    padding: 18px;
}

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

.year-summary div {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
    padding: 12px;
}

.year-summary strong {
    display: block;
    margin-top: 4px;
    font-size: 20px;
}

.year-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.year-tools input {
    width: 116px;
}

.year-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
}

.month-card {
    min-height: 108px;
    display: grid;
    align-content: center;
    gap: 4px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    text-align: left;
    padding: 10px;
}

.month-card:hover,
.month-card.selected {
    background: #eef7f4;
    border-color: rgba(31, 122, 109, 0.55);
}

.month-card span,
.month-card small {
    color: var(--muted);
    font-size: 12px;
}

.month-card strong {
    font-size: 18px;
    color: var(--accent-dark);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 420px;
    gap: 16px;
    align-items: start;
    min-width: 0;
}

.calendar-panel,
.side-panel section {
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(222, 217, 207, 0.9);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.calendar-panel {
    overflow: hidden;
    min-width: 0;
}

.weekday-row,
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekday-row {
    background: #efe9df;
    border-bottom: 1px solid var(--line);
}

.weekday-row span {
    min-height: 40px;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.calendar-grid {
    min-height: 690px;
    min-width: 0;
}

.day-cell {
    min-width: 0;
    min-height: 114px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.8);
    padding: 9px;
    text-align: left;
    color: var(--ink);
    border-radius: 0;
    display: grid;
    align-content: start;
    gap: 6px;
}

.day-cell:nth-child(7n) {
    border-right: 0;
}

.day-cell:hover,
.day-cell.selected {
    background: #eef7f4;
}

.day-cell.is-empty {
    background: rgba(246, 243, 237, 0.55);
    cursor: default;
}

.day-head {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.day-number {
    width: 26px;
    height: 26px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: #f2eee6;
    color: var(--ink);
    font-weight: 700;
}

.day-cell.today .day-number {
    background: var(--accent);
    color: #fff;
}

.day-money {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.money-line {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    font-size: 12px;
}

.money-line b {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.income {
    color: var(--income);
}

.expense {
    color: var(--expense);
}

.net {
    color: var(--ink);
    font-weight: 800;
}

.side-panel {
    display: grid;
    gap: 16px;
    min-width: 0;
}

.side-panel section {
    padding: 18px;
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.panel-heading h2 {
    margin-top: 4px;
    font-size: 20px;
}

.panel-heading strong {
    color: var(--accent-dark);
    font-size: 20px;
    white-space: nowrap;
}

.panel-heading.compact {
    margin-bottom: 12px;
}

.panel-heading.compact h2 {
    font-size: 16px;
}

.stack-form {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.stack-form label {
    display: grid;
    gap: 5px;
}

.inline-fields {
    display: grid;
    grid-template-columns: 0.85fr 1.15fr;
    gap: 10px;
}

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

.calc-preview {
    min-height: 38px;
    display: flex;
    align-items: center;
    border: 1px dashed rgba(31, 122, 109, 0.42);
    border-radius: 8px;
    background: #eef7f4;
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 700;
    padding: 8px 10px;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.segmented label {
    display: block;
    cursor: pointer;
}

.segmented input {
    position: absolute;
    width: 1px;
    height: 1px;
    min-height: 0;
    margin: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.segmented span {
    min-height: 40px;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: #fff;
    border-right: 1px solid var(--line);
}

.segmented label:last-child span {
    border-right: 0;
}

.segmented input:checked + span {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
}

.check-row {
    display: flex !important;
    align-items: center;
    gap: 8px;
}

.check-row input {
    width: 18px;
    min-height: 18px;
}

.entry-list-wrap h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.entry-list,
.fixed-list {
    display: grid;
    gap: 8px;
}

.entry-item,
.fixed-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
    padding: 10px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.entry-item p,
.fixed-item p {
    margin: 0;
    overflow-wrap: anywhere;
}

.entry-item small,
.fixed-item small {
    color: var(--muted);
}

.mini-actions {
    display: flex;
    gap: 6px;
}

.mini-button {
    min-height: 32px;
    padding: 0 10px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--ink);
}

.mini-button:hover {
    background: #f3eee5;
    color: var(--expense);
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    max-width: min(360px, calc(100vw - 40px));
    background: #1f2421;
    color: #fff;
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: var(--shadow);
    z-index: 20;
}

.install-sheet {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    background: rgba(35, 37, 33, 0.34);
    padding: 20px;
}

.install-panel {
    width: min(420px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 22px;
    display: grid;
    gap: 14px;
}

.install-panel h2,
.install-panel p {
    margin: 0;
}

.install-panel h2 {
    font-size: 22px;
}

.install-panel p {
    color: var(--muted);
    line-height: 1.55;
}

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

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

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

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

    .top-actions {
        justify-content: stretch;
    }

    .top-actions input,
    .top-actions button {
        flex: 1 1 120px;
    }

    .month-select-wrap {
        flex: 1 1 180px;
    }

    .month-picker-button {
        width: 100%;
    }

    .month-picker-panel {
        position: fixed;
        left: 14px;
        right: 14px;
        top: 86px;
        width: auto;
        max-height: calc(100vh - 112px);
        overflow: auto;
    }

    .summary-grid,
    .year-summary,
    .side-panel {
        grid-template-columns: 1fr;
    }

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

    .calendar-grid {
        min-height: auto;
    }

    .day-cell {
        min-height: 96px;
        padding: 7px;
    }

    .money-line {
        display: block;
    }

    .inline-fields,
    .fixed-fields {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    body {
        position: relative;
    }

    .weekday-row span {
        min-height: 34px;
    }

    .day-cell {
        min-height: 82px;
        padding: 6px;
    }

    .day-money {
        gap: 2px;
    }

    .money-line {
        font-size: 11px;
    }

    .day-number {
        width: 22px;
        height: 22px;
    }

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

    .month-picker-panel {
        grid-template-columns: 1fr;
    }

    .picker-shortcuts {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .picker-months {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .picker-month + .picker-month {
        border-left: 0;
        border-top: 1px solid var(--line);
        padding-left: 0;
        padding-top: 16px;
    }
}
