:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #171f2b;
  --line: #253141;
  --text: #f3f6fa;
  --muted: #8a94a6;
  --green: #35d07f;
  --red: #ff4d4d;
  --violet: #6c5ce7;
  --cyan: #46c7e8;
  --card-radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Inter, Manrope, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
  background:
    radial-gradient(circle at 14% 12%, rgba(108, 92, 231, 0.2), transparent 30%),
    radial-gradient(circle at 85% 6%, rgba(70, 199, 232, 0.12), transparent 24%),
    linear-gradient(135deg, #0b0f14 0%, #101722 55%, #0b0f14 100%);
}

button,
input {
  font: inherit;
}

.login-body {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding:
    max(24px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.login-shell {
  width: min(420px, 100%);
}

.login-card,
.panel,
.stat-card {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.035));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.login-card {
  padding: 32px;
  border-radius: var(--card-radius);
}

.eyebrow {
  display: inline-flex;
  margin-bottom: 14px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 58px;
  line-height: 1;
  letter-spacing: 0;
}

.login-card h1 {
  font-size: 42px;
}

.login-card p,
.topbar p,
.panel-head p {
  color: var(--muted);
  margin-top: 10px;
}

.login-form {
  margin-top: 28px;
  display: grid;
  gap: 12px;
}

label {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--card-radius);
  outline: none;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 12px 13px;
  min-height: 46px;
}

input:focus,
input:focus-visible {
  border-color: rgba(108, 92, 231, 0.85);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.18);
}

button {
  border: 0;
  border-radius: var(--card-radius);
  cursor: pointer;
  color: white;
  background: linear-gradient(135deg, var(--violet), #c148d8);
  padding: 12px 16px;
  font-weight: 800;
  min-height: 46px;
  touch-action: manipulation;
}

button:hover {
  filter: brightness(1.08);
}

.ghost-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
}

.error-box {
  margin-top: 18px;
  border: 1px solid rgba(255, 77, 77, 0.35);
  border-radius: var(--card-radius);
  color: #ffb2b2;
  background: rgba(255, 77, 77, 0.1);
  padding: 12px;
}

.app-shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding:
    max(32px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  min-height: 132px;
  border-radius: var(--card-radius);
  padding: 22px;
}

.stat-card span,
.stat-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin: 12px 0 8px;
  color: var(--red);
  font-size: 46px;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat-card.accent strong,
.stat-card.positive strong {
  color: var(--green);
}

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

.panel {
  overflow: hidden;
  border-radius: var(--card-radius);
}

.panel-head {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.panel h2 {
  font-size: 22px;
  letter-spacing: 0;
}

.rows {
  min-height: 230px;
  max-height: 52vh;
  overflow: auto;
}

.row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 140px;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.row-date {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.row-main {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.income-row .row-main {
  display: grid;
  gap: 3px;
}

.income-row span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
}

.row-amount {
  text-align: right;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.negative {
  color: var(--red);
}

.positive {
  color: var(--green);
}

.entry-form {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) 132px 44px;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.035);
}

.income-form {
  grid-template-columns: 128px 132px minmax(0, 1fr) minmax(0, 1fr) 44px;
}

.entry-form button {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

@media (max-width: 980px) {
  .topbar,
  .tables-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .entry-form,
  .income-form {
    grid-template-columns: 1fr;
  }

  .entry-form button {
    width: 100%;
  }
}

@media (max-width: 720px) {
  body {
    min-height: 100svh;
    background:
      linear-gradient(180deg, rgba(70, 199, 232, 0.12), transparent 220px),
      radial-gradient(circle at 50% -70px, rgba(108, 92, 231, 0.36), transparent 260px),
      #0b0f14;
  }

  h1 {
    font-size: 34px;
    line-height: 1.02;
  }

  .login-body {
    align-items: start;
    padding-top: max(34px, env(safe-area-inset-top));
  }

  .login-card {
    padding: 24px;
  }

  .login-card h1 {
    font-size: 36px;
  }

  .login-card p {
    font-size: 14px;
    line-height: 1.45;
  }

  .app-shell {
    padding:
      max(18px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(18px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 12px;
    margin-bottom: 14px;
  }

  .topbar .eyebrow {
    margin-bottom: 10px;
  }

  .topbar p {
    max-width: 260px;
    margin-top: 8px;
    font-size: 13px;
    line-height: 1.35;
  }

  .ghost-button {
    min-height: 44px;
    padding: 9px 12px;
    font-size: 14px;
  }

  .stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }

  #balance-card {
    order: -1;
    grid-column: 1 / -1;
    min-height: 128px;
    background:
      linear-gradient(145deg, rgba(255, 77, 77, 0.16), rgba(255, 255, 255, 0.055)),
      var(--panel);
  }

  #balance-card.positive {
    background:
      linear-gradient(145deg, rgba(53, 208, 127, 0.16), rgba(255, 255, 255, 0.055)),
      var(--panel);
  }

  #balance-card strong {
    font-size: 44px;
  }

  .stat-card {
    min-height: 108px;
    padding: 15px;
  }

  .stat-card span,
  .stat-card small {
    font-size: 10px;
    line-height: 1.3;
  }

  .stat-card strong {
    margin: 10px 0 7px;
    font-size: 27px;
  }

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

  .panel-head {
    padding: 16px;
  }

  .panel h2 {
    font-size: 20px;
    line-height: 1.15;
  }

  .panel-head p {
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.35;
  }

  .rows {
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 2px 0 10px;
  }

  .row {
    grid-template-areas:
      "main amount"
      "date amount";
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 12px;
    align-items: center;
    min-height: 76px;
    margin: 10px 10px 0;
    padding: 13px 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--card-radius);
    background: rgba(255, 255, 255, 0.045);
  }

  .row-date {
    grid-area: date;
    font-size: 12px;
  }

  .row-main {
    grid-area: main;
    white-space: normal;
    line-height: 1.25;
  }

  .income-row .row-main {
    gap: 4px;
  }

  .row-amount {
    grid-area: amount;
    align-self: center;
    text-align: right;
    font-size: 16px;
    white-space: nowrap;
  }

  .entry-form,
  .income-form {
    position: sticky;
    bottom: 0;
    z-index: 3;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
    background: rgba(11, 15, 20, 0.88);
    backdrop-filter: blur(18px);
  }

  .entry-form input,
  .entry-form button {
    min-height: 50px;
    font-size: 16px;
  }

  .entry-form input[name="description"],
  .income-form input[name="description"],
  .income-form input[name="company"],
  .entry-form button {
    grid-column: 1 / -1;
  }

  .entry-form button {
    height: 52px;
    font-size: 26px;
  }
}

@media (max-width: 380px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .ghost-button {
    width: 100%;
  }

  .stats-grid,
  .entry-form,
  .income-form {
    grid-template-columns: 1fr;
  }

  #balance-card {
    grid-column: auto;
  }
}
