:root {
    color-scheme: light;
    --bg: #F6F7F9;
    --surface: #FFFFFF;
    --text: #171A1F;
    --muted: #6B7280;
    --line: #E3E6EA;
    --accent: #2F5FD0;
    --accent-hover: #244CB0;
    --accent-soft: #E8EEFB;
    --danger: #B42318;
    --danger-soft: #FEE4E2;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
}

h1 {
    margin: 0 0 8px;
    font-size: 24px;
    font-weight: 650;
}

h2 {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 650;
}

p {
    margin: 0 0 12px;
}

p:last-child {
    margin-bottom: 0;
}

a {
    color: var(--accent);
}

.skip-link {
    position: absolute;
    top: -48px;
    left: 8px;
    z-index: 100;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.skip-link:focus {
    top: calc(8px + env(safe-area-inset-top));
}

.topbar {
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 640px;
    min-height: 56px;
    margin: 0 auto;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
}

.brand {
    color: var(--text);
    font-size: 20px;
    font-weight: 650;
    text-decoration: none;
}

.topbar-form {
    margin: 0;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-user {
    max-width: 132px;
    overflow: hidden;
    color: var(--muted);
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--accent);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
}

.shell {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.has-nav .shell {
    padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

.bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    border-top: 1px solid var(--line);
    background: var(--surface);
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-inner {
    display: flex;
    max-width: 640px;
    margin: 0 auto;
}

.bottom-link {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    padding: 4px 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
}

.bottom-link svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.bottom-link.is-active {
    color: var(--accent);
}

.fab {
    position: fixed;
    right: max(16px, calc((100vw - 640px) / 2 + 16px));
    bottom: calc(72px + env(safe-area-inset-bottom));
    z-index: 21;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #FFFFFF;
    font-size: 32px;
    font-weight: 400;
    line-height: 1;
    text-decoration: none;
}

.fab:hover {
    background: var(--accent-hover);
}

.card {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
}

.card + .card {
    margin-top: 16px;
}

.card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 16px 0;
}

.card-grid .card + .card {
    margin-top: 0;
}

.settings-link {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text);
    text-decoration: none;
}

.settings-link:hover {
    border-color: var(--accent);
}

.settings-link-title {
    font-size: 18px;
    font-weight: 650;
}

.auth-card {
    max-width: 420px;
    margin: 24px auto 0;
}

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

.small {
    font-size: 14px;
}

.hint {
    margin-top: 24px;
    font-size: 14px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 14px;
    font-weight: 600;
}

.field input,
.field select {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

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

.field--inline {
    gap: 4px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--accent);
    color: #FFFFFF;
    font: inherit;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

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

.button--secondary {
    border-color: var(--line);
    background: var(--surface);
    color: var(--accent);
}

.button--secondary:hover {
    background: var(--accent-soft);
}

.button--compact {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 15px;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.link-button {
    min-height: 44px;
    padding: 8px 0;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.link-button--danger {
    color: var(--danger);
}

.crumbs {
    margin: 0 0 8px;
    font-size: 14px;
}

.manage-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.manage-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.manage-item:first-child {
    padding-top: 0;
    border-top: 0;
}

.manage-item--archived {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.manage-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
}

.manage-form .field--inline {
    flex: 1 1 160px;
    min-width: 0;
}

.manage-form .button--compact {
    flex: 0 0 auto;
}

.manage-action {
    margin: 0;
}

.manage-name {
    font-weight: 600;
}

.manage-tag {
    display: flex;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
}

.tag--blue {
    background: #DCE8FF;
    color: #1E3A8A;
}

.tag--peach {
    background: #FFE5D4;
    color: #7C2D12;
}

.tag--mint {
    background: #DDF5E8;
    color: #14532D;
}

.tag--lavender {
    background: #EAE2FF;
    color: #4C1D95;
}

.tag--sky {
    background: #DDF3F8;
    color: #164E63;
}

.tag--rose {
    background: #FFE0E7;
    color: #881337;
}

.tag--sand {
    background: #F5E8C8;
    color: #713F12;
}

.tag--lime {
    background: #EAF5D3;
    color: #365314;
}

.form-error {
    margin: 16px 0 0;
    padding: 10px 12px;
    border: 1px solid var(--danger);
    border-radius: 10px;
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 14px;
}

.form-success {
    margin: 0 0 16px;
    padding: 10px 12px;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--text);
    font-size: 14px;
}

.details {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 16px;
    margin: 0;
}

.details dt {
    color: var(--muted);
    font-size: 14px;
}

.details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.page-head h1 {
    margin: 0 0 4px;
}

.page-head .muted {
    margin: 0;
}

.button--block {
    width: 100%;
}

.button--danger {
    border-color: var(--danger);
    background: var(--danger);
    color: #FFFFFF;
}

.button--danger:hover {
    background: #8F1C14;
}

.month-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 18px 0 8px;
}

.month-title {
    font-size: 18px;
    font-weight: 650;
}

.month-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 22px;
    text-decoration: none;
}

.month-arrow:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.month-summary {
    margin: 12px 0 20px;
}

.month-total {
    margin: 0 0 2px;
    font-size: 30px;
    font-weight: 650;
    line-height: 1.25;
}

.filters {
    margin: 16px 0 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
}

.filters summary {
    min-height: 44px;
    padding: 12px 16px;
    font-weight: 600;
    cursor: pointer;
}

.filter-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 16px 16px;
}

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

