:root {
    --bg: #eef2f6;
    --bg-deep: #18212c;
    --surface: #ffffff;
    --surface-soft: #f7f9fb;
    --text: #16202a;
    --muted: #687382;
    --line: #dde5ee;
    --primary: #168f73;
    --primary-dark: #0f6d57;
    --accent: #f06f48;
    --accent-soft: #fff0ea;
    --danger: #d94b4b;
    --danger-dark: #a93232;
    --shadow: 0 22px 60px rgba(19, 31, 43, 0.16);
    --shadow-soft: 0 14px 34px rgba(25, 42, 58, 0.09);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(22, 143, 115, 0.12), transparent 34%),
        linear-gradient(225deg, rgba(240, 111, 72, 0.14), transparent 30%),
        var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
}

button,
input {
    font: inherit;
}

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

.app-shell {
    width: min(1540px, calc(100% - 36px));
    margin: 0 auto;
    padding: 26px 0 34px;
}

.app-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(145deg, var(--primary), var(--bg-deep));
    box-shadow: 0 12px 28px rgba(15, 109, 87, 0.28);
    font-weight: 900;
}

.app-title p,
.app-title strong,
h1,
h2,
h3,
p {
    margin: 0;
}

.app-title p {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.app-title strong {
    display: block;
    margin-top: 2px;
    font-size: 1.08rem;
}

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

.month-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}

h1 {
    font-size: clamp(1.65rem, 2.4vw, 2.65rem);
    font-weight: 900;
    margin-left: 12px;
    white-space: nowrap;
    letter-spacing: 0;
}

.btn {
    border: 1px solid rgba(22, 32, 42, 0.09);
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
    cursor: pointer;
    border-radius: 8px;
    min-height: 40px;
    box-shadow: 0 8px 18px rgba(24, 35, 47, 0.07);
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.btn:hover {
    border-color: rgba(22, 143, 115, 0.38);
    box-shadow: 0 14px 24px rgba(24, 35, 47, 0.1);
    transform: translateY(-1px);
}

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

.text-btn {
    padding: 0 18px;
    color: #fff;
    background: var(--bg-deep);
    border-color: var(--bg-deep);
    text-transform: lowercase;
}

.icon-btn {
    width: 42px;
    font-weight: 900;
}

.primary-btn {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    padding: 0 20px;
}

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

.ghost-btn {
    display: none;
    padding: 0 14px;
    color: var(--muted);
}

.ghost-btn.is-visible {
    display: inline-flex;
    align-items: center;
}

.danger-btn {
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
}

.danger-btn:hover {
    background: var(--danger-dark);
}

.small-btn {
    min-height: 32px;
    padding: 0 11px;
    box-shadow: none;
}

.monthly-total {
    position: relative;
    min-width: 280px;
    overflow: hidden;
    text-align: right;
    background: linear-gradient(145deg, var(--bg-deep), #253445);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    padding: 16px 18px;
    color: #fff;
    box-shadow: var(--shadow-soft);
}

.monthly-total::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(22, 143, 115, 0.32), rgba(240, 111, 72, 0.2));
    opacity: 0.75;
}

.monthly-total span,
.monthly-total strong {
    position: relative;
}

.monthly-total span,
.muted,
.top-panel span,
.day-count {
    color: var(--muted);
    font-size: 0.84rem;
}

.monthly-total span {
    color: rgba(255, 255, 255, 0.68);
    font-weight: 700;
}

.monthly-total strong {
    display: block;
    margin-top: 6px;
    font-size: 1.42rem;
    font-weight: 900;
}

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

.calendar-panel,
.top-panel {
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(16px);
}

.calendar-panel {
    overflow: hidden;
}

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

.weekday-grid {
    background: rgba(247, 249, 251, 0.9);
    border-bottom: 1px solid var(--line);
}

