:root {
    color-scheme: light;
    --bg: #f7f7f5;
    --surface: #ffffff;
    --surface-soft: #fff8f4;
    --surface-hover: #f4f4f1;
    --text: #1b1b1b;
    --muted: #858585;
    --border: #e4e4df;
    --orange: #ff7043;
    --orange-light: #ff8658;
    --green: #23b77b;
    --selected: #1d1d1d;
    --danger: #b42318;
    --danger-border: #e45b4b;
    --success-bg: #eaf8f1;
    --success-text: #176c4c;
    --danger-bg: #fff0ee;
    --decor: #fff0e9;
    --shadow: rgb(30 30 30 / 7%);
    --radius: 24px;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d1117;
    --surface: #161b22;
    --surface-soft: #1a1d22;
    --surface-hover: #20262e;
    --text: #f3f4f5;
    --muted: #9aa2ad;
    --border: #303741;
    --selected: #252b33;
    --danger: #ff8a7a;
    --danger-border: #c85f50;
    --success-bg: #15382d;
    --success-text: #75dbb3;
    --danger-bg: #40201e;
    --decor: #38241c;
    --shadow: rgb(0 0 0 / 28%);
}

html.theme-ready *,
html.theme-ready *::before,
html.theme-ready *::after {
    transition:
        background-color 240ms ease,
        border-color 240ms ease,
        color 200ms ease,
        box-shadow 240ms ease,
        fill 200ms ease;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Manrope, Arial, sans-serif;
}

.app-shell,
.auth-page,
.app-page {
    min-height: 100vh;
}

.auth-page,
.app-page {
    padding: 28px 20px 40px;
}

.auth-page {
    background: radial-gradient(circle at 0 100%, var(--decor) 0 10%, transparent 10.1%);
}

.auth-page__content,
.app-page__content {
    width: 100%;
    max-width: 540px;
    margin: 0 auto;
}

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

.app-header {
    z-index: 5;
    margin-bottom: 55px;
}

.app-header__actions {
    display: flex;
    gap: 10px;
}

.app-logo {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--text);
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.05em;
    text-decoration: none;
}

.app-logo:hover {
    color: var(--text);
}

.app-logo__mark {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--orange-light), var(--orange));
    color: #ffffff;
    font-size: 27px;
}

.round-action {
    display: grid;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font-size: 19px;
}

.round-action:hover,
.round-action:focus-visible {
    border-color: var(--orange);
    background: var(--surface-hover);
    color: var(--orange);
}

.auth-form {
    margin-top: 145px;
}

.app-title {
    margin: 0 0 38px;
    color: var(--text);
    font-size: clamp(35px, 10vw, 43px);
    font-weight: 800;
    letter-spacing: -0.065em;
    line-height: 1.1;
}

.section-heading {
    margin-bottom: 32px;
}

.section-heading__links {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
}

.section-heading__links a {
    color: var(--muted);
    font-size: clamp(30px, 8.5vw, 39px);
    font-weight: 800;
    letter-spacing: -0.06em;
    line-height: 1.08;
    text-decoration: none;
}

.section-heading__links a:hover,
.section-heading__links a:focus-visible {
    color: var(--orange);
}

.section-heading .app-title {
    margin: 0;
}

.history-kind-filter {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    margin-bottom: 14px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
}

.history-kind-filter a {
    display: grid;
    min-height: 44px;
    place-items: center;
    border-radius: 14px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.history-kind-filter a:hover,
.history-kind-filter a:focus-visible {
    color: var(--orange);
}

.history-kind-filter a.is-active {
    background: var(--selected);
    color: #ffffff;
}

html[data-theme="dark"] .history-kind-filter a.is-active {
    color: var(--orange);
}

.history-period {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) 46px;
    align-items: stretch;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
}

.history-period__arrow {
    display: grid;
    place-items: center;
    color: var(--muted);
    text-decoration: none;
}

.history-period__arrow:hover,
.history-period__arrow:focus-visible {
    color: var(--orange);
}

.history-period__label {
    display: flex;
    min-height: 54px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border-right: 1px solid var(--border);
    border-left: 1px solid var(--border);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
}

.history-period__label i {
    color: var(--orange);
}

.history-filter-tools {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 28px;
}

.history-filter-tools > a,
.history-date-filter summary {
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.history-filter-tools > a:hover,
.history-date-filter summary:hover {
    color: var(--orange);
}

.history-date-filter {
    position: relative;
    text-align: right;
}

.history-date-filter summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    list-style: none;
}

