:root {
    color-scheme: light dark;

    --bg: var(--tg-theme-bg-color, #f3f4f7);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #ffffff);
    --card: var(--tg-theme-section-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #11131a);
    --muted: var(--tg-theme-hint-color, #747986);
    --accent: var(--tg-theme-button-color, #7357ff);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --link: var(--tg-theme-link-color, #7357ff);
    --border: color-mix(in srgb, var(--muted) 20%, transparent);
    --danger: #ef4444;
    --success: #28b67a;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    min-height: var(--tg-viewport-stable-height, 100vh);
    background: var(--bg);
    color: var(--text);
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select {
    font: inherit;
}

button {
    color: inherit;
}

.hidden {
    display: none !important;
}

.app-shell {
    width: min(100%, 760px);
    margin: 0 auto;
    padding:
        calc(20px + env(safe-area-inset-top))
        16px
        calc(110px + env(safe-area-inset-bottom));
}

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

.eyebrow {
    margin: 0 0 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
}

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

h1 {
    margin-bottom: 0;
    font-size: 27px;
    letter-spacing: -0.04em;
}

h2 {
    margin: 0;
    font-size: 22px;
    letter-spacing: -0.03em;
}

.avatar {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--secondary-bg);
    font-weight: 750;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hero-card {
    position: relative;
    overflow: hidden;
    padding: 22px;
    border-radius: 27px;
    background:
        radial-gradient(
            circle at 100% 0,
            color-mix(in srgb, var(--accent) 72%, white) 0,
            transparent 48%
        ),
        linear-gradient(
            145deg,
            color-mix(in srgb, var(--accent) 82%, #171923),
            color-mix(in srgb, var(--accent) 45%, #11131a)
        );
    color: #ffffff;
}

.hero-card::after {
    position: absolute;
    right: -35px;
    bottom: -75px;
    width: 170px;
    height: 170px;
    border: 35px solid rgb(255 255 255 / 8%);
    border-radius: 50%;
    content: "";
}

.hero-head {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.hero-label {
    margin-bottom: 7px;
    color: rgb(255 255 255 / 72%);
    font-size: 14px;
}

.hero-value {
    margin-bottom: 0;
    font-size: 38px;
    font-weight: 800;
    letter-spacing: -0.055em;
}

.round-button {
    display: grid;
    flex: 0 0 auto;
    width: 45px;
    height: 45px;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: rgb(255 255 255 / 18%);
    color: white;
    font-size: 29px;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.next-payment {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 28px;
    padding-top: 17px;
    border-top: 1px solid rgb(255 255 255 / 18%);
}

.next-icon {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 12px;
    background: rgb(255 255 255 / 12%);
}

.next-label {
    margin-bottom: 3px;
    color: rgb(255 255 255 / 68%);
    font-size: 12px;
}

.next-value {
    margin-bottom: 0;
    font-size: 14px;
    font-weight: 650;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 13px;
}

.metric-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--card);
}

.metric-icon {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 13px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.metric-label {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
}

.metric-value {
    margin-bottom: 0;
    font-size: 18px;
    font-weight: 760;
    letter-spacing: -0.025em;
}

.section {
    margin-top: 30px;
}

.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.text-button {
    border: 0;
    background: transparent;
    color: var(--link);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.filter-row {
    display: flex;
    gap: 8px;
    margin: 0 -16px 15px;
    padding: 0 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.filter-row::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    flex: 0 0 auto;
    padding: 8px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
}

.filter-chip.active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-text);
}

.subscription-list {
    display: grid;
    gap: 11px;
}

.subscription-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 13px;
    width: 100%;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 21px;
    background: var(--card);
    text-align: left;
    cursor: pointer;
}

.subscription-icon {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    border-radius: 15px;
    background: color-mix(in srgb, var(--accent) 11%, transparent);
    font-size: 21px;
}

.subscription-main {
    min-width: 0;
}

.subscription-name {
    margin-bottom: 5px;
    overflow: hidden;
    font-size: 16px;
    font-weight: 720;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subscription-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 9px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 12px;
}

.subscription-side {
    text-align: right;
}

.subscription-price {
    margin-bottom: 5px;
    font-size: 15px;
    font-weight: 760;
    white-space: nowrap;
}

.subscription-date {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.due-soon {
    color: #f59e0b;
}

.overdue {
    color: var(--danger);
}

.empty-card {
    padding: 30px 20px;
    border: 1px dashed var(--border);
    border-radius: 23px;
    text-align: center;
}

.empty-icon {
    margin-bottom: 13px;
    font-size: 34px;
}

.empty-card h3 {
    margin-bottom: 7px;
}

.empty-card p {
    max-width: 330px;
    margin: 0 auto 18px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.stats-list {
    display: grid;
    gap: 15px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: var(--card);
}

.stat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 7px;
    font-size: 13px;
}

.stat-name {
    overflow: hidden;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-value {
    color: var(--muted);
    white-space: nowrap;
}

.stat-track {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: color-mix(in srgb, var(--muted) 13%, transparent);
}

.stat-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.primary-button,
.danger-button {
    width: 100%;
    min-height: 51px;
    border: 0;
    border-radius: 16px;
    font-weight: 730;
    cursor: pointer;
}

.primary-button {
    background: var(--accent);
    color: var(--accent-text);
}

.danger-button {
    margin-top: 10px;
    background: color-mix(in srgb, var(--danger) 13%, transparent);
    color: var(--danger);
}

.floating-add {
    position: fixed;
    z-index: 10;
    right: max(18px, env(safe-area-inset-right));
    bottom: calc(20px + env(safe-area-inset-bottom));
    display: grid;
    width: 58px;
    height: 58px;
    place-items: center;
    border: 0;
    border-radius: 19px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 31px;
    box-shadow: 0 14px 35px
        color-mix(in srgb, var(--accent) 35%, transparent);
    cursor: pointer;
}

.state-screen {
    display: grid;
    min-height: 70vh;
    place-content: center;
    justify-items: center;
    text-align: center;
}

.state-screen p {
    max-width: 310px;
    color: var(--muted);
    line-height: 1.5;
}

.state-icon {
    margin-bottom: 14px;
    font-size: 42px;
}

.loader {
    width: 35px;
    height: 35px;
    margin-bottom: 16px;
    border: 3px solid color-mix(
        in srgb,
        var(--accent) 20%,
        transparent
    );
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.modal {
    position: fixed;
    z-index: 30;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgb(0 0 0 / 48%);
    cursor: pointer;
}

.modal-sheet {
    position: relative;
    z-index: 1;
    width: min(100%, 760px);
    max-height: calc(94vh - env(safe-area-inset-top));
    padding:
        10px
        18px
        calc(22px + env(safe-area-inset-bottom));
    overflow-y: auto;
    border-radius: 27px 27px 0 0;
    background: var(--secondary-bg);
}

.sheet-handle {
    width: 42px;
    height: 5px;
    margin: 0 auto 17px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--muted) 34%, transparent);
}

.modal-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 21px;
}

.icon-button {
    display: grid;
    width: 39px;
    height: 39px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--card);
    font-size: 25px;
    cursor: pointer;
}

.field {
    display: block;
    margin-bottom: 15px;
}

.field > span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 620;
}

.field input,
.field select,
.date-wrapper {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--card);
    color: var(--text);
}

.field input,
.field select {
    min-height: 50px;
    padding: 0 14px;
    outline: none;
}

.field input:focus,
.field select:focus,
.date-wrapper:focus-within {
    border-color: var(--accent);
}

.date-wrapper {
    display: flex;
    min-height: 50px;
    align-items: center;
    padding: 0 14px;
}

.date-wrapper input {
    min-height: auto;
    padding: 0;
    border: 0;
    background: transparent;
}

.submit-button {
    margin-top: 8px;
}

.toast {
    position: fixed;
    z-index: 50;
    left: 50%;
    bottom: calc(26px + env(safe-area-inset-bottom));
    max-width: calc(100% - 34px);
    padding: 12px 17px;
    transform: translateX(-50%);
    border-radius: 14px;
    background: color-mix(in srgb, var(--text) 92%, transparent);
    color: var(--bg);
    font-size: 14px;
    font-weight: 650;
    text-align: center;
}

@media (min-width: 640px) {
    .app-shell {
        padding-inline: 24px;
    }

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

    .filter-row {
        margin-inline: 0;
        padding-inline: 0;
    }

    .floating-add {
        right: calc(50% - 356px);
    }

    .modal-sheet {
        margin-bottom: 18px;
        border-radius: 27px;
    }
}

/* Subscription pause state */

.secondary-button {
    width: 100%;
    min-height: 51px;
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
    color: var(--text);
    font-weight: 730;
    cursor: pointer;
}

.subscription-card.is-paused {
    opacity: 0.62;
}

.subscription-card.is-paused .subscription-icon {
    filter: grayscale(0.8);
}

.paused-date {
    color: var(--muted);
}

/* Forecast analytics v1 */

:root {
    --chart-monthly: var(--accent);
    --chart-30-days: #22c55e;
    --chart-yearly: #f59e0b;
    --chart-once: #ef4444;
}

.metric-card-button {
    position: relative;
    width: 100%;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.metric-card-button:active {
    transform: scale(0.985);
}

.metric-arrow {
    margin-left: auto;
    color: var(--muted);
    font-size: 25px;
}

.analytics-screen {
    width: 100%;
}

.analytics-topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
}

.analytics-back {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    color: var(--text);
    font-size: 22px;
    cursor: pointer;
}

.analytics-title {
    min-width: 0;
}

.analytics-title h1 {
    overflow: hidden;
    font-size: 23px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.analytics-year {
    min-height: 42px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--card);
    color: var(--text);
    font-weight: 700;
}

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

.analytics-summary-card {
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 19px;
    background: var(--card);
}

.analytics-summary-card p {
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
}

.analytics-summary-card strong {
    display: block;
    overflow: hidden;
    font-size: 17px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.analytics-chart-card {
    margin-top: 14px;
    padding: 17px;
    border: 1px solid var(--border);
    border-radius: 23px;
    background: var(--card);
}

.analytics-chart-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
}

.budget-field {
    width: 115px;
}

.budget-field span {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 11px;
}

.budget-field input {
    width: 100%;
    min-height: 39px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--secondary-bg);
    color: var(--text);
}

.analytics-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 13px;
    margin-top: 17px;
    color: var(--muted);
    font-size: 11px;
}

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

.analytics-legend i {
    width: 9px;
    height: 9px;
    border-radius: 3px;
}

.legend-monthly {
    background: var(--chart-monthly);
}

.legend-30-days {
    background: var(--chart-30-days);
}

.legend-yearly {
    background: var(--chart-yearly);
}

.legend-once {
    background: var(--chart-once);
}

.analytics-chart {
    margin-top: 13px;
    overflow-x: auto;
    scrollbar-width: none;
}

.analytics-chart::-webkit-scrollbar {
    display: none;
}

.analytics-svg {
    display: block;
    width: 100%;
    min-width: 620px;
    height: auto;
}

.analytics-svg text {
    fill: var(--muted);
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    font-size: 11px;
}

.analytics-grid-line {
    stroke: var(--border);
    stroke-width: 1;
}

.analytics-budget-line {
    stroke: var(--danger);
    stroke-width: 1.5;
    stroke-dasharray: 5 5;
}

.bar-monthly {
    fill: var(--chart-monthly);
}

.bar-30-days {
    fill: var(--chart-30-days);
}

.bar-yearly {
    fill: var(--chart-yearly);
}

.bar-once {
    fill: var(--chart-once);
}

.analytics-month-hit {
    fill: transparent;
    cursor: pointer;
}

.analytics-month-selection {
    fill: color-mix(
        in srgb,
        var(--accent) 9%,
        transparent
    );
}

.analytics-details {
    margin-top: 28px;
}

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

.analytics-payment-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 13px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--card);
}

.analytics-payment-name {
    margin-bottom: 4px;
    font-weight: 720;
}

.analytics-payment-meta {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 12px;
}

.analytics-payment-price {
    align-self: center;
    font-weight: 760;
    white-space: nowrap;
}

.analytics-empty-month {
    padding: 24px 17px;
    border: 1px dashed var(--border);
    border-radius: 18px;
    color: var(--muted);
    text-align: center;
}

.analytics-notice {
    margin: 22px 5px 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
}

