:root {
    --color-primary: #137a67;
    --color-primary-dark: #0f6555;
    --color-bg: #f3f7f6;
    --color-card: #ffffff;
    --color-text: #1f2329;
    --color-sub: #6b7280;
    --color-income: #16a34a;
    --color-expense: #dc2626;
    --radius: 16px;
    --shadow-card: 0 8px 24px rgba(25, 70, 62, 0.07);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background:
        radial-gradient(circle at 50% -10%, rgba(19, 122, 103, 0.10), transparent 320px),
        var(--color-bg);
    color: var(--color-text);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}

.view {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
}

input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d6dbe3;
    border-radius: 10px;
    font-size: 16px;
    background: #fff;
    outline: none;
}

input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(19, 122, 103, 0.12);
}

button {
    font-family: inherit;
    touch-action: manipulation;
}

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

button:focus-visible,
input:focus-visible {
    outline: 3px solid rgba(19, 122, 103, 0.22);
    outline-offset: 2px;
}

label {
    display: block;
    margin-bottom: 16px;
}

label > span {
    display: block;
    font-size: 13px;
    color: var(--color-sub);
    margin-bottom: 6px;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: var(--color-primary);
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    margin-top: 8px;
}

.btn-primary:disabled {
    opacity: 0.6;
}

.btn-primary:active:not(:disabled) {
    background: var(--color-primary-dark);
}

.btn-install {
    display: block;
    margin: 16px auto 0;
    border: 1px solid var(--color-primary);
    color: var(--color-primary);
    background: transparent;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 14px;
}

.install-hint {
    color: var(--color-sub);
    font-size: 13px;
    text-align: center;
    margin-top: 16px;
}

.error-text {
    color: var(--color-expense);
    font-size: 14px;
    margin-top: 12px;
    text-align: center;
}

.icon-button {
    border: none;
    background: transparent;
    font-size: 22px;
    color: var(--color-sub);
    padding: 4px 12px;
}

.icon-button:disabled {
    opacity: 0.35;
}

#view-login {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    padding: 28px 24px;
    border: 1px solid rgba(19, 122, 103, 0.10);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow-card);
}

.login-logo {
    width: 84px;
    height: 84px;
    border-radius: 20px;
    display: block;
    margin: 0 auto 16px;
}

.login-card h1 {
    text-align: center;
    font-size: 26px;
    margin-bottom: 28px;
}

.home-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(243, 247, 246, 0.90);
    border-bottom: 1px solid rgba(19, 122, 103, 0.08);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    padding: calc(8px + env(safe-area-inset-top)) 16px 4px;
}

.title-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
}

.title-bar h1 {
    font-size: 18px;
    font-weight: 600;
}

.title-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.top-tabs {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 4px;
}

.top-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 7px 4px 5px;
    border: none;
    background: transparent;
    font-size: 15px;
    color: var(--color-sub);
}

.top-tab.active {
    color: var(--color-text);
    font-weight: 600;
}

.tab-indicator {
    width: 20px;
    height: 3px;
    border-radius: 999px;
    background: transparent;
}

.top-tab.active .tab-indicator {
    background: var(--color-primary);
}

.period-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 2px;
}

#period-label {
    font-size: 17px;
    font-weight: 600;
    min-width: 120px;
    text-align: center;
}

.refresh,
.logout {
    position: relative;
    font-size: 13px;
    padding: 4px 7px;
}

.refresh::after,
.logout::after {
    content: "";
    position: absolute;
    inset: -12px -9px;
}

.pending-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 52px 1fr 52px;
    align-items: center;
    min-height: 56px;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
    background: rgba(243, 247, 246, 0.92);
    border-bottom: 1px solid rgba(19, 122, 103, 0.08);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.pending-header h1 {
    font-size: 19px;
    text-align: center;
}

.pending-refresh {
    padding: 4px;
    font-size: 13px;
}

.pending-content {
    padding: 4px 16px calc(24px + env(safe-area-inset-bottom));
}

