:root {
  color-scheme: light;
  --bg-base: #eef3f9;
  --bg-soft: #dbe8f6;
  --bg-strong: #d2e2f4;
  --ink: #0f1826;
  --muted: #566279;
  --panel-1: rgba(255, 255, 255, 0.9);
  --panel-2: rgba(255, 255, 255, 0.78);
  --panel-solid: rgba(255, 255, 255, 0.97);
  --line: rgba(255, 255, 255, 0.86);
  --line-soft: rgba(13, 27, 49, 0.14);
  --line-faint: rgba(13, 27, 49, 0.08);
  --brand: #2a75eb;
  --brand-2: #1d59d0;
  --ok: #15945d;
  --warn: #c57a1a;
  --danger: #ce4258;
  --focus: rgba(42, 117, 235, 0.26);
  --glass-shadow: 0 22px 56px rgba(16, 30, 50, 0.18), 0 6px 18px rgba(16, 30, 50, 0.08);
  --glass-shadow-soft: 0 12px 26px rgba(16, 30, 50, 0.12);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --font-main: "Manrope", "SF Pro Display", "SF Pro Text", "Avenir Next", "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg-base: #0b111b;
  --bg-soft: #111b2a;
  --bg-strong: #152337;
  --ink: #e9f1fd;
  --muted: #9fb0c8;
  --panel-1: rgba(22, 34, 52, 0.9);
  --panel-2: rgba(19, 29, 45, 0.82);
  --panel-solid: rgba(21, 34, 52, 0.96);
  --line: rgba(114, 143, 176, 0.5);
  --line-soft: rgba(173, 199, 228, 0.24);
  --line-faint: rgba(173, 199, 228, 0.12);
  --brand: #67a8ff;
  --brand-2: #3d8af0;
  --ok: #59d69f;
  --warn: #f0b45a;
  --danger: #ef7a8d;
  --focus: rgba(103, 168, 255, 0.34);
  --glass-shadow: 0 28px 64px rgba(1, 7, 16, 0.6), 0 10px 24px rgba(1, 7, 16, 0.45);
  --glass-shadow-soft: 0 12px 24px rgba(1, 7, 16, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg-base: #0b111b;
    --bg-soft: #111b2a;
    --bg-strong: #152337;
    --ink: #e9f1fd;
    --muted: #9fb0c8;
    --panel-1: rgba(22, 34, 52, 0.9);
    --panel-2: rgba(19, 29, 45, 0.82);
    --panel-solid: rgba(21, 34, 52, 0.96);
    --line: rgba(114, 143, 176, 0.5);
    --line-soft: rgba(173, 199, 228, 0.24);
    --line-faint: rgba(173, 199, 228, 0.12);
    --brand: #67a8ff;
    --brand-2: #3d8af0;
    --ok: #59d69f;
    --warn: #f0b45a;
    --danger: #ef7a8d;
    --focus: rgba(103, 168, 255, 0.34);
    --glass-shadow: 0 28px 64px rgba(1, 7, 16, 0.6), 0 10px 24px rgba(1, 7, 16, 0.45);
    --glass-shadow-soft: 0 12px 24px rgba(1, 7, 16, 0.45);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-main);
  font-weight: 600;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(84, 155, 255, 0.32), transparent 30%),
    radial-gradient(circle at 92% 14%, rgba(71, 201, 160, 0.24), transparent 35%),
    radial-gradient(circle at 84% 86%, rgba(127, 114, 255, 0.15), transparent 34%),
    linear-gradient(160deg, var(--bg-base), var(--bg-soft) 52%, var(--bg-strong));
  letter-spacing: -0.01em;
}

body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(56px);
  z-index: 0;
}

body::before {
  width: 380px;
  height: 380px;
  top: -120px;
  left: -80px;
  background: rgba(114, 170, 255, 0.16);
}

