:root {
  --bg-start: #050816;
  --bg-mid: #0b1430;
  --bg-end: #14162f;
  --surface: rgba(10, 16, 34, 0.68);
  --surface-strong: rgba(14, 21, 45, 0.9);
  --text: #eff5ff;
  --muted: #a5b3cc;
  --border: rgba(173, 196, 255, 0.14);
  --primary: #ff5f9b;
  --primary-2: #ffb84d;
  --accent: #53c7ff;
  --accent-2: #8d7bff;
  --success: #39d98a;
  --danger: #ff607e;
  --shadow: 0 30px 70px rgba(0, 0, 0, 0.38);
  --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.22);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) max(env(safe-area-inset-bottom), 0px) env(safe-area-inset-left);
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 95, 155, 0.18), transparent 28%),
    radial-gradient(circle at 85% 12%, rgba(83, 199, 255, 0.2), transparent 26%),
    radial-gradient(circle at 15% 78%, rgba(141, 123, 255, 0.18), transparent 30%),
    linear-gradient(145deg, var(--bg-start), var(--bg-mid) 48%, var(--bg-end));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  filter: blur(16px);
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
  animation: drift 16s ease-in-out infinite;
}

body::before {
  top: -120px;
  right: -80px;
  background: radial-gradient(circle, rgba(255, 95, 155, 0.26), rgba(255, 95, 155, 0));
}

body::after {
  bottom: -140px;
  left: -100px;
  background: radial-gradient(circle, rgba(83, 199, 255, 0.22), rgba(83, 199, 255, 0));
  animation-delay: -8s;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Bricolage Grotesque", "Trebuchet MS", sans-serif;
  letter-spacing: 0.2px;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100vw - 24px));
  margin: 16px auto 24px;
  display: grid;
  gap: 16px;
  animation: fade-up 0.8s ease both;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(env(safe-area-inset-top), 16px) 12px max(env(safe-area-inset-bottom), 16px);
  position: relative;
  z-index: 1;
}

.auth-card {
  width: min(560px, 100%);
  padding: 20px 16px;
  display: grid;
  gap: 16px;
}