.pending-hint,
.pending-count,
.pending-loading,
.pending-empty {
    color: var(--color-sub);
    font-size: 13px;
    line-height: 1.6;
    text-align: center;
}

.pending-hint {
    margin: 6px 0 12px;
    padding: 12px 14px;
    border: 1px solid rgba(19, 122, 103, 0.10);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.72);
}

.pending-count {
    width: fit-content;
    margin: 0 auto 12px;
    padding: 3px 10px;
    border-radius: 999px;
    color: var(--color-primary-dark);
    background: rgba(19, 122, 103, 0.10);
}

.pending-loading,
.pending-empty {
    padding: 44px 8px;
}

.pending-record-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    list-style: none;
}

.pending-record-item {
    min-width: 0;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--color-card);
    border: 1px solid rgba(19, 122, 103, 0.08);
    box-shadow: var(--shadow-card);
}

.pending-record-top,
.pending-record-main {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.pending-record-top {
    align-items: center;
    margin-bottom: 9px;
    color: var(--color-sub);
    font-size: 12px;
}

.pending-record-kind {
    flex: 0 0 auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: #f1f3f6;
}

.pending-record-kind.income {
    background: #ecfdf3;
}

.pending-record-kind.expense {
    background: #fef2f2;
}

.pending-record-date {
    min-width: 0;
    overflow-wrap: anywhere;
    text-align: right;
}

.pending-record-main {
    align-items: flex-start;
}

.pending-record-description {
    min-width: 0;
}

.pending-record-reason {
    overflow-wrap: anywhere;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.45;
}

.pending-record-category,
.pending-record-note {
    overflow-wrap: anywhere;
    color: var(--color-sub);
    font-size: 13px;
    line-height: 1.5;
}

.pending-record-category {
    margin-top: 3px;
}

.pending-record-note {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f1f3f6;
}

.pending-record-amount {
    flex: 0 0 auto;
    padding-top: 1px;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
}

.cards {
    padding: 6px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

.card {
    background: var(--color-card);
    border-radius: var(--radius);
    padding: 13px 16px;
    border: 1px solid rgba(19, 122, 103, 0.07);
    box-shadow: var(--shadow-card);
}

.card-label {
    font-size: 12px;
    color: var(--color-sub);
}

.balance-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 32px;
}

.balance-visibility {
    min-width: 58px;
    min-height: 34px;
    padding: 6px 12px;
    border: 1px solid rgba(19, 122, 103, 0.22);
    border-radius: 999px;
    background: rgba(19, 122, 103, 0.06);
    color: var(--color-primary-dark);
    font-size: 13px;
    font-weight: 600;
}

.balance-visibility:active {
    background: rgba(19, 122, 103, 0.13);
}

.balance-value {
    font-size: 30px;
    font-weight: 700;
    margin-top: 2px;
    letter-spacing: 0.5px;
}

.balance-value.is-hidden {
    color: #52605d;
    letter-spacing: 5px;
}

.summary-freshness {
    margin-top: 4px;
    color: var(--color-sub);
    font-size: 12px;
}

.flow-card {
    display: flex;
    flex-direction: column;
}

.flow-row {
    display: flex;
}

.flow-item {
    flex: 1;
    min-width: 0;
}

.flow-row .flow-item + .flow-item {
    border-left: 1px solid #eef0f4;
    padding-left: 16px;
}

.net-row {
    border-top: 1px solid #eef0f4;
    margin-top: 9px;
    padding-top: 7px;
}

.flow-value {
    font-size: 18px;
    font-weight: 700;
    margin-top: 2px;
}

.balance-value.amount-s {
    font-size: 25px;
}

.balance-value.amount-xs {
    font-size: 21px;
}

.flow-value.amount-s {
    font-size: 15px;
}

.flow-value.amount-xs {
    font-size: 13px;
}

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

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

.card h2 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.category-list {
    list-style: none;
}

.category-list li {
    padding: 12px 0;
    border-top: 1px solid #f1f3f6;
    font-size: 15px;
}

.category-list li:first-child {
    border-top: none;
}

.category-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-bar {
    margin-top: 6px;
    height: 4px;
    border-radius: 999px;
    background: #eef0f4;
    overflow: hidden;
}

.category-bar-fill {
    height: 100%;
    border-radius: 999px;
}

.category-bar-fill.expense {
    background: rgba(220, 38, 38, 0.55);
}

.category-bar-fill.income {
    background: rgba(22, 163, 74, 0.55);
}

.category-amount.amount-s {
    font-size: 13px;
}

.category-amount.amount-xs {
    font-size: 12px;
}

.empty-text {
    color: var(--color-sub);
    font-size: 14px;
    text-align: center;
    padding: 4px 0;
}

.entries-card {
    padding-top: 4px;
    padding-bottom: 4px;
}

.entry-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 2px;
    border: none;
    background: transparent;
    font-size: 15px;
    color: var(--color-text);
    text-align: left;
}