body::after {
  width: 320px;
  height: 320px;
  right: -80px;
  bottom: -120px;
  background: rgba(108, 214, 180, 0.14);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

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

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.68rem;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(140deg, var(--panel-solid), var(--panel-1));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.48);
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 82%, transparent);
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 2rem;
  background-image:
    linear-gradient(45deg, transparent 50%, color-mix(in srgb, var(--muted) 90%, transparent) 50%),
    linear-gradient(135deg, color-mix(in srgb, var(--muted) 90%, transparent) 50%, transparent 50%);
  background-position:
    calc(100% - 15px) calc(50% - 2px),
    calc(100% - 10px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

input:focus,
select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--brand) 58%, var(--line-soft));
  box-shadow: 0 0 0 3px var(--focus), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

button,
.btn-link {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.52rem 0.78rem;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}

button {
  color: #ffffff;
  background: linear-gradient(138deg, var(--brand), var(--brand-2));
  box-shadow: 0 10px 18px color-mix(in srgb, var(--brand) 35%, transparent);
}

button:hover,
.btn-link:hover {
  filter: brightness(1.04);
}

button:active,
.btn-link:active {
  transform: translateY(1px);
}

button.ghost,
.profile-trigger,
.btn-link {
  border-color: var(--line-soft);
  color: var(--ink);
  background: linear-gradient(140deg, var(--panel-solid), var(--panel-1));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.44);
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  min-height: 2.1rem;
}

button.danger {
  background: linear-gradient(140deg, #df5d72, #c43c52);
}

.page {
  position: relative;
  z-index: 1;
  width: min(1360px, calc(100vw - 1.1rem));
  margin: 0.5rem auto 1rem;
  animation: page-in 280ms ease-out;
}

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

.bg-ornament {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 75% 72%, rgba(255, 255, 255, 0.46), transparent 34%),
    radial-gradient(circle at 20% 82%, rgba(255, 255, 255, 0.3), transparent 24%);
  mix-blend-mode: soft-light;
  opacity: 0.58;
  z-index: 0;
}

.glass,
.topbar,
.control-panel,
.stat-card,
.budget-card,
.auth-card,
.profile-panel,
.modal-dialog,
.theme-switcher,
.flash,
.autosave-status {
  border: 1px solid var(--line);
  background: linear-gradient(140deg, var(--panel-solid), var(--panel-1));
  backdrop-filter: blur(16px) saturate(130%);
  -webkit-backdrop-filter: blur(16px) saturate(130%);
  box-shadow: var(--glass-shadow);
}

.theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  padding: 0.26rem 0.4rem;
  box-shadow: var(--glass-shadow-soft);
}

.theme-switcher label {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--muted);
  margin-left: 0.25rem;
}

.theme-switcher select {
  width: 100px;
  font-size: 0.74rem;
  border-radius: 999px;
  padding: 0.34rem 1.75rem 0.34rem 0.6rem;
}

.theme-switcher-global {
  position: fixed;
  top: max(0.55rem, env(safe-area-inset-top));
  right: max(0.62rem, env(safe-area-inset-right));
  z-index: 50;
}

.auth-shell {
  min-height: calc(100vh - 1.8rem);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(440px, 100%);
  border-radius: var(--radius-xl);
  padding: 1.15rem;
}

.auth-card h1 {
  font-size: clamp(1.42rem, 2.4vw, 1.66rem);
  font-weight: 900;
  letter-spacing: -0.02em;
}

.auth-form {
  margin-top: 0.85rem;
  display: grid;
  gap: 0.48rem;
}

.auth-form label {
  font-size: 0.79rem;
  font-weight: 800;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.checkbox-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
}

.hint {
  margin-top: 0.72rem;
}

.auth-links {
  margin-top: 0.64rem;
}

