  :root {
    color-scheme: light;
    --bg: #f4f7fc;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #14213d;
    --muted: #64748b;
    --border: #e2e8f0;

    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eff6ff;
    --navy: #172554;

    --income: #059669;
    --income-soft: #ecfdf5;
    --income-border: #a7f3d0;

    --expense: #dc2626;
    --expense-soft: #fef2f2;
    --expense-border: #fecaca;

    --purple: #7c3aed;
    --purple-soft: #f5f3ff;
    --purple-border: #ddd6fe;

    --amber: #d97706;
    --amber-soft: #fffbeb;
    --amber-border: #fde68a;

    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --shadow-sm: 0 8px 24px rgba(37, 50, 84, 0.06);
    --shadow-md: 0 18px 50px rgba(37, 50, 84, 0.11);

    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
      "Segoe UI", sans-serif;
  }

  * {
    box-sizing: border-box;
  }

  html {
    min-height: 100%;
    background: var(--bg);
  }

  body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
      radial-gradient(circle at 4% 4%, rgba(37, 99, 235, 0.12), transparent 25%),
      radial-gradient(circle at 96% 8%, rgba(124, 58, 237, 0.08), transparent 24%),
      linear-gradient(180deg, #f8fbff 0%, var(--bg) 42%, #f5f7fb 100%);
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
  }

  button {
    cursor: pointer;
  }

  svg {
    width: 1em;
    height: 1em;
  }

  .hidden {
    display: none !important;
  }

  .page-shell {
    width: min(1240px, calc(100% - 32px));
    margin: 0 auto;
    padding: 26px 0 48px;
  }

  /* Auth */
  .auth-view {
    min-height: calc(100vh - 74px);
    display: grid;
    place-items: center;
  }

  .auth-card {
    position: relative;
    width: min(100%, 460px);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.85);
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(18px);
  }

  .auth-content {
    position: relative;
    z-index: 1;
    padding: 36px;
  }

  .auth-decoration {
    position: absolute;
    border-radius: 999px;
    filter: blur(2px);
    pointer-events: none;
  }

  .auth-decoration-one {
    top: -90px;
    right: -70px;
    width: 220px;
    height: 220px;
    background: rgba(37, 99, 235, 0.14);
  }

  .auth-decoration-two {
    bottom: -100px;
    left: -80px;
    width: 220px;
    height: 220px;
    background: rgba(124, 58, 237, 0.1);
  }

  .auth-heading {
    margin: 0 0 24px;
  }

  .auth-heading h2 {
    margin: 7px 0 8px;
    font-size: clamp(1.5rem, 4vw, 2rem);
    line-height: 1.14;
    letter-spacing: -0.04em;
  }

  .auth-heading p {
    margin: 0;
    color: var(--muted);
    line-height: 1.65;
  }

  /* Brand and header */
  .brand {
    display: flex;
    align-items: center;
    gap: 14px;
  }

  .brand-center {
    margin-bottom: 28px;
  }

  .brand-mark {
    display: grid;
    width: 48px;
    height: 48px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 15px;
    color: #ffffff;
    background: linear-gradient(135deg, #172554, #2563eb 72%, #60a5fa);
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.25);
    font-weight: 850;
    letter-spacing: -0.04em;
  }

  .brand h1,
  .brand p,
  .panel h2,
  .panel p,
  .hero-strip h2,
  .hero-strip p {
    margin: 0;
  }

  .brand h1 {
    font-size: 1.16rem;
    letter-spacing: -0.025em;
  }

  .brand p,
  .panel p,
  .hero-strip p {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.88rem;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    padding: 14px 16px;
    border: 1px solid rgba(226, 232, 240, 0.85);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.78);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(14px);
  }

  .eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 850;
    letter-spacing: 0.09em;
    text-transform: uppercase;
  }

  .hero-strip {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 16px;
    padding: 4px 2px;
  }

  .hero-strip h2 {
    margin-top: 5px;
    font-size: clamp(1.65rem, 3vw, 2.2rem);
    letter-spacing: -0.045em;
  }

  .hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border: 1px solid var(--income-border);
    border-radius: 999px;
    color: var(--income);
    background: rgba(236, 253, 245, 0.85);
    font-size: 0.78rem;
    font-weight: 750;
    white-space: nowrap;
  }

  .hero-badge span {
    font-size: 0.7rem;
  }

  /* Forms */
  .stack-form,
  .transaction-form {
    display: grid;
    gap: 16px;
  }

  .stack-form label,
  .transaction-form label,
  .filters label {
    display: grid;
    gap: 7px;
    color: #334155;
    font-size: 0.86rem;
    font-weight: 720;
  }

  input,
  select,
  textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color 150ms ease, box-shadow 150ms ease,
      background 150ms ease;
  }

  input,
  select {
    min-height: 45px;
    padding: 0 13px;
  }

  textarea {
    min-height: 105px;
    resize: vertical;
    padding: 12px 13px;
  }

  input::placeholder,
  textarea::placeholder {
    color: #94a3b8;
  }

  input:hover,
  select:hover,
  textarea:hover {
    border-color: #cbd5e1;
  }

  input:focus,
  select:focus,
  textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  }

  .money-input {
    position: relative;
  }

  .money-input span {
    position: absolute;
    top: 50%;
    left: 13px;
    z-index: 1;
    color: var(--muted);
    font-weight: 800;
    transform: translateY(-50%);
    pointer-events: none;
  }

  .money-input input {
    padding-left: 40px;
  }

  .button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 12px;
    font-weight: 800;
    transition: transform 120ms ease, box-shadow 120ms ease,
      background 120ms ease, border-color 120ms ease;
  }

  .button:hover {
    transform: translateY(-1px);
  }

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

  .button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
  }

  .button-block {
    width: 100%;
  }

  .button-primary {
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    box-shadow: 0 9px 20px rgba(37, 99, 235, 0.2);
  }

  .button-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover), var(--primary));
    box-shadow: 0 12px 24px rgba(37, 99, 235, 0.26);
  }

  .form-mode-income .button-primary {
    background: linear-gradient(135deg, #047857, #10b981);
    box-shadow: 0 9px 20px rgba(5, 150, 105, 0.2);
  }

  .form-mode-income .button-primary:hover {
    background: linear-gradient(135deg, #047857, #059669);
  }

  .form-mode-expense .button-primary {
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
  }

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

  .button-secondary:hover,
  .button-ghost:hover {
    border-color: #cbd5e1;
    background: var(--surface-soft);
  }

  .button-ghost {
    border-color: var(--border);
    color: var(--text);
    background: rgba(255, 255, 255, 0.62);
  }

  .button-export {
    border-color: var(--income-border);
    color: #047857;
    background: var(--income-soft);
  }

  .button-export:hover {
    border-color: #6ee7b7;
    background: #d1fae5;
  }

  .form-hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.5;
    text-align: center;
  }

  /* Summary */
  .summary-section {
    margin-bottom: 20px;
  }

  .summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
  }

  .summary-card {
    position: relative;
    min-width: 0;
    overflow: hidden;
    padding: 19px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: transform 180ms ease, box-shadow 180ms ease;
  }

  .summary-card::after {
    content: "";
    position: absolute;
    right: -28px;
    bottom: -48px;
    width: 125px;
    height: 125px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.06;
  }

  .summary-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 32px rgba(37, 50, 84, 0.1);
  }

  .summary-card-top {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 13px;
  }

  .summary-icon {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 12px;
    font-size: 1.18rem;
  }

  .summary-label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
  }

  .summary-card strong {
    position: relative;
    z-index: 1;
    display: block;
    overflow: hidden;
    font-size: clamp(1.16rem, 2vw, 1.55rem);
    letter-spacing: -0.045em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .summary-card small {
    position: relative;
    z-index: 1;
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.4;
  }

  .balance-card {
    color: #1d4ed8;
    border-color: #bfdbfe;
    background: linear-gradient(145deg, #ffffff 25%, #eff6ff 100%);
  }

  .balance-card .summary-icon {
    color: #1d4ed8;
    background: #dbeafe;
  }

  .balance-card.balance-negative {
    color: var(--expense);
    border-color: var(--expense-border);
    background: linear-gradient(145deg, #ffffff 25%, var(--expense-soft) 100%);
  }

  .balance-card.balance-negative .summary-icon {
    color: var(--expense);
    background: #fee2e2;
  }

  .income-card {
    color: var(--income);
    border-color: var(--income-border);
    background: linear-gradient(145deg, #ffffff 25%, var(--income-soft) 100%);
  }

  .income-card .summary-icon {
    color: var(--income);
    background: #d1fae5;
  }

  .expense-card {
    color: var(--expense);
    border-color: var(--expense-border);
    background: linear-gradient(145deg, #ffffff 25%, var(--expense-soft) 100%);
  }

  .expense-card .summary-icon {
    color: var(--expense);
    background: #fee2e2;
  }

  .transaction-card {
    color: var(--purple);
    border-color: var(--purple-border);
    background: linear-gradient(145deg, #ffffff 25%, var(--purple-soft) 100%);
  }

  .transaction-card .summary-icon {
    color: var(--purple);
    background: #ede9fe;
  }

  /* Panels */
  .content-grid {
    display: grid;
    grid-template-columns: minmax(300px, 0.82fr) minmax(0, 1.68fr);
    gap: 20px;
    align-items: start;
  }

  .panel {
    position: relative;
    overflow: hidden;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.93);
    box-shadow: var(--shadow-sm);
  }

  .transaction-panel::before,
  .history-panel::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 4px;
  }

  .transaction-panel::before {
    background: linear-gradient(90deg, #2563eb, #60a5fa);
  }

  .transaction-panel.form-mode-income::before {
    background: linear-gradient(90deg, #059669, #34d399);
  }

  .history-panel::before {
    background: linear-gradient(90deg, #7c3aed, #a78bfa);
  }

  .panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
  }

  .panel-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .panel-icon {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 13px;
    font-size: 1.22rem;
  }

  .panel-icon-blue {
    color: var(--primary);
    background: var(--primary-soft);
  }

  .form-mode-income .panel-icon-blue {
    color: var(--income);
    background: var(--income-soft);
  }

  .panel-icon-purple {
    color: var(--purple);
    background: var(--purple-soft);
  }

  .transaction-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .full-width {
    grid-column: 1 / -1;
  }

  .form-actions {
    display: flex;
    gap: 10px;
  }

  .filters {
    display: grid;
    grid-template-columns: 160px 160px minmax(180px, 1fr) 135px;
    gap: 12px;
    align-items: end;
    margin-bottom: 18px;
    padding: 14px;
    border: 1px solid var(--purple-border);
    border-radius: 17px;
    background: linear-gradient(145deg, #fbfaff, var(--purple-soft));
  }

  .filters label {
    display: grid;
    gap: 7px;
    min-width: 0;
    color: #334155;
    font-size: 0.86rem;
    font-weight: 720;
  }

  .filter-search {
    min-width: 0;
  }

  .filter-button {
    width: 100%;
    min-height: 45px;
    white-space: nowrap;
  }

  /* Table */
  .table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 17px;
    background: var(--surface);
  }

  table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
  }

  th,
  td {
    padding: 14px 15px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
  }

  th {
    color: #64748b;
    background: #f8fafc;
    font-size: 0.75rem;
    font-weight: 850;
    letter-spacing: 0.045em;
    text-transform: uppercase;
  }

  td {
    font-size: 0.88rem;
  }

  tbody tr:last-child td {
    border-bottom: none;
  }

  tbody tr {
    transition: background 120ms ease;
  }

  tbody tr:hover {
    background: #f8fafc;
  }

  tbody tr.income-row:hover {
    background: #f0fdf8;
  }

  tbody tr.expense-row:hover {
    background: #fff8f8;
  }

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

  .badge {
    display: inline-flex;
    min-height: 27px;
    align-items: center;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 850;
    text-transform: capitalize;
  }

  .badge-income {
    border: 1px solid var(--income-border);
    color: var(--income);
    background: var(--income-soft);
  }

  .badge-expense {
    border: 1px solid var(--expense-border);
    color: var(--expense);
    background: var(--expense-soft);
  }

  .amount-income {
    color: var(--income);
    font-weight: 850;
  }

  .amount-expense {
    color: var(--expense);
    font-weight: 850;
  }

  .action-group {
    display: inline-flex;
    gap: 7px;
  }

  .action-button {
    min-height: 34px;
    padding: 0 11px;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 0.78rem;
    font-weight: 800;
  }

  .action-button:hover {
    border-color: #93c5fd;
    background: #dbeafe;
  }

  .action-button.delete {
    border-color: var(--expense-border);
    color: var(--danger);
    background: var(--danger-soft);
  }

  .action-button.delete:hover {
    background: #fee2e2;
  }

  .state-box {
    padding: 28px 18px;
    border: 1px dashed #cbd5e1;
    border-radius: 17px;
    color: var(--muted);
    background: var(--surface-soft);
    text-align: center;
  }

  /* Toast */
  .toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    max-width: min(390px, calc(100% - 40px));
    padding: 13px 16px;
    border: 1px solid var(--border);
    border-radius: 13px;
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
    transition: opacity 180ms ease, transform 180ms ease;
  }

  .toast.show {
    opacity: 1;
    transform: translateY(0);
  }

  .toast.error {
    border-color: var(--expense-border);
    color: var(--danger);
    background: var(--danger-soft);
  }

  .toast.success {
    border-color: var(--income-border);
    color: var(--income);
    background: var(--income-soft);
  }

  @media (max-width: 980px) {
    .summary-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .filters {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-search {
      grid-column: 1 / -1;
    }
  }

  @media (max-width: 620px) {
    .page-shell {
      width: min(100% - 20px, 1240px);
      padding-top: 12px;
    }

    .auth-content,
    .panel {
      padding: 19px;
    }

    .topbar {
      align-items: flex-start;
      border-radius: 17px;
    }

    .brand p {
      max-width: 190px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .hero-strip {
      align-items: flex-start;
      flex-direction: column;
    }

    .summary-grid {
      gap: 10px;
    }

    .summary-card {
      padding: 15px;
    }

    .summary-icon {
      width: 34px;
      height: 34px;
    }

    .transaction-form,
    .filters {
      grid-template-columns: 1fr;
    }

    .full-width,
    .filter-search {
      grid-column: auto;
    }

    .panel-heading-wrap {
      align-items: stretch;
      flex-direction: column;
    }

    .form-actions {
      flex-direction: column;
    }

    .filter-button,
    .button-export {
      width: 100%;
    }

    .toast {
      top: 12px;
      right: 10px;
      left: 10px;
      max-width: none;
    }
  }

  .chart-section {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
    gap: 20px;
    margin-bottom: 20px;
  }

  .chart-panel {
    min-height: 360px;
  }

  .chart-panel canvas {
    width: 100% !important;
    max-height: 280px;
  }

  @media (max-width: 980px) {
    .chart-section {
      grid-template-columns: 1fr;
    }
  }