.auth-card h1 {
  font-size: clamp(2.4rem, 5vw, 4rem);
  line-height: 0.96;
  background: linear-gradient(104deg, #ff6aa7, #ffd56b 34%, #7ce8ff 68%, #b29cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 14px 34px rgba(124, 232, 255, 0.24);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-chips {
  justify-content: flex-start;
}

.hero {
  text-align: center;
  padding: 8px 8px 0;
  display: grid;
  gap: 8px;
  justify-items: center;
}

.session-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.session-badge {
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(83, 199, 255, 0.08);
  border: 1px solid rgba(83, 199, 255, 0.14);
  color: #dfeeff;
  font-size: 0.84rem;
  font-weight: 700;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(10, 16, 34, 0.72);
  color: #dce8ff;
  border: 1px solid rgba(173, 196, 255, 0.2);
  box-shadow: var(--shadow-soft);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hero h1 {
  font-size: clamp(1.9rem, 10.5vw, 3rem);
  line-height: 0.95;
  background: linear-gradient(104deg, #ff70ac, #ffd86f 34%, #7ce8ff 68%, #b79fff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow:
    0 10px 28px rgba(124, 232, 255, 0.18),
    0 0 24px rgba(183, 159, 255, 0.18);
  letter-spacing: 0.02em;
}

.subtitle {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.65;
}

.hero-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.hero-chips span {
  padding: 8px 11px;
  border-radius: 999px;
  background: rgba(10, 16, 34, 0.78);
  border: 1px solid rgba(173, 196, 255, 0.16);
  box-shadow: var(--shadow-soft);
  color: #dce8ff;
  font-size: 0.82rem;
  font-weight: 700;
  backdrop-filter: blur(16px);
}

.panel,
.card {
  position: relative;
  background: linear-gradient(180deg, var(--surface-strong), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel {
  padding: 16px;
}

.panel::before,
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0.02));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.panel h2 {
  font-size: 1.12rem;
  margin-bottom: 10px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid-2 {
  grid-template-columns: 1fr;
}

.grid-3 {
  grid-template-columns: 1fr;
}

.grid-4 {
  grid-template-columns: 1fr;
  align-items: end;
}

.purchase-form {
  display: grid;
  gap: 14px;
}

.items-stack {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: end;
}

.plus-item-btn {
  min-width: 48px;
  font-size: 1.15rem;
  line-height: 1;
}

.remove-item-btn {
  min-width: 86px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 700;
  color: #d8e5ff;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
  border-radius: 16px;
  border: 1px solid rgba(173, 196, 255, 0.16);
  padding: 12px 13px;
  background: rgba(7, 12, 25, 0.9);
  color: var(--text);
  outline: none;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease,
    background-color 0.18s ease;
}

input:hover,
select:hover {
  background: rgba(10, 17, 35, 0.98);
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(83, 199, 255, 0.16), 0 12px 28px rgba(83, 199, 255, 0.12);
  transform: translateY(-1px);
}

.btn {
  border: none;
  border-radius: 14px;
  min-height: 44px;
  padding: 11px 16px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    opacity 0.18s ease,
    filter 0.18s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.2);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn.primary {
  color: white;
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  box-shadow: 0 14px 30px rgba(255, 92, 138, 0.22);
}

.btn.primary:hover {
  filter: saturate(1.05) brightness(1.01);
}

.btn.ghost {
  color: #dce8ff;
  background: rgba(10, 16, 34, 0.82);
  border: 1px solid rgba(173, 196, 255, 0.18);
}

.btn.active-login {
  color: #ffffff;
  background: linear-gradient(120deg, #1f9ded, #0f7dc4);
  border-color: transparent;
}

.btn.danger {
  color: white;
  background: linear-gradient(120deg, #ff5e84, var(--danger));
  box-shadow: 0 14px 30px rgba(255, 96, 126, 0.24);
}

.stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.card {
  padding: 17px;
  overflow: hidden;
}

.card:nth-child(1)::after,
.card:nth-child(2)::after,
.card:nth-child(3)::after,
.card:nth-child(4)::after {
  content: "";
  position: absolute;
  inset: auto -18px -20px auto;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  opacity: 0.18;
  filter: blur(2px);
  pointer-events: none;
}

.card:nth-child(1)::after {
  background: radial-gradient(circle, #ffb54a 0%, transparent 68%);
}

.card:nth-child(2)::after {
  background: radial-gradient(circle, #18a9f1 0%, transparent 68%);
}

.card:nth-child(3)::after {
  background: radial-gradient(circle, #6d79ff 0%, transparent 68%);
}

.card:nth-child(4)::after {
  background: radial-gradient(circle, #2ebd74 0%, transparent 68%);
}

.card h3 {
  font-size: 0.92rem;
  color: #b8c7e1;
  margin-bottom: 8px;
}

.card p {
  margin: 0;
  font-size: 1.36rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.settlement {
  margin: 0;
  font-weight: 700;
  color: #d9efff;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(83, 199, 255, 0.1);
  border: 1px solid rgba(83, 199, 255, 0.14);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-panel {
  background:
    radial-gradient(circle at 110% -20%, rgba(84, 205, 255, 0.14), transparent 38%),
    radial-gradient(circle at -15% 120%, rgba(255, 111, 163, 0.12), transparent 34%),
    linear-gradient(165deg, rgba(2, 4, 10, 0.96), rgba(5, 8, 20, 0.95));
  border-color: rgba(153, 180, 238, 0.22);
}

.history-head {
  align-items: flex-end;
}

.history-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.history-filter {
  min-width: 185px;
}

.history-filter select {
  min-width: 185px;
}

.history-meta {
  margin: 12px 2px 0;
  color: #9db1d6;
  font-size: 0.86rem;
  font-weight: 600;
}

.history-footer {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.table-wrap {
  overflow-x: hidden;
  border-radius: 18px;
  border: 1px solid rgba(124, 148, 206, 0.2);
  background: rgba(3, 5, 13, 0.9);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: linear-gradient(90deg, rgba(255, 95, 155, 0.12), rgba(83, 199, 255, 0.12));
}

th,
td {
  text-align: left;
  padding: 13px 12px;
  border-bottom: 1px solid rgba(173, 196, 255, 0.1);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

th {
  font-size: 0.84rem;
  color: #b5c4de;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td {
  font-size: 0.95rem;
}

td::before {
  content: none;
}

tbody tr {
  transition: background-color 0.16s ease, transform 0.16s ease;
}

tbody tr:hover {
  background: rgba(83, 199, 255, 0.07);
}

.month-row td {
  border-bottom: 1px solid rgba(173, 196, 255, 0.12);
  background: linear-gradient(90deg, rgba(26, 35, 65, 0.9), rgba(11, 18, 36, 0.7));
  color: #d8e8ff;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 12px;
}

.is-editing {
  background: rgba(83, 199, 255, 0.1);
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.is-editing input,
.is-editing select {
  min-width: 0;
}

.row-lock {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(173, 196, 255, 0.12);
  color: #9fb2d3;
  font-size: 0.86rem;
  font-weight: 700;
}

.empty-state {
  margin: 14px 0 2px;
  color: #9ab0d0;
  font-weight: 600;
}

/* -----------------------
   UTILITIES
------------------------ */
.hidden {
  display: none !important;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drift {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }

  50% {
    transform: translate3d(0, 18px, 0) scale(1.05);
  }
}

@media (max-width: 359px) {
  body::before,
  body::after {
    display: none;
  }
}

@media (min-width: 480px) {
  body::before,
  body::after {
    width: 280px;
    height: 280px;
  }

  .app-shell {
    width: min(1120px, calc(100vw - 36px));
    margin-top: 18px;
    margin-bottom: 30px;
  }

  .auth-shell {
    padding: max(env(safe-area-inset-top), 20px) 16px max(env(safe-area-inset-bottom), 20px);
  }

  .auth-card {
    padding: 24px;
  }

  .hero h1 {
    font-size: clamp(2.15rem, 8.8vw, 3.5rem);
  }

  .stats {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (min-width: 768px) {
  body::before,
  body::after {
    width: 320px;
    height: 320px;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .item-row {
    grid-template-columns: 1fr 1fr auto auto;
  }

  .remove-item-btn {
    grid-column: auto;
  }

  .session-bar .btn {
    width: auto;
  }
}

@media (min-width: 1024px) {
  body::before,
  body::after {
    width: 360px;
    height: 360px;
  }

  .app-shell {
    width: min(1120px, 94vw);
    margin: 24px auto 44px;
  }

  .auth-shell {
    padding: 24px;
  }

  .auth-card {
    padding: 28px;
  }

  .hero h1 {
    font-size: clamp(2.6rem, 5.8vw, 4.8rem);
  }

  .subtitle {
    font-size: 1.02rem;
  }

  .grid-4,
  .stats {
    grid-template-columns: repeat(4, minmax(140px, 1fr));
  }
}

@media (max-width: 640px) {
  .hero {
    padding-top: 2px;
  }

  .subtitle {
    font-size: 0.9rem;
    line-height: 1.45;
  }

  .hero-chips {
    display: none;
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .stats {
    grid-template-columns: 1fr;
  }

  .item-row {
    grid-template-columns: 1fr;
  }

  .plus-item-btn,
  .remove-item-btn {
    grid-column: span 1;
    width: 100%;
  }

  .panel-head {
    align-items: flex-start;
  }

  .history-head {
    gap: 10px;
  }

  .history-controls {
    width: 100%;
    display: grid;
    gap: 8px;
  }

  .history-filter,
  .history-filter select,
  #downloadPdfBtn,
  #showMoreHistoryBtn {
    width: 100%;
    min-width: 0;
  }

  .history-meta {
    margin-left: 0;
    margin-right: 0;
  }

  .settlement {
    width: 100%;
    text-align: center;
  }

  .session-bar {
    align-items: center;
    justify-content: center;
    position: static;
    backdrop-filter: blur(16px);
    background: rgba(10, 16, 34, 0.85);
    padding: 8px;
    border-radius: 16px;
    border: 1px solid rgba(173, 196, 255, 0.14);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
    margin-top: 4px;
  }

  .session-badge {
    width: 100%;
    text-align: center;
  }

  .session-bar .btn {
    width: auto;
    min-width: 132px;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
    border-radius: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tbody tr {
    border: 1px solid rgba(173, 196, 255, 0.14);
    border-radius: 14px;
    background: rgba(7, 12, 25, 0.76);
    padding: 12px;
  }

  tbody tr.month-row {
    border: 0;
    padding: 0;
    background: transparent;
  }

  td {
    padding: 0;
    border: 0;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(84px, 36%) 1fr;
    align-items: start;
    font-size: 0.92rem;
  }

  td + td {
    margin-top: 10px;
  }

  td::before {
    content: attr(data-label);
    color: #9fb2d3;
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.35;
  }

  .row-actions {
    width: 100%;
    display: grid;
    gap: 8px;
  }

  .row-actions .btn,
  td .btn,
  td .row-lock {
    width: 100%;
    justify-content: center;
  }

  .is-editing td {
    grid-template-columns: 1fr;
  }

  .is-editing td::before {
    margin-bottom: 2px;
  }

  .month-row td {
    display: block;
    width: 100%;
    grid-template-columns: 1fr;
    margin: 0;
    padding: 8px 0 2px;
    border: 0;
    background: transparent;
    color: #d2e2ff;
    letter-spacing: 0.05em;
  }

  .month-row td::before {
    content: none;
  }
}