fieldset.field {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

fieldset.field legend {
    padding: 0;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
}

.segmented {
    display: flex;
    gap: 8px;
}

.segment {
    position: relative;
    flex: 1 1 0;
}

.segment input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.segment span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    font-weight: 600;
}

.segment input:checked + span {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.segment input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip,
.tag-choice {
    position: relative;
    display: inline-flex;
}

.tag-choice[hidden] {
    display: none;
}

.chip-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.chip-label {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-size: 14px;
    cursor: pointer;
}

.chip-input:checked + .chip-label {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.chip-input:focus-visible + .chip-label,
.chip-input:focus-visible + .tag {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tag-choice .tag {
    border: 1px solid transparent;
    cursor: pointer;
}

.chip-input:checked + .tag {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tag-search {
    width: 100%;
    min-height: 48px;
    margin-bottom: 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

.expense-form {
    margin-top: 16px;
}

.expense-day {
    margin-top: 20px;
}

.day-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 0 2px 6px;
    border-bottom: 1px solid var(--line);
}

.day-title {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    font-weight: 650;
}

.day-total {
    color: var(--muted);
    font-size: 13px;
}

.expense-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.expense-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 2px;
    border-bottom: 1px solid var(--line);
    color: var(--text);
    text-decoration: none;
}

.expense-row:hover .expense-category {
    color: var(--accent);
}

.expense-main {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.expense-category {
    font-weight: 600;
}

.expense-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.expense-comment {
    color: var(--muted);
    font-size: 15px;
    overflow-wrap: anywhere;
}

.expense-author {
    color: var(--muted);
    font-size: 13px;
}

.expense-amount {
    flex: 0 0 auto;
    font-size: 16px;
    font-weight: 650;
    text-align: right;
    white-space: nowrap;
}

.expense-equivalent {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.rate-preview {
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 15px;
}

.rate-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rate-input input {
    flex: 1 1 auto;
}

.rate-unit {
    color: var(--muted);
    font-size: 18px;
}

.currency-toggle {
    display: flex;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}

.currency-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.currency-option + .currency-option {
    border-left: 1px solid var(--line);
}

.currency-option.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.summary-title {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 14px;
}

.summary-main {
    margin: 0 0 6px;
    font-size: 30px;
    font-weight: 650;
    line-height: 1.25;
}

.summary-section {
    margin-top: 16px;
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.summary-list,
.summary-tag-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.summary-row {
    padding: 10px 0;
    border-top: 1px solid var(--line);
}

.summary-row:first-child {
    padding-top: 0;
    border-top: 0;
}

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

.summary-name {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.summary-amount {
    flex: 0 0 auto;
    font-weight: 650;
    white-space: nowrap;
}

.summary-meter {
    display: flex;
    align-items: center;
    gap: 8px;
}

.summary-meter progress {
    flex: 1 1 auto;
    width: 100%;
    height: 8px;
    border: 0;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    appearance: none;
}

.summary-meter progress::-webkit-progress-bar {
    border-radius: 999px;
    background: var(--accent-soft);
}

.summary-meter progress::-webkit-progress-value {
    border-radius: 999px;
    background: var(--accent);
}

.summary-meter progress::-moz-progress-bar {
    border-radius: 999px;
    background: var(--accent);
}

.summary-percent {
    flex: 0 0 auto;
    min-width: 36px;
    color: var(--muted);
    font-size: 13px;
    text-align: right;
}

.summary-tag-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-top: 1px solid var(--line);
}

.summary-tag-row:first-child {
    padding-top: 0;
    border-top: 0;
}

.summary-section .details {
    margin-top: 8px;
}

.badge {
    display: inline-block;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.empty-state {
    margin-top: 20px;
    text-align: center;
}

.expense-detail {
    margin: 16px 0;
}

.expense-detail-category {
    margin: 0 0 4px;
    color: var(--muted);
}

.expense-detail-amount {
    margin: 0 0 4px;
    font-size: 32px;
    font-weight: 650;
}

.expense-detail-tags {
    margin-bottom: 16px;
}

.danger-zone {
    margin-top: 24px;
    padding: 0 16px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
}

.danger-zone summary {
    min-height: 44px;
    padding: 12px 0;
    color: var(--danger);
    font-weight: 600;
    cursor: pointer;
}

@media (min-width: 480px) {
    .filter-grid {
        grid-template-columns: 1fr 1fr;
    }
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

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