:root {
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 999px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.12);
    --transition: 0.2s ease;
    --control-height: 46px;
    --accent: #4f6ef7;
    --accent-hover: #3d5ce5;
    --accent-soft: rgba(79, 110, 247, 0.12);
    --danger: #e5484d;
    --danger-soft: rgba(229, 72, 77, 0.12);
    --success: #30a46c;
    --success-soft: rgba(48, 164, 108, 0.12);
    --bg: #f0f2f8;
    --bg-elevated: #ffffff;
    --bg-muted: #e8ebf3;
    --bg-subtle: #f7f8fc;
    --text: #111827;
    --text-secondary: #5b6478;
    --text-muted: #8b93a7;
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.14);
    --topbar-bg: rgba(255, 255, 255, 0.82);
    --input-bg: #ffffff;
    --gradient-1: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(79, 110, 247, 0.18), transparent);
    --gradient-2: radial-gradient(circle at 100% 0%, rgba(255, 77, 109, 0.08), transparent 40%);
}

[data-theme="dark"] {
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
    --accent: #6b8cff;
    --accent-hover: #8aa4ff;
    --accent-soft: rgba(107, 140, 255, 0.16);
    --danger: #ff6b6b;
    --danger-soft: rgba(255, 107, 107, 0.14);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.14);
    --bg: #0f1117;
    --bg-elevated: #181b24;
    --bg-muted: #222633;
    --bg-subtle: #1a1e28;
    --text: #f3f4f8;
    --text-secondary: #a8afc0;
    --text-muted: #727a8f;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --topbar-bg: rgba(15, 17, 23, 0.88);
    --input-bg: #1e2230;
    --gradient-1: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(107, 140, 255, 0.15), transparent);
    --gradient-2: radial-gradient(circle at 100% 0%, rgba(255, 77, 109, 0.1), transparent 40%);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

[data-theme="dark"] {
    color-scheme: dark;
}

body {
    font-family: var(--font);
    background: var(--bg);
    background-image: var(--gradient-1), var(--gradient-2);
    background-attachment: fixed;
    margin: 0;
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    transition: background-color var(--transition), color var(--transition);
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Topbar ── */

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--topbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 760px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
    text-decoration: none;
    flex-shrink: 0;
}

.brand:hover {
    color: var(--text);
    text-decoration: none;
}

.brand-icon {
    border-radius: 8px;
}

.nav {
    display: flex;
    gap: 4px;
    flex: 1;
}

.nav-link {
    padding: 8px 14px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
    background: var(--bg-muted);
    color: var(--text);
    text-decoration: none;
}

.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.nav-link-icon {
    display: none;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 6px 6px 12px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
}

.user-chip-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Theme toggle ── */

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--bg-subtle);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--bg-muted);
    color: var(--text);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.icon-moon {
    display: none;
}

[data-theme="dark"] .icon-sun {
    display: none;
}

[data-theme="dark"] .icon-moon {
    display: block;
}

/* ── Main ── */

.main {
    flex: 1;
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 20px 48px;
}

.page-head {
    margin-bottom: 24px;
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 6px;
}

.page-desc {
    color: var(--text-secondary);
    font-size: 15px;
    margin: 0;
    max-width: 520px;
}

.period-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    margin-bottom: 24px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.period-current {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 160px;
}

.period-current-label {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.period-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    background: var(--accent-soft);
    color: var(--accent);
}

.period-badge-archive {
    background: var(--bg-muted);
    color: var(--text-secondary);
}

.period-picker {
    margin-left: auto;
}

.period-picker input[type="month"] {
    height: var(--control-height);
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.btn-icon-nav {
    color: var(--text-secondary);
}

.btn-icon-nav:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.category-cashbacks-period {
    color: var(--text-muted);
    font-weight: 500;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Cards ── */

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: background var(--transition), border-color var(--transition);
}

.section-card {
    margin-bottom: 16px;
}

.section-card:last-child {
    margin-bottom: 0;
}

.section-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
}

.section-subtitle {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 16px;
}

.section-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: var(--radius-full);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
}

/* ── Forms ── */

