:root {
    --tg-bg: var(--tg-theme-bg-color, #ffffff);
    --tg-text: var(--tg-theme-text-color, #1c1c1e);
    --tg-hint: var(--tg-theme-hint-color, #8e8e93);
    --tg-link: var(--tg-theme-link-color, #2481cc);
    --tg-button: var(--tg-theme-button-color, #2481cc);
    --tg-button-text: var(--tg-theme-button-text-color, #ffffff);
    --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
}

* {
    box-sizing: border-box;
}

/* .card-list and .state-block both set an explicit `display`, which — at
   equal specificity — beats the browser's built-in `[hidden] { display:
   none }` rule. Without this, toggling the `hidden` attribute from JS had
   no visual effect and every state (loading/error/empty/list) rendered
   at once. */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--tg-bg);
    color: var(--tg-text);
}

.app {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
    min-height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 600;
    margin: 8px 0 16px;
}

.menu-button {
    border: none;
    background: transparent;
    color: var(--tg-hint);
    font-size: 22px;
    line-height: 1;
    padding: 8px;
    cursor: pointer;
}

.hint {
    color: var(--tg-hint);
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 20px;
}

.card-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.payment-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--tg-secondary-bg);
    border-radius: 12px;
    padding: 12px 14px;
    border: none;
    border-left: 3px solid transparent;
    width: 100%;
    text-align: left;
    font: inherit;
    color: inherit;
    cursor: pointer;
    transition: filter 0.25s ease, background-color 0.25s ease, border-color 0.25s ease;
    animation: cardIn 0.25s ease both;
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* v1.1 — calm, not alarming: a thin colored edge draws the eye without
   turning the whole card into a warning banner. */
.payment-card.overdue {
    border-left-color: #e03131;
    background: rgba(224, 49, 49, 0.12);
}

.payment-card.today {
    border-left-color: #f5b400;
}

/* Paid: a bit lighter (via brightness, not opacity — opacity would also
   fade the checkmark and make text hard to read) plus strikethrough on the
   title and meta line. Deliberately NOT full grey (ТЗ v1.1 §1: "не
   использовать полностью серый цвет карточки"). */
.payment-card.paid {
    filter: brightness(1.08);
    border-left-color: transparent;
}

.payment-card.paid .payment-title,
.payment-card.paid .payment-meta {
    text-decoration: line-through;
}

.payment-dot {
    width: 14px;
    height: 14px;
    min-width: 14px;
    border-radius: 50%;
    background: var(--payment-color, var(--tg-hint));
}

.payment-title {
    font-weight: 500;
    font-size: 15px;
}

.payment-meta {
    color: var(--tg-hint);
    font-size: 13px;
    margin-top: 2px;
}

.payment-check {
    margin-left: auto;
    font-size: 16px;
    line-height: 1;
}

.primary-button {
    display: block;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: var(--tg-button);
    color: var(--tg-button-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 8px;
}

.primary-button.secondary {
    background: var(--tg-secondary-bg);
    color: var(--tg-text);
}

.primary-button.danger {
    background: var(--tg-secondary-bg);
    color: #e03131;
}

.state-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 32px 12px;
    gap: 12px;
}

.state-block .hint {
    margin-bottom: 8px;
}

.state-block .primary-button {
    max-width: 260px;
}

.error-text {
    color: var(--tg-hint);
    font-size: 14px;
    line-height: 1.4;
}

.spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid var(--tg-secondary-bg);
    border-top-color: var(--tg-button);
    animation: spin 0.8s linear infinite;
}

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

#add-payment-form {
    display: flex;
    flex-direction: column;
}

.form-label {
    font-size: 13px;
    color: var(--tg-hint);
    margin: 14px 0 6px;
}

.form-label:first-child {
    margin-top: 0;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    border: none;
    border-radius: 10px;
    background: var(--tg-secondary-bg);
    color: var(--tg-text);
    font-size: 15px;
    font-family: inherit;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--tg-hint);
    margin: 16px 0 4px;
}

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

#save-payment-button,
#add-save-button,
#edit-save-button {
    margin-top: 24px;
}

/* Opening animation for the detail/edit screens (ТЗ v1.1 §4). */
#payment-detail-view:not([hidden]),
#edit-payment-view:not([hidden]) {
    animation: viewIn 0.22s ease both;
}

@keyframes viewIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.detail-card {
    background: var(--tg-secondary-bg);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.detail-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.detail-dot {
    width: 18px;
    height: 18px;
    min-width: 18px;
    border-radius: 50%;
    background: var(--payment-color, var(--tg-hint));
}

.detail-title {
    font-size: 17px;
    font-weight: 600;
}

.detail-fields {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 12px;
    margin: 0;
}

.detail-fields dt {
    color: var(--tg-hint);
    font-size: 13px;
}

.detail-fields dd {
    margin: 0;
    font-size: 14px;
    text-align: right;
}

.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 6px 0 4px;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    padding: 0;
}

.color-swatch.selected {
    border-color: var(--tg-text);
}

/* -- summary banner (ТЗ v1.1 §2) — calm by default, colored only when there's
   something that actually needs attention. */
.summary-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--tg-secondary-bg);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border-left: 3px solid transparent;
    animation: cardIn 0.25s ease both;
}

.summary-banner.tone-danger {
    border-left-color: #e03131;
    background: rgba(224, 49, 49, 0.1);
}

.summary-banner.tone-warning {
    border-left-color: #f5b400;
    background: rgba(245, 180, 0, 0.1);
}

.summary-banner.tone-positive {
    border-left-color: #40c057;
    background: rgba(64, 192, 87, 0.1);
}

.summary-icon {
    font-size: 20px;
    line-height: 1.3;
}

.summary-title {
    font-weight: 600;
    font-size: 14px;
}

.summary-subtitle {
    color: var(--tg-hint);
    font-size: 13px;
    margin-top: 2px;
}

.summary-list {
    margin: 4px 0 0;
    padding: 0 0 0 18px;
    font-size: 13px;
    color: var(--tg-text);
}

.summary-list li {
    line-height: 1.5;
}

.summary-list-more {
    color: var(--tg-hint);
    list-style: none;
    margin-left: -18px;
}

/* -- "..." menu (ТЗ v1.1 §3) — a plain bottom sheet, stub items for now. */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: flex-end;
    z-index: 20;
}

.menu-sheet {
    width: 100%;
    background: var(--tg-bg);
    border-radius: 16px 16px 0 0;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    animation: sheetIn 0.2s ease both;
}

@keyframes sheetIn {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--tg-text);
    font-size: 16px;
    padding: 14px 20px;
    cursor: pointer;
}

.menu-item + .menu-item {
    border-top: 1px solid var(--tg-secondary-bg);
}

/* -- toast (ТЗ v1.1 §5) */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(8px);
    background: var(--tg-text);
    color: var(--tg-bg);
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 30;
    max-width: 90%;
    text-align: center;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