.history-date-filter summary::-webkit-details-marker {
    display: none;
}

.history-date-filter form {
    position: absolute;
    z-index: 4;
    top: 30px;
    right: 0;
    width: min(330px, calc(100vw - 40px));
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: 0 16px 40px var(--shadow);
    text-align: left;
}

.history-date-filter .setup-button {
    width: 100%;
}

.form-field {
    margin-bottom: 18px;
}

.form-field > label:not(.segment-control__item) {
    display: block;
    margin: 0 0 8px 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.app-input-group,
.create-input-group {
    flex-wrap: nowrap;
}

.app-input-group .input-group-text,
.app-input-group .form-control,
.app-input-group .form-select,
.password-toggle {
    min-height: 64px;
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
}

.app-input-group .input-group-text {
    padding-left: 21px;
    border-radius: var(--radius) 0 0 var(--radius);
    font-size: 20px;
}

.app-input-group .form-control,
.app-input-group .form-select {
    min-width: 0;
    border-left: 0;
    padding: 16px;
    box-shadow: none;
}

.app-input-group > input[type="date"].form-control {
    width: 0;
    min-width: 0;
    flex: 1 1 0;
    -webkit-appearance: none;
    appearance: none;
}

.app-input-group > input[type="date"]::-webkit-date-and-time-value {
    min-height: 1.5em;
    text-align: left;
}

.amount-icon {
    display: grid;
    width: 24px;
    height: 24px;
    place-items: center;
    border: 2px solid currentcolor;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
}

.app-input-group .form-control:focus,
.app-input-group .form-select:focus {
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
    box-shadow: none;
}

.app-input-group:focus-within .input-group-text,
.app-input-group:focus-within .form-control,
.app-input-group:focus-within .form-select,
.app-input-group:focus-within .password-toggle {
    border-color: var(--orange);
}

.app-input-group .form-control:last-child,
.app-input-group .form-select:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.form-control::placeholder,
textarea::placeholder {
    color: var(--muted);
    opacity: 1;
}

.password-toggle {
    border-left: 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--muted);
}

.app-currency {
    padding-right: 18px;
    border-left: 0 !important;
    border-radius: 0 var(--radius) var(--radius) 0 !important;
    color: var(--muted) !important;
    font-weight: 700;
}

.app-input-group--textarea textarea {
    min-height: 118px;
    padding-top: 20px;
    line-height: 1.5;
    resize: vertical;
}

.app-input-group--textarea .input-group-text {
    align-items: flex-start;
    padding-top: 16px;
}

.app-input-group--textarea .input-group-text i {
    line-height: 1;
}

.segment-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.segment-control__input {
    position: absolute;
    opacity: 0;
}

.segment-control__item {
    display: flex;
    min-height: 62px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 19px;
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
}

.segment-control__input:checked + .segment-control__item--expense {
    background: var(--selected);
    color: #ffffff;
}

.segment-control__input:checked + .segment-control__item--expense i {
    color: var(--orange);
}

.segment-control__input:checked + .segment-control__item--income {
    background: var(--success-bg);
    color: var(--success-text);
}

.segment-control__item--income i {
    color: var(--green);
}

.form-submit {
    min-height: 64px;
    border: 0;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--orange-light), var(--orange));
    color: #ffffff;
    font-size: 18px;
    font-weight: 800;
}

.form-submit:hover {
    background: linear-gradient(135deg, var(--orange-light), var(--orange));
    color: #ffffff;
    box-shadow: 0 8px 22px color-mix(in srgb, var(--orange) 24%, transparent);
}

.form-submit:disabled {
    background: var(--border);
    color: var(--muted);
    opacity: 1;
}

.app-alert {
    border: 0;
    border-radius: 16px;
    font-weight: 600;
}

.alert-success.app-alert {
    background: var(--success-bg);
    color: var(--success-text);
}

.alert-danger.app-alert {
    background: var(--danger-bg);
    color: var(--danger);
}

.field-message {
    display: none;
    margin: 7px 10px 0;
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
}

.has-error .field-message {
    display: block;
}

.has-error .app-input-group .input-group-text,
.has-error .app-input-group .form-control,
.has-error .app-input-group .form-select,
.setup-form__field.has-error .form-control,
.setup-form__field.has-error .form-select,
.create-field.has-error .form-control,
.create-field.has-error .form-select {
    border-color: var(--danger-border);
}