.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input,
.field input[type="email"],
.field input[type="password"],
.field input[type="text"] {
    width: 100%;
    min-height: var(--control-height);
    padding: 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    box-sizing: border-box;
}

select.input {
    width: 100%;
    min-height: var(--control-height);
    padding: 0 40px 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background-color: var(--input-bg);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b93a7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px;
}

[data-theme="dark"] select.input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a8afc0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

.input:focus,
.field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input::placeholder,
.field input::placeholder {
    color: var(--text-muted);
}

.color-field {
    display: flex;
    align-items: center;
    gap: 12px;
}

.color-pair {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.color-pair-block {
    flex-wrap: wrap;
}

.color-picker {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.color-picker-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
}

.color-picker input[type="color"] {
    width: 44px;
    height: 44px;
    padding: 3px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    cursor: pointer;
}

.field-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 13px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--transition), transform 0.1s ease, opacity var(--transition);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    width: 100%;
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-muted);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--border-strong);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-muted);
    color: var(--text);
}

.btn-sm {
    width: auto;
    padding: 9px 16px;
    font-size: 13px;
}

.btn-text,
.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background var(--transition);
}

.btn-text:hover,
.btn-link:hover {
    background: var(--accent-soft);
}

.btn-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.btn-logout:hover {
    background: var(--accent-soft);
}

.btn-logout-icon {
    display: none;
    width: 20px;
    height: 20px;
}

.btn-danger-text {
    color: var(--danger);
}

.btn-danger-text:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.inline-form {
    display: inline;
    margin: 0;
}

/* ── Alerts ── */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: rgba(229, 72, 77, 0.2);
}

.alert-success {
    background: var(--success-soft);
    color: var(--success);
    border-color: rgba(48, 164, 108, 0.2);
}

/* ── Tabs (auth) ── */

.tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 24px;
}

.tab {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.tab.active {
    background: var(--bg-elevated);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

/* ── Auth page ── */

.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px 20px;
}

.auth-top {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10;
}

.auth-wrap {
    width: 100%;
    max-width: 420px;
}

.auth-hero {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo {
    display: block;
    margin: 0 auto 16px;
    border-radius: 16px;
    box-shadow: var(--shadow-md);
}

.auth-title {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0 0 8px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    margin: 0;
}

.auth-card {
    box-shadow: var(--shadow-md);
}

/* ── Owners (settings) ── */

.owner-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.owner-card-full {
    flex-direction: row;
    align-items: flex-start;
}

.owner-card-full .owner-avatar {
    margin-top: 2px;
}

.owner-card-top {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    width: 100%;
}

.owner-banks {
    margin-top: 4px;
}

.owner-banks-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.owner-banks-hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 8px 0 0;
}

.section-hint {
    margin: -8px 0 16px;
}

.bank-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bank-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    user-select: none;
}

.bank-check:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.bank-check input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.owner-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.owner-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: #fff;
    background: var(--owner-color-light, var(--accent));
    box-shadow: inset 0 -2px 6px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
}

[data-theme="dark"] .owner-avatar.themed-color {
    background: var(--owner-color-dark, var(--owner-color-light, var(--accent)));
}

.owner-form {
    flex: 1;
    min-width: 0;
}

.owner-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.owner-name {
    width: 100%;
}

.bank-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    width: 100%;
}

.bank-name {
    width: 100%;
}

.category-name {
    width: 100%;
}

.color-pair-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.color-pair-row .color-picker {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.color-pair-row .color-picker input[type="color"] {
    width: var(--control-height);
    height: var(--control-height);
    min-height: var(--control-height);
    border: none;
    padding: 0;
    background: transparent;
}

.owner-fields .input {
    flex: none;
    width: 100%;
}

.owner-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.owner-add-form {
    margin: 0;
}

/* ── Cashback list ── */

.cashback-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cashback-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    transition: background var(--transition), border-color var(--transition);
}

.cashback-category {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 12px;
}

.cashback-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.cashback-tag {
    --tag-color: var(--tag-color-light, var(--accent));
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: color-mix(in srgb, var(--tag-color) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--tag-color) 28%, transparent);
    font-size: 13px;
    font-weight: 500;
}

