:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #18202f;
    --muted: #6b7280;
    --line: #dfe5ef;
    --primary: #146c5f;
    --primary-dark: #0f544a;
    --danger: #b42318;
    --income: #117a44;
    --shadow: 0 18px 50px rgba(32, 42, 68, 0.08);
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    padding-bottom: 106px;
}

body.modal-open {
    overflow: hidden;
}

a {
    color: inherit;
}

html {
    min-width: 320px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px 18px 10px;
}

.topbar > div:first-child {
    min-width: 0;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 30px;
}

h2 {
    font-size: 18px;
}

.eyebrow {
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.layout {
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px;
}

.narrow {
    max-width: 560px;
    margin: 0 auto;
    padding: 18px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card,
.panel,
.install-box {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.stat-card {
    padding: 18px;
}

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

.stat-card strong {
    font-size: 25px;
    word-break: break-word;
}

.stat-card.danger strong,
.amount.expense {
    color: var(--danger);
}

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

.content-grid {
    display: grid;
    grid-template-columns: 0.8fr 1.2fr;
    gap: 18px;
    margin-bottom: 18px;
}

.panel {
    padding: 18px;
}

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

.panel-head span,
.muted {
    color: var(--muted);
    font-size: 13px;
}

.panel-head a {
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 7px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
}

.button.compact {
    min-height: 36px;
    padding: 0 12px;
    font-size: 13px;
}

.button.primary {
    background: var(--primary);
    color: #ffffff;
}

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

.button.secondary {
    background: #ffffff;
    border-color: var(--line);
}

.top-actions {
    display: flex;
    gap: 10px;
}

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 12px;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    grid-template-rows: 1fr;
    gap: 4px;
    width: min(520px, calc(100% - 24px));
    transform: translateX(-50%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 12px 35px rgba(32, 42, 68, 0.16);
    padding: 6px;
}

.dashboard-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(135deg, #ffffff 0%, #eef8f3 58%, #fff7df 100%);
    box-shadow: var(--shadow);
}

.dashboard-hero h2 {
    max-width: 560px;
    margin-top: 4px;
    font-size: 24px;
}

.month-filter {
    display: grid;
    gap: 8px;
    min-width: min(100%, 350px);
}

.month-filter label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.month-filter div {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
}

.dashboard-stats {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 18px;
    margin-bottom: 18px;
}

.dashboard-grid.single {
    grid-template-columns: 1fr;
}

.daily-chart {
    display: flex;
    align-items: end;
    gap: 8px;
    min-height: 230px;
    overflow-x: auto;
    padding: 10px 2px 0;
    -webkit-overflow-scrolling: touch;
}

.daily-column {
    display: grid;
    grid-template-rows: auto 1fr auto;
    align-items: end;
    justify-items: center;
    gap: 7px;
    min-width: 74px;
    height: 210px;
}

.daily-amount {
    color: var(--text);
    font-size: 12px;
    line-height: 1.2;
    overflow-wrap: anywhere;
    text-align: center;
}

.daily-bar {
    width: 100%;
    min-height: 12px;
    border-radius: 7px 7px 3px 3px;
    background: linear-gradient(180deg, #e0a21a 0%, #d85d3d 100%);
}

.daily-day {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.daily-mobile-bar {
    display: none;
}

.bottom-nav a {
    display: grid;
    gap: 2px;
    justify-items: center;
    align-content: center;
    min-width: 0;
    min-height: 48px;
    border-radius: 7px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-decoration: none;
}

.top-actions .mobile-pay {
    display: none;
}

.bottom-nav a:hover {
    background: #f3f6fa;
    color: var(--primary);
}

.nav-icon {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: #eef2f7;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}

.button.full {
    width: 100%;
}

.quick-actions {
    align-self: start;
}

.quick-button-grid {
    display: grid;
    gap: 10px;
}

.entry-form {
    display: grid;
    gap: 13px;
}

.entry-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.optional-text {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

input,
select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    font: inherit;
    padding: 9px 11px;
    background: #ffffff;
    appearance: none;
}

input:focus,
select:focus {
    border-color: var(--primary);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(20, 108, 95, 0.13);
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #eef2f7;
    border-radius: 8px;
    padding: 4px;
}

.segmented label {
    display: block;
}

.segmented input {
    position: absolute;
    opacity: 0;
}

.segmented span {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 36px;
    border-radius: 6px;
    color: var(--muted);
    font-weight: 700;
}

.segmented input:checked + span {
    background: #ffffff;
    color: var(--primary);
    box-shadow: 0 2px 10px rgba(32, 42, 68, 0.08);
}

.bars {
    display: grid;
    gap: 14px;
}

.bar-label {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
    margin-bottom: 6px;
}

.bar-track {
    height: 9px;
    overflow: hidden;
    background: #edf1f6;
    border-radius: 999px;
}

.bar-track div {
    height: 100%;
    background: #e0a21a;
    border-radius: inherit;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px 8px;
    text-align: left;
    font-size: 14px;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.right {
    text-align: right;
}

.pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 700;
    background: #f3f4f6;
}

.pill.expense {
    color: var(--danger);
    background: #fff1f0;
}

.pill.income {
    color: var(--income);
    background: #ecfdf3;
}

.pill.yes {
    color: var(--income);
    background: #ecfdf3;
}

.pill.no {
    color: var(--danger);
    background: #fff1f0;
}

.pill.pending {
    color: #665200;
    background: #fff8d6;
}

.item-list {
    display: grid;
    gap: 12px;
}

.item-list.compact {
    gap: 10px;
}

.track-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.track-item strong {
    display: block;
    font-size: 15px;
    overflow-wrap: anywhere;
}

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

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

.button.mark {
    min-height: 34px;
    padding: 0 11px;
    font-size: 13px;
}

.button.mark.yes {
    background: #ecfdf3;
    color: var(--income);
}

.button.mark.no {
    background: #fff1f0;
    color: var(--danger);
}

.reset-link {
    margin-top: 14px;
}

.page-footer {
    max-width: 1180px;
    margin: 8px auto 102px;
    padding: 0 18px;
    text-align: center;
}

.page-footer a {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.actions {
    white-space: nowrap;
}

.actions a {
    color: var(--primary);
    font-weight: 700;
    margin-left: 10px;
    text-decoration: none;
}

.actions a:first-child {
    margin-left: 0;
}

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

.center-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
}

.install-box {
    width: min(100%, 460px);
    padding: 24px;
}

.install-box h1 {
    margin-bottom: 10px;
}

.install-box .button {
    margin-top: 18px;
}

.login-form {
    margin-top: 18px;
}

.notice {
    border-radius: 7px;
    margin-bottom: 14px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 700;
}

.notice.success {
    background: #ecfdf3;
    color: var(--income);
}

.notice.error {
    background: #fff1f0;
    color: var(--danger);
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 18px;
    overflow-x: hidden;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.48);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(100%, 460px);
    max-height: min(760px, calc(100vh - 36px));
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(17, 24, 39, 0.24);
    padding: 18px;
    overscroll-behavior: contain;
}

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

.icon-button {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #ffffff;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 22px;
    line-height: 1;
}

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

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

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

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

@media (max-width: 620px) {
    body {
        background: #ffffff;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
        padding: 18px 14px 8px;
    }

    .top-actions {
        justify-content: flex-start;
        width: auto;
    }

    .top-actions .button:not(.primary) {
        display: none;
    }

    .top-actions .button.primary {
        min-height: 38px;
        width: auto;
        padding: 0 14px;
    }

    .stats-grid,
    .content-grid,
    .dashboard-stats,
    .two-col {
        grid-template-columns: 1fr;
    }

    .dashboard-hero {
        align-items: stretch;
        flex-direction: column;
        box-shadow: none;
        padding: 14px;
    }

    .dashboard-hero h2 {
        font-size: 20px;
    }

    .month-filter div {
        grid-template-columns: 1fr;
    }

    .daily-chart {
        display: grid;
        gap: 10px;
        min-height: 0;
        overflow-x: visible;
        padding: 0;
    }

    .daily-column {
        display: grid;
        grid-template-columns: 52px minmax(0, 1fr) minmax(86px, auto);
        gap: 10px;
        align-items: center;
        height: auto;
        min-width: 0;
    }

    .daily-bar {
        display: none;
    }

    .daily-mobile-bar {
        display: block;
        height: 10px;
        overflow: hidden;
        border-radius: 999px;
        background: #edf1f6;
    }

    .daily-mobile-bar div {
        height: 100%;
        border-radius: inherit;
        background: linear-gradient(90deg, #e0a21a 0%, #d85d3d 100%);
    }

    .daily-amount {
        justify-self: end;
        text-align: right;
    }

    .daily-day {
        font-size: 12px;
    }

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

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

    .layout,
    .narrow {
        padding: 14px;
    }

    .panel,
    .stat-card,
    .install-box {
        box-shadow: none;
    }

    .panel {
        padding: 14px;
    }

    .quick-actions {
        order: -1;
    }

    .panel-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

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

    .button,
    input,
    select {
        min-height: 46px;
    }

    .button.compact {
        min-height: 38px;
        width: auto;
    }

    .bottom-nav {
        bottom: 10px;
        width: min(430px, calc(100% - 20px));
        border-color: rgba(255, 255, 255, 0.08);
        background: #151719;
        box-shadow: 0 18px 46px rgba(0, 0, 0, 0.28);
        grid-template-columns: repeat(5, minmax(0, 1fr));
        grid-auto-flow: column;
        grid-auto-columns: minmax(0, 1fr);
        grid-template-rows: 1fr;
        padding: 6px;
    }

    .bottom-nav a {
        min-width: 0;
        min-height: 48px;
        color: rgba(255, 255, 255, 0.72);
        font-size: 11px;
    }

    .bottom-nav a:hover {
        background: rgba(255, 255, 255, 0.08);
        color: #ffffff;
    }

    .nav-icon {
        width: 20px;
        height: 20px;
        border-radius: 7px;
        background: transparent;
        color: rgba(255, 255, 255, 0.82);
        font-size: 15px;
    }

    .table-wrap {
        overflow: visible;
    }

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
        width: 100%;
    }

    table {
        min-width: 0;
    }

    thead {
        display: none;
    }

    tbody {
        display: grid;
        gap: 12px;
    }

    tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 10px;
    }

    th,
    td {
        border-bottom: 0;
        padding: 7px 0;
    }

    td {
        display: grid;
        grid-template-columns: 108px minmax(0, 1fr);
        gap: 10px;
        align-items: start;
        font-size: 14px;
    }

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
    }

    td.right {
        text-align: left;
    }

    .actions {
        white-space: normal;
    }

    .actions a {
        display: inline-flex;
        min-height: 34px;
        align-items: center;
        margin: 0 12px 0 0;
    }

    .modal {
        align-items: end;
        justify-items: stretch;
        width: 100%;
        max-width: 100%;
        height: var(--app-height, 100vh);
        max-height: var(--app-height, 100vh);
        overflow: hidden;
        padding: 0;
    }

    .modal-panel {
        width: 100%;
        max-width: 100%;
        max-height: calc(var(--app-height, 100vh) - 12px);
        overflow-x: hidden;
        border-radius: 8px 8px 0 0;
        padding: 16px;
    }

    @supports (height: 100dvh) {
        .modal {
            height: 100dvh;
            max-height: 100dvh;
        }

        .modal-panel {
            max-height: calc(100dvh - 12px);
        }
    }

    .modal-panel .entry-form,
    .modal-panel .two-col,
    .modal-panel label,
    .modal-panel input,
    .modal-panel select,
    .modal-panel .segmented,
    .modal-panel .button {
        min-width: 0;
        max-width: 100%;
    }

    .modal-panel .two-col {
        gap: 10px;
    }

    .modal-panel input,
    .modal-panel select {
        font-size: 16px;
    }

    .modal-panel .segmented span {
        min-width: 0;
        padding: 0 8px;
        font-size: 15px;
    }

    h1 {
        font-size: 25px;
    }
}