.setup-panel {
    margin: 0 0 24px;
    padding: 22px;
    border: 1px solid color-mix(in srgb, var(--orange) 35%, var(--border));
    border-radius: 24px;
    background: var(--surface-soft);
}

.setup-panel__heading {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
}

.setup-panel__heading > i {
    color: var(--orange);
    font-size: 22px;
}

.setup-panel h2 {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 800;
}

.setup-panel p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.setup-form {
    display: grid;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.setup-form + .setup-form {
    margin-top: 18px;
}

.setup-form__field label,
.create-field label {
    display: block;
    margin: 0 0 6px 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.setup-form__field .form-control,
.setup-form__field .form-select,
.create-field .form-control,
.create-field .form-select,
.create-input-group .input-group-text {
    min-height: 52px;
    border-color: var(--border);
    border-radius: 15px;
    background: var(--surface);
    color: var(--text);
    box-shadow: none;
}

.create-input-group .form-control {
    border-radius: 15px 0 0 15px;
}

.create-input-group .input-group-text {
    border-radius: 0 15px 15px 0;
    color: var(--muted);
}

.setup-button {
    min-height: 50px;
    border: 1px solid var(--orange);
    border-radius: 15px;
    color: var(--orange);
    font-weight: 800;
}

.setup-button:hover {
    border-color: var(--orange);
    background: var(--orange);
    color: #ffffff;
}

.entity-shortcuts {
    display: grid;
    gap: 12px;
    margin-top: 24px;
}

.entity-shortcuts a {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 14px 17px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
}

.entity-shortcuts a:hover {
    border-color: var(--orange);
}

.entity-shortcuts__icon {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 13px;
    background: var(--surface-soft);
    color: var(--orange);
    font-size: 18px;
}

.entity-shortcuts strong,
.entity-shortcuts small {
    display: block;
}

.entity-shortcuts small {
    margin-top: 2px;
    color: var(--muted);
}

.entity-list {
    display: grid;
    gap: 10px;
    margin-bottom: 28px;
}

.entity-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 13px;
    min-height: 76px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 21px;
    background: var(--surface);
}

.entity-editor summary {
    cursor: pointer;
    list-style: none;
}

.entity-editor summary::-webkit-details-marker {
    display: none;
}

.entity-editor summary:focus {
    outline: none;
}

.entity-editor summary:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 35%, transparent);
}

.entity-editor[open] .entity-card {
    border-color: color-mix(in srgb, var(--orange) 45%, var(--border));
}

.entity-editor[open] .entity-card__chevron {
    color: var(--orange);
}

.entity-card__icon {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    border-radius: 15px;
    font-size: 21px;
}