[data-theme="dark"] .cashback-tag.themed-color {
    --tag-color: var(--tag-color-dark, var(--tag-color-light, var(--accent)));
}

.cashback-tag-bank {
    color: var(--tag-color);
}

.cashback-tag-percent {
    color: var(--text);
    font-weight: 600;
}

/* ── Empty states ── */

.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-state.compact {
    padding: 24px;
}

.empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.empty-title {
    font-size: 17px;
    font-weight: 600;
    margin: 0 0 6px;
}

.empty-text {
    color: var(--text-secondary);
    margin: 0;
    font-size: 14px;
}

/* ── Settings tabs ── */

.settings-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
    padding: 4px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.settings-tab {
    flex: 1;
    min-width: max-content;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    text-decoration: none;
    transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.settings-tab:hover {
    color: var(--text);
    text-decoration: none;
}

.settings-tab.active {
    background: var(--bg-elevated);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* ── Settings row layout (actions on the right) ── */

.settings-row-form {
    display: flex;
    align-items: center;
    gap: 16px;
}

.settings-row-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-row-content > .input {
    width: 100%;
}

.settings-row-actions {
    display: flex;
    flex-direction: row;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--control-height);
    height: var(--control-height);
    min-width: var(--control-height);
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-muted);
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.btn-icon svg {
    width: 20px;
    height: 20px;
}

.btn-icon-save:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.btn-icon-danger {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: color-mix(in srgb, var(--danger) 20%, transparent);
}

.btn-icon-danger:hover {
    background: color-mix(in srgb, var(--danger) 18%, transparent);
    border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.btn-icon-primary {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.btn-icon-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.settings-add-form {
    display: flex;
    align-items: flex-end;
    gap: 16px;
}

.settings-add-fields {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.settings-add-fields > .input {
    width: 100%;
}

.settings-add-fields.ref-add-row-categories {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
}

.settings-add-actions {
    flex-shrink: 0;
}

.category-block {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.category-cashbacks {
    padding-top: 4px;
    border-top: 1px solid var(--border);
}

.category-cashbacks-head {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
}

.cashback-rows {
    list-style: none;
    padding: 0;
    margin: 0 0 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cashback-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.cashback-fields .cashback-owner,
.cashback-fields .cashback-bank {
    flex: 1;
    min-width: 130px;
}

.percent-field {
    position: relative;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: var(--control-height);
    max-width: 100%;
}

.input-percent {
    width: 72px;
    min-width: 72px;
    flex: none;
    min-height: var(--control-height);
    padding: 0 28px 0 10px !important;
    box-sizing: border-box;
}

.percent-suffix {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    pointer-events: none;
}

.cashback-form-add {
    padding-top: 4px;
}

/* ── Reference lists (banks, categories) ── */

.ref-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ref-item {
    padding: 12px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.owner-check-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--owner-color-light, var(--accent));
    flex-shrink: 0;
}

[data-theme="dark"] .owner-check-dot.themed-color {
    background: var(--owner-color-dark, var(--owner-color-light, var(--accent)));
}

.ref-fields {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.ref-fields .input {
    flex: 1;
    min-width: 120px;
}

.input-emoji {
    flex: 0 0 56px !important;
    min-width: 56px !important;
    min-height: var(--control-height) !important;
    text-align: center;
    font-size: 18px;
    padding: 0 8px !important;
}

.input-sort {
    flex: 0 0 72px !important;
    min-width: 72px !important;
    min-height: var(--control-height) !important;
    padding: 0 10px !important;
}

.settings-add-fields.ref-add-row-categories .input {
    flex: 1;
    min-width: 120px;
}

.settings-add-fields.ref-add-row-categories .input-emoji {
    flex: 0 0 56px;
    min-width: 56px;
}

.settings-add-fields.ref-add-row-categories .input-sort {
    flex: 0 0 72px;
    min-width: 72px;
}

/* ── Responsive ── */

@media (max-width: 640px) {
    .topbar-inner {
        flex-wrap: nowrap;
        padding: 10px 12px;
        gap: 8px;
    }

    .brand span {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .nav {
        order: 0;
        width: auto;
        flex: 1;
        min-width: 0;
        justify-content: flex-end;
        gap: 4px;
    }

    .nav-link {
        width: 40px;
        height: 40px;
        min-width: 40px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .nav-link-label {
        display: none;
    }

    .nav-link-icon {
        display: block;
    }

    .topbar-actions {
        gap: 6px;
    }

    .user-chip {
        padding: 0;
        border: none;
        background: none;
        gap: 0;
    }

    .user-chip-name {
        display: none;
    }

    .btn-logout {
        width: 40px;
        height: 40px;
        min-width: 40px;
        padding: 0;
        border: 1px solid var(--border);
        border-radius: var(--radius-full);
        background: var(--bg-subtle);
        color: var(--text-secondary);
    }

    .btn-logout:hover {
        background: var(--bg-muted);
        color: var(--text);
    }

    .btn-logout-label {
        display: none;
    }

    .btn-logout-icon {
        display: block;
    }

    .main {
        padding: 20px 16px 40px;
    }

    .page-title {
        font-size: 24px;
    }

    .period-picker {
        display: none;
    }

    .period-bar {
        justify-content: center;
    }

    .period-current {
        flex: 0 1 auto;
        justify-content: center;
    }

    .owner-card-top {
        flex-direction: column;
    }

    .owner-card-full {
        flex-direction: column;
    }

    .settings-row-form {
        flex-direction: column;
        align-items: stretch;
    }

    .settings-row-content,
    .bank-fields,
    .owner-fields,
    .ref-fields {
        width: 100%;
    }

    .ref-fields {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 10px;
        width: 100%;
    }

    .ref-fields .input-emoji {
        flex: 0 0 56px;
        width: 56px;
    }

    .ref-fields .category-name {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
    }

    .ref-fields .input-sort {
        flex: 0 0 72px;
        width: 72px;
    }

    .settings-add-fields.ref-add-row-categories {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 10px;
        width: 100%;
    }

    .settings-add-fields.ref-add-row-categories .input-emoji {
        flex: 0 0 56px;
        width: 56px;
    }

    .settings-add-fields.ref-add-row-categories .category-name {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
    }

    .settings-add-fields.ref-add-row-categories .input-sort {
        flex: 0 0 72px;
        width: 72px;
    }

    .settings-row-actions {
        flex-direction: row;
        justify-content: flex-end;
        width: 100%;
        min-width: 0;
    }

    .settings-add-form {
        flex-direction: column;
        align-items: stretch;
    }

    .settings-add-actions {
        display: flex;
        justify-content: flex-end;
    }

    .cashback-fields {
        flex-direction: column;
        align-items: stretch;
    }

    .cashback-fields .cashback-owner,
    .cashback-fields .cashback-bank {
        width: 100%;
        flex: none;
    }

    .percent-field {
        width: 100%;
        flex: none;
        max-width: 100%;
    }

    .input-percent {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        padding-right: 34px !important;
    }

    .percent-suffix {
        right: 14px;
    }

    select.input {
        background-position: right 20px center;
        padding-right: 46px;
    }

    .owner-avatar {
        display: none;
    }

    .owner-fields {
        flex-wrap: wrap;
    }

    .owner-add-row {
        flex-wrap: wrap;
    }

    .owner-add-row .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .auth-title {
        font-size: 26px;
    }

    .card {
        padding: 20px;
    }
}

/* Fallback for browsers without color-mix */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
    .cashback-tag {
        background: var(--bg-muted);
    }
}

/* ── PWA install banner ── */

.pwa-install {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.pwa-install-body {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.pwa-install-icon {
    border-radius: 10px;
    flex-shrink: 0;
}

.pwa-install-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.pwa-install-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.pwa-install-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.35;
}

.pwa-install-actions {
    display: flex;
    align-items: center;
    justify-content: stretch;
    gap: 10px;
}

.pwa-install-btn {
    flex: 1 1 auto;
    min-height: var(--control-height);
}

.pwa-install-close {
    flex-shrink: 0;
    white-space: nowrap;
}

@media (display-mode: standalone) {
    .topbar {
        padding-top: env(safe-area-inset-top, 0px);
    }

    .main {
        padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
    }

    .pwa-install {
        display: none;
    }
}