.auth-links a {
  color: var(--brand-2);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.auth-links a:hover {
  text-decoration: underline;
}

.dashboard-shell {
  display: grid;
  gap: 0.58rem;
}

.topbar {
  border-radius: var(--radius-xl);
  padding: 0.68rem 0.82rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  position: relative;
  z-index: 70;
  overflow: visible;
}

.topbar h1 {
  font-size: clamp(1.02rem, 1.7vw, 1.34rem);
  font-weight: 900;
  letter-spacing: -0.02em;
}

.topbar p {
  margin-top: 0.12rem;
  font-size: 0.76rem;
}

.top-actions {
  display: inline-flex;
  align-items: center;
}

.profile-menu {
  position: relative;
  z-index: 80;
}

.profile-trigger {
  list-style: none;
  user-select: none;
  font-size: 0.8rem;
  font-weight: 900;
  border-radius: 999px;
  padding: 0.5rem 0.72rem;
}

.profile-trigger::-webkit-details-marker {
  display: none;
}

.profile-trigger::after {
  content: " ▾";
  font-size: 0.7rem;
}

.profile-menu[open] .profile-trigger::after {
  content: " ▴";
}

.profile-panel {
  position: absolute;
  top: calc(100% + 0.42rem);
  right: 0;
  width: min(440px, 95vw);
  max-height: min(80vh, 800px);
  overflow: auto;
  border-radius: var(--radius-lg);
  padding: 0.62rem;
  display: grid;
  gap: 0.55rem;
  z-index: 90;
}

.profile-head {
  padding-bottom: 0.46rem;
  border-bottom: 1px solid var(--line-faint);
}

.profile-head strong {
  font-size: 0.82rem;
  font-weight: 900;
}

.profile-section {
  display: grid;
  gap: 0.38rem;
}

.profile-section label,
.profile-section h4 {
  font-size: 0.74rem;
  font-weight: 900;
  color: var(--muted);
  margin: 0;
}

.deleted-list {
  display: grid;
  gap: 0.32rem;
}

.deleted-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.42rem;
  padding: 0.36rem 0.44rem;
  border: 1px solid var(--line-faint);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--panel-1) 92%, transparent);
}

.deleted-item strong {
  display: block;
  font-size: 0.77rem;
  font-weight: 850;
}

.deleted-item small {
  display: block;
  font-size: 0.67rem;
  margin-top: 0.04rem;
}

.deleted-item button {
  min-height: 1.7rem;
  padding: 0.28rem 0.56rem;
  font-size: 0.7rem;
}

.profile-logout {
  width: 100%;
}

.profile-form {
  grid-template-columns: 1fr;
}

.control-panel {
  border-radius: var(--radius-lg);
  padding: 0.62rem;
}

.control-meta {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 0.45rem;
  margin-bottom: 0.46rem;
}

.control-meta strong {
  font-size: 0.82rem;
  font-weight: 900;
}

.control-actions {
  display: flex;
  justify-content: flex-end;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 0.45rem;
}

.stat-card {
  border-radius: var(--radius-md);
  padding: 0.56rem 0.66rem;
  box-shadow: var(--glass-shadow-soft);
}

.stat-card p {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 800;
}

.stat-card h2,
.stat-card h3 {
  margin-top: 0.14rem;
  font-size: 1.02rem;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.stat-card.soft {
  background: linear-gradient(
      135deg,
      color-mix(in srgb, var(--panel-1) 88%, rgba(147, 221, 193, 0.22)),
      color-mix(in srgb, var(--panel-2) 84%, rgba(139, 198, 255, 0.2))
    );
}

.status-pill {
  margin-top: 0.24rem;
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.46rem;
  font-size: 0.68rem;
  font-weight: 900;
  border: 1px solid transparent;
}

.status-pill.good {
  color: color-mix(in srgb, var(--ok) 90%, black 10%);
  background: color-mix(in srgb, var(--ok) 18%, transparent);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
}

.status-pill.bad {
  color: color-mix(in srgb, var(--danger) 88%, black 12%);
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
}

.dashboard-form {
  display: grid;
  gap: 0.5rem;
}

.sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.5rem;
}

.budget-card,
.password-card {
  border-radius: var(--radius-lg);
  padding: 0.58rem 0.64rem;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.32rem;
}

.card-head h3 {
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.subtotal {
  color: var(--ok);
  font-size: 0.8rem;
  font-weight: 900;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line-faint);
  padding: 0.28rem 0;
  vertical-align: middle;
}

th {
  font-size: 0.64rem;
  font-weight: 900;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td {
  font-size: 0.81rem;
  font-weight: 750;
}

tbody tr {
  transition: background 140ms ease;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--panel-1) 42%, transparent);
}