.weekday-grid span {
    padding: 14px 12px;
    text-align: center;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.calendar-grid {
    min-height: 730px;
}

.day-cell {
    position: relative;
    min-height: 134px;
    border: 0;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
    padding: 13px;
    text-align: left;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    box-shadow: none;
}

.day-cell:hover {
    z-index: 1;
    background: #ffffff;
    box-shadow: inset 0 0 0 1px rgba(22, 143, 115, 0.22), 0 18px 28px rgba(22, 32, 42, 0.1);
}

.day-cell.empty {
    background: rgba(237, 242, 246, 0.64);
    cursor: default;
}

.day-cell.empty:hover {
    box-shadow: none;
    transform: none;
}

.day-cell.today {
    background: linear-gradient(180deg, rgba(22, 143, 115, 0.09), rgba(255, 255, 255, 0.92));
    box-shadow: inset 0 0 0 2px rgba(22, 143, 115, 0.72);
}

.day-cell.has-expense::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
}

.day-head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.day-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--surface-soft);
    color: #23313f;
    font-weight: 900;
}

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

.day-signal {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: transparent;
}

.has-expense .day-signal {
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(240, 111, 72, 0.12);
}

.day-total {
    width: 100%;
    margin-top: auto;
    color: var(--primary-dark);
    font-size: 1.08rem;
    font-weight: 900;
    line-height: 1.2;
    word-break: break-word;
}

.day-count {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 0 9px;
    background: var(--surface-soft);
    font-weight: 800;
}

.top-panel {
    position: sticky;
    top: 18px;
    padding: 20px;
}

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

.panel-heading h2 {
    font-size: 1.08rem;
    font-weight: 900;
}

.top-list {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: top;
}

.top-list li {
    position: relative;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
    counter-increment: top;
}

.top-list li::before {
    content: counter(top);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    color: var(--primary-dark);
    background: rgba(22, 143, 115, 0.1);
    font-weight: 900;
}

.top-list li:last-child {
    border-bottom: 0;
}

.top-list strong,
.top-list span {
    display: block;
}

.top-list strong {
    overflow-wrap: anywhere;
}

.top-list b {
    display: block;
    margin-top: 7px;
    color: var(--accent);
    font-size: 1.02rem;
}

.top-list .empty-state {
    display: block;
}

.top-list .empty-state::before {
    display: none;
}

.empty-state {
    color: var(--muted);
    line-height: 1.5;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10;
    background: rgba(12, 19, 26, 0.58);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    backdrop-filter: blur(10px);
}

.modal-backdrop.is-open {
    display: flex;
}

.modal {
    width: min(720px, 100%);
    max-height: min(780px, calc(100vh - 36px));
    overflow: auto;
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.86);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 24px;
}

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

.modal-header h2 {
    margin-top: 3px;
    font-size: 1.42rem;
    font-weight: 900;
}

.expense-form {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(170px, 0.8fr);
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.expense-form label span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 900;
}

.expense-form input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 0 13px;
    color: var(--text);
}

.expense-form input:focus {
    outline: 3px solid rgba(22, 143, 115, 0.16);
    border-color: var(--primary);
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.day-list-wrap {
    padding-top: 20px;
}

.day-list-wrap h3 {
    font-size: 1rem;
    font-weight: 900;
    margin-bottom: 12px;
}

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

.day-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 20px rgba(24, 35, 47, 0.05);
}

.day-item strong,
.day-item span {
    display: block;
}

.day-item strong {
    overflow-wrap: anywhere;
}

.day-item span {
    margin-top: 5px;
    color: var(--primary-dark);
    font-weight: 900;
}

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.load-error {
    grid-column: 1 / -1;
    padding: 24px;
    color: var(--danger-dark);
}

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

    .top-panel {
        position: static;
        order: -1;
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 20px, 1540px);
        padding: 14px 0 24px;
    }

    .toolbar,
    .month-controls {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .monthly-total {
        width: 100%;
        min-width: 0;
        text-align: left;
    }

    h1 {
        width: 100%;
        margin: 8px 0 0;
        white-space: normal;
    }

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

    .day-cell {
        min-height: 106px;
        padding: 8px;
    }

    .day-number {
        width: 28px;
        height: 28px;
        font-size: 0.86rem;
    }

    .day-total {
        font-size: 0.82rem;
    }

    .day-count {
        min-height: 21px;
        padding: 0 6px;
        font-size: 0.68rem;
    }

    .weekday-grid span {
        padding: 10px 2px;
        font-size: 0.68rem;
    }

    .expense-form {
        grid-template-columns: 1fr;
        padding: 12px;
    }

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

    .row-actions {
        justify-content: flex-start;
    }
}