.entity-card__icon--yellow { background: #fff2b8; color: #5f4a00; }
.entity-card__icon--green { background: #d9f7e6; color: #168456; }
.entity-card__icon--blue { background: #dce9ff; color: #326bd6; }
.entity-card__icon--violet { background: #eadcff; color: #7542c7; }
.entity-card__icon--orange { background: #ffeadf; color: var(--orange); }

html[data-theme="dark"] .entity-card__icon {
    filter: saturate(0.9) brightness(0.82);
}

.entity-card__body {
    min-width: 0;
}

.entity-card__body h2 {
    overflow: hidden;
    margin: 0;
    font-size: 15px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entity-card__body > strong,
.entity-card__body > small {
    display: block;
}

.entity-card__body > strong {
    overflow: hidden;
    font-size: 15px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entity-card__body > small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.entity-card__body p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.entity-card__value {
    text-align: right;
}

.entity-card__value strong,
.entity-card__value span {
    display: block;
}

.entity-card__value strong {
    font-size: 14px;
    white-space: nowrap;
}

.entity-card__value span {
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

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

.entity-card__kind--expense { color: var(--orange); }
.entity-card__kind--income { color: var(--green); }

.archive-section {
    margin-bottom: 28px;
}

.archive-section > h2 {
    margin: 0 0 14px;
    font-size: 22px;
    font-weight: 800;
}

.entity-card--archived {
    grid-template-columns: auto minmax(0, 1fr) auto;
}

.restore-button {
    display: flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 12px;
    border: 1px solid color-mix(in srgb, var(--green) 45%, var(--border));
    border-radius: 14px;
    color: var(--green);
    font-size: 13px;
    font-weight: 800;
}

.restore-button:hover {
    border-color: var(--green);
    background: color-mix(in srgb, var(--green) 10%, transparent);
    color: var(--green);
}

.transaction-history {
    display: grid;
    gap: 26px;
}

.transaction-day__caption {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.transaction-day__date {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 5px;
}

.transaction-day__date > strong {
    color: var(--orange);
    font-size: 72px;
    font-weight: 700;
    letter-spacing: -0.08em;
    line-height: 0.95;
}

.transaction-day__date > span,
.transaction-day__date b {
    display: block;
}

.transaction-day__date > span {
    color: var(--muted);
    font-size: 13px;
}

.transaction-day__date b {
    margin-bottom: 2px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.transaction-day__items {
    display: grid;
    gap: 7px;
}

.transaction-editor summary {
    cursor: pointer;
    list-style: none;
}

.transaction-editor summary::-webkit-details-marker {
    display: none;
}

.transaction-editor summary:focus {
    outline: none;
}

.transaction-editor summary:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 35%, transparent);
}

.transaction-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 11px;
    min-height: 96px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
}

.transaction-editor[open] .transaction-card {
    border-color: color-mix(in srgb, var(--orange) 45%, var(--border));
}

.transaction-card__icon {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border-radius: 13px;
    font-size: 19px;
}

.transaction-card__icon--expense {
    background: color-mix(in srgb, var(--orange) 14%, var(--surface));
    color: var(--orange);
}

.transaction-card__icon--income {
    background: color-mix(in srgb, var(--green) 14%, var(--surface));
    color: var(--green);
}

.transaction-card__body {
    min-width: 0;
}

.transaction-card__body strong,
.transaction-card__meta {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.transaction-card__body strong {
    font-size: 16px;
    font-weight: 800;
}

.transaction-card__body small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

.transaction-card__comment {
    display: -webkit-box;
    overflow: hidden;
    margin-top: 7px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-height: 1.35;
}

.transaction-card__amount {
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.transaction-card__amount--income {
    color: var(--green);
}

.transaction-card__edit {
    color: var(--muted);
    font-size: 13px;
}

.transaction-editor[open] .transaction-card__edit {
    color: var(--orange);
}

.transaction-editor__panel {
    margin-top: 7px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface-soft);
}

.transaction-editor__panel .segment-control__item {
    min-height: 50px;
    border-radius: 15px;
    font-size: 13px;
}

.transaction-editor__panel .app-input-group .input-group-text,
.transaction-editor__panel .app-input-group .form-control,
.transaction-editor__panel .app-input-group .form-select {
    min-height: 54px;
}

.transaction-editor__panel .form-submit {
    min-height: 54px;
    border-radius: 17px;
    font-size: 15px;
}

.history-empty a {
    display: inline-block;
    margin-top: 12px;
    color: var(--orange);
    font-weight: 700;
}

.entity-editor__panel {
    margin-top: 8px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface-soft);
}

.entity-editor__panel .form-submit {
    min-height: 52px;
    border-radius: 16px;
    font-size: 15px;
}

.entity-editor__hint {
    margin: -2px 2px 14px;
    color: var(--muted);
    font-size: 12px;
}

.danger-button {
    display: flex;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    border: 1px solid var(--danger-border);
    border-radius: 16px;
    color: var(--danger);
    font-weight: 800;
}

.danger-button:hover {
    border-color: var(--danger-border);
    background: var(--danger-bg);
    color: var(--danger);
}

.empty-state {
    padding: 28px;
    border: 1px dashed var(--border);
    border-radius: 22px;
    color: var(--muted);
    text-align: center;
}

.empty-state i {
    font-size: 28px;
}

.empty-state p {
    margin: 8px 0 0;
}

.create-card {
    scroll-margin-top: 20px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
}

.create-card h2 {
    margin: 0 0 18px;
    font-size: 19px;
    font-weight: 800;
}

.create-field {
    margin-bottom: 14px;
}

.create-card .form-submit {
    min-height: 54px;
    margin-top: 6px;
    border-radius: 17px;
    font-size: 16px;
}

@media (min-width: 576px) {
    .auth-page,
    .app-page {
        padding: 44px;
    }

    .transaction-form {
        padding: 34px;
        border: 1px solid var(--border);
        border-radius: 32px;
        background: var(--surface);
        box-shadow: 0 14px 32px var(--shadow);
    }

    .setup-form {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
        align-items: end;
    }

    .setup-button {
        padding: 0 20px;
    }

    .create-card {
        padding: 26px;
    }
}

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