.entry-row + .entry-row {
    border-top: 1px solid #f1f3f6;
}

.entry-extra {
    display: flex;
    align-items: center;
    gap: 8px;
}

.entry-badge {
    min-width: 22px;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(19, 122, 103, 0.10);
    color: var(--color-primary-dark);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.entry-arrow {
    color: var(--color-sub);
    font-size: 18px;
    line-height: 1;
}

.fab {
    position: fixed;
    bottom: calc(16px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 48px);
    max-width: 432px;
    padding: 14px;
    border: none;
    border-radius: 999px;
    background: var(--color-primary);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(19, 122, 103, 0.32);
}

.record-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
}

.record-header h1 {
    font-size: 19px;
}

#record-form {
    padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
}

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

.field-label {
    display: block;
    font-size: 13px;
    color: var(--color-sub);
    margin-bottom: 6px;
}

.category-select {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border: 1px solid #d6dbe3;
    border-radius: 10px;
    font-size: 16px;
    background: #fff;
    color: var(--color-text);
    text-align: left;
}

.category-select:focus-visible {
    border-color: var(--color-primary);
}

.category-select-text.placeholder {
    color: #9ca3af;
}

.category-select-arrow {
    color: var(--color-sub);
    font-size: 12px;
}

.sheet {
    position: fixed;
    inset: 0;
    z-index: 100;
}

.sheet-mask {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 480px;
    margin: 0 auto;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    max-height: calc(100dvh - env(safe-area-inset-top));
    overflow-y: auto;
    overscroll-behavior: contain;
    animation: sheet-up 0.18s ease-out;
}

@keyframes sheet-up {
    from {
        transform: translateY(24px);
        opacity: 0.6;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (min-width: 520px) {
    #view-login {
        max-width: 440px;
    }
}

@media (max-width: 359px) {
    #view-login {
        padding: 16px;
    }

    .login-card {
        padding: 22px 18px;
        border-radius: 18px;
    }

    .title-bar {
        align-items: flex-start;
    }

    .title-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .cards,
    .pending-content {
        padding-left: 12px;
        padding-right: 12px;
    }

    #record-form {
        padding-left: 16px;
        padding-right: 16px;
    }

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

.sheet-title {
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 14px;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.category-grid-item {
    border: none;
    border-radius: 10px;
    background: #f2f4f7;
    padding: 12px 4px;
    font-size: 15px;
    color: var(--color-text);
}

.category-grid-item:active {
    background: #e4e8ee;
}

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

.btn-secondary {
    flex: 1;
    padding: 12px;
    border: 1px solid #d6dbe3;
    border-radius: 12px;
    background: #fff;
    font-size: 16px;
    color: var(--color-text);
}

.sheet-confirm {
    flex: 1;
    width: auto;
    margin-top: 0;
}

.kind-toggle {
    display: flex;
    background: #e4e8ee;
    border-radius: 12px;
    padding: 3px;
    margin-bottom: 18px;
}

.kind-item {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: 9px;
    font-size: 15px;
    color: var(--color-sub);
}

.kind-item.active {
    background: #fff;
    font-weight: 600;
    color: var(--color-text);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}