td input {
  max-width: 112px;
  padding-top: 0.44rem;
  padding-bottom: 0.44rem;
}

.row-chip {
  margin-left: 0.34rem;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--panel-1) 88%, transparent);
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 800;
  padding: 0.1rem 0.36rem;
}

.actions-cell {
  text-align: right;
}

.compact-btn {
  padding: 0;
}

.icon-delete {
  width: 1.5rem;
  height: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: none;
  filter: none;
  transform: none;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.icon-delete:hover {
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border-color: color-mix(in srgb, var(--danger) 18%, transparent);
  color: var(--danger);
  box-shadow: none;
  filter: none;
}

.icon-delete:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 22%, transparent);
}

.autosave-status {
  justify-self: end;
  border-radius: 999px;
  padding: 0.18rem 0.52rem;
  font-size: 0.69rem;
  font-weight: 900;
  border: 1px solid transparent;
  box-shadow: var(--glass-shadow-soft);
}

.autosave-status.ok {
  color: color-mix(in srgb, var(--ok) 90%, black 10%);
  background: color-mix(in srgb, var(--ok) 18%, var(--panel-2));
  border-color: color-mix(in srgb, var(--ok) 32%, transparent);
}

.autosave-status.saving {
  color: color-mix(in srgb, var(--brand) 90%, black 10%);
  background: color-mix(in srgb, var(--brand) 16%, var(--panel-2));
  border-color: color-mix(in srgb, var(--brand) 28%, transparent);
}

.autosave-status.error {
  color: color-mix(in srgb, var(--danger) 90%, black 10%);
  background: color-mix(in srgb, var(--danger) 15%, var(--panel-2));
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
}

.backup-actions {
  display: grid;
  gap: 0.42rem;
}

.restore-form,
.password-form {
  display: grid;
  gap: 0.36rem;
  grid-template-columns: 1fr auto;
}

.restore-form input[type="file"] {
  border: 1px dashed var(--line-soft);
  background: linear-gradient(140deg, var(--panel-solid), var(--panel-1));
  padding: 0.45rem 0.55rem;
}

.flash-stack {
  display: grid;
  gap: 0.34rem;
}

.flash {
  border-radius: var(--radius-sm);
  padding: 0.38rem 0.54rem;
  font-size: 0.75rem;
  font-weight: 900;
}

.flash-success {
  color: color-mix(in srgb, var(--ok) 90%, black 10%);
  border-color: color-mix(in srgb, var(--ok) 34%, transparent);
  background: color-mix(in srgb, var(--ok) 16%, var(--panel-2));
}

.flash-error {
  color: color-mix(in srgb, var(--danger) 90%, black 10%);
  border-color: color-mix(in srgb, var(--danger) 34%, transparent);
  background: color-mix(in srgb, var(--danger) 14%, var(--panel-2));
}

.modal-dialog {
  border-radius: var(--radius-lg);
  width: min(470px, calc(100vw - 1.2rem));
  padding: 0;
}

.modal-dialog::backdrop {
  background: rgba(6, 14, 27, 0.48);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-form {
  padding: 0.74rem;
  display: grid;
  gap: 0.44rem;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h3 {
  font-size: 0.92rem;
  font-weight: 900;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.34rem;
}

@media (max-width: 920px) {
  .control-meta {
    grid-template-columns: 1fr;
  }

  .restore-form,
  .password-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .page {
    width: calc(100vw - 0.78rem);
    margin: 0.4rem auto 0.74rem;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions > * {
    width: 100%;
  }

  .profile-trigger,
  .btn-link,
  .top-actions button {
    width: 100%;
  }

  .profile-panel {
    width: min(96vw, 440px);
    right: 0;
  }

  .sections-grid {
    grid-template-columns: 1fr;
  }

  td input {
    max-width: 102px;
  }

  .theme-switcher-global {
    right: 0.4rem;
    top: 0.4rem;
    padding: 0.2rem 0.28rem;
  }

  .theme-switcher-global label {
    display: none;
  }

  .theme-switcher-global select {
    width: 92px;
  }
}
