:root {
  color-scheme: dark;
  --bg: hsl(228 35% 9%);
  --bg-soft: hsl(228 28% 13%);
  --panel: hsla(0 0% 100% / 0.08);
  --panel-strong: hsla(0 0% 100% / 0.12);
  --panel-border: hsla(0 0% 100% / 0.12);
  --text: hsl(210 40% 96%);
  --muted: hsl(215 20% 72%);
  --accent: hsl(193 95% 58%);
  --accent-2: hsl(269 90% 70%);
  --accent-3: hsl(37 94% 63%);
  --success: hsl(152 71% 55%);
  --danger: hsl(0 83% 67%);
  --warning: hsl(37 96% 62%);
  --shadow: 0 24px 80px hsla(228 70% 4% / 0.45);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --max-width: min(2120px, calc(100vw - 24px));
  --transition: 180ms ease;
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: hsl(220 40% 97%);
  --bg-soft: hsl(220 35% 93%);
  --panel: hsla(0 0% 100% / 0.82);
  --panel-strong: hsla(0 0% 100% / 0.95);
  --panel-border: hsla(220 30% 35% / 0.1);
  --text: hsl(228 40% 14%);
  --muted: hsl(225 15% 42%);
  --accent: hsl(202 88% 48%);
  --accent-2: hsl(265 80% 60%);
  --accent-3: hsl(31 90% 54%);
  --success: hsl(152 55% 38%);
  --danger: hsl(0 72% 56%);
  --warning: hsl(35 82% 50%);
  --shadow: 0 22px 60px hsla(220 45% 20% / 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', sans-serif;
  background:
    radial-gradient(circle at top left, hsla(193 95% 58% / 0.18), transparent 30%),
    radial-gradient(circle at top right, hsla(269 90% 70% / 0.2), transparent 24%),
    linear-gradient(180deg, var(--bg), var(--bg-soft));
  color: var(--text);
  transition: background 220ms ease, color 220ms ease;
}

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

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: min(2120px, calc(100vw - 24px));
  max-width: none;
  margin: 0 auto;
  padding: 32px 12px 80px;
}

.ambient {
  position: fixed;
  inset: auto;
  width: 360px;
  height: 360px;
  border-radius: 999px;
  filter: blur(70px);
  pointer-events: none;
  opacity: 0.55;
}

.ambient-one {
  top: -80px;
  left: -100px;
  background: hsla(193 95% 58% / 0.18);
}

.ambient-two {
  right: -120px;
  bottom: 40px;
  background: hsla(269 90% 70% / 0.14);
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-xl);
}

.topbar,
.controls,
.table-panel,
.hero-card,
.kpi-card {
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 28px;
  margin-bottom: 24px;
}

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

h1 {
  font-size: clamp(2rem, 2vw + 1rem, 3.5rem);
  margin-top: 6px;
}

h2 {
  font-size: clamp(1.4rem, 1vw + 1rem, 2rem);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 700;
}

.subtle-text {
  color: var(--muted);
  margin-top: 8px;
}

.topbar-actions,
.footer-actions,
.action-cluster,
.hero-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.topbar-actions {
  justify-content: flex-end;
}

.row-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: center;
}

.primary-button,
.ghost-button,
.danger-button,
.chip-button,
.icon-button {
  border: 0;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition), color var(--transition), border-color var(--transition);
}

.primary-button,
.ghost-button,
.danger-button,
.chip-button {
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
}

.primary-button {
  color: hsl(220 40% 8%);
  background: linear-gradient(135deg, var(--accent), hsl(164 87% 64%));
  box-shadow: 0 16px 30px hsla(193 95% 58% / 0.3);
}

.ghost-button,
.chip-button,
.icon-button {
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--panel-border);
}

.danger-button {
  color: white;
  background: linear-gradient(135deg, hsl(0 85% 62%), hsl(11 86% 64%));
}

.primary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.chip-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.chip-button.active {
  background: linear-gradient(135deg, hsla(193 95% 58% / 0.22), hsla(269 90% 70% / 0.24));
  color: var(--text);
  border-color: hsla(193 95% 58% / 0.28);
}

.theme-toggle-icon {
  font-size: 1rem;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.hero-card {
  padding: 28px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(145deg, hsla(0 0% 100% / 0.12), hsla(0 0% 100% / 0.03)),
    radial-gradient(circle at top right, hsla(193 95% 58% / 0.28), transparent 30%),
    radial-gradient(circle at bottom left, hsla(269 90% 70% / 0.22), transparent 28%);
}

.hero-copy p:last-child {
  margin-top: 14px;
  max-width: 62ch;
  color: var(--muted);
  line-height: 1.7;
}

.soft-pill,
.platform-pill,
.status-badge,
.expiry-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.soft-pill,
.platform-pill {
  background: hsla(0 0% 100% / 0.08);
  border: 1px solid hsla(0 0% 100% / 0.08);
}

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

.kpi-card {
  padding: 22px;
  min-height: 150px;
}

.kpi-card p {
  color: var(--muted);
  font-weight: 600;
}

.kpi-card h3 {
  font-size: clamp(1.8rem, 1.4vw + 1rem, 2.8rem);
  margin: 16px 0 10px;
}

.kpi-card span {
  color: var(--muted);
}

.accent-cyan::after,
.accent-violet::after,
.accent-amber::after,
.accent-emerald::after {
  content: '';
  position: absolute;
  inset: auto -30px -48px auto;
  width: 130px;
  height: 130px;
  border-radius: 999px;
  opacity: 0.28;
}

.accent-cyan::after {
  background: var(--accent);
}

.accent-violet::after {
  background: var(--accent-2);
}

.accent-amber::after {
  background: var(--accent-3);
}

.accent-emerald::after {
  background: var(--success);
}

.controls,
.table-panel {
  padding: 24px;
  margin-bottom: 24px;
}

.control-row {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.control-row + .control-row {
  margin-top: 18px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 280px;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: var(--panel-strong);
  padding: 0 16px;
  min-height: 56px;
}

.search-box input {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.filter-row label,
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-row span,
.form-grid span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

select,
input,
textarea {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  padding: 14px 16px;
  background: var(--panel-strong);
  color: var(--text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-color: color-mix(in srgb, var(--bg-soft) 62%, white 6%);
  color: var(--text);
}

option {
  background: hsl(230 24% 18%);
  color: hsl(210 40% 96%);
}

:root[data-theme='light'] option {
  background: hsl(0 0% 100%);
  color: hsl(228 40% 14%);
}

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

select:focus,
input:focus,
textarea:focus {
  border-color: hsla(193 95% 58% / 0.6);
  box-shadow: 0 0 0 4px hsla(193 95% 58% / 0.12);
}

.auth-loading,
.login-card,
.login-hero {
  padding: 32px;
}

.auth-loading,
.login-card {
  display: grid;
  gap: 16px;
}

.auth-loading {
  min-height: 360px;
  place-items: center;
  text-align: center;
}

.login-screen {
  min-height: calc(100vh - 64px);
  display: grid;
  align-items: center;
}

.login-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 24px;
}

.login-hero {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 420px;
  background:
    linear-gradient(145deg, hsla(0 0% 100% / 0.12), hsla(0 0% 100% / 0.03)),
    radial-gradient(circle at top right, hsla(193 95% 58% / 0.28), transparent 30%),
    radial-gradient(circle at bottom left, hsla(269 90% 70% / 0.22), transparent 28%);
}

.login-card {
  align-content: center;
  min-height: 420px;
}

.login-form,
.controls label,
.form-grid label {
  display: grid;
  gap: 10px;
}

.login-form {
  margin-top: 12px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
}

.auth-message {
  margin: 0;
  border-radius: 16px;
  padding: 12px 14px;
  border: 1px solid transparent;
  font-weight: 600;
}

.auth-message.error {
  color: hsl(0 100% 88%);
  background: hsla(0 83% 67% / 0.14);
  border-color: hsla(0 83% 67% / 0.24);
}

:root[data-theme='light'] .auth-message.error {
  color: hsl(0 68% 34%);
}

.auth-badge {
  margin: 0;
  padding: 12px 16px;
  border-radius: 999px;
  color: var(--text);
  background: linear-gradient(135deg, hsla(193 95% 58% / 0.2), hsla(269 90% 70% / 0.2));
  border: 1px solid hsla(193 95% 58% / 0.24);
  font-weight: 700;
  white-space: nowrap;
}

.table-panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

.table-wrapper {
  overflow: auto;
  border-radius: 20px;
  border: 1px solid var(--panel-border);
}

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

thead {
  background: hsla(0 0% 100% / 0.04);
}

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

th {
  color: var(--muted);
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  word-break: keep-all;
  line-height: 1.1;
}

tbody tr {
  transition: background var(--transition), transform var(--transition);
}

tbody tr:hover {
  background: hsla(0 0% 100% / 0.03);
}

.record-meta {
  display: grid;
  gap: 6px;
}

.record-name {
  font-weight: 700;
}

.record-subtle,
.mono {
  color: var(--muted);
  font-size: 0.88rem;
}

.mono {
  font-variant-numeric: tabular-nums;
}

.status-paid {
  background: hsla(152 71% 55% / 0.16);
  color: hsl(152 90% 80%);
}

:root[data-theme='light'] .status-paid {
  color: hsl(152 60% 30%);
}

.status-partial {
  background: hsla(37 96% 62% / 0.16);
  color: hsl(45 100% 78%);
}

:root[data-theme='light'] .status-partial {
  color: hsl(35 80% 32%);
}

.status-unpaid,
.expired {
  background: hsla(0 83% 67% / 0.16);
  color: hsl(0 100% 84%);
}

:root[data-theme='light'] .status-unpaid,
:root[data-theme='light'] .expired {
  color: hsl(0 65% 36%);
}

.email-line {
  display: block;
  line-height: 1.45;
  white-space: nowrap;
}

.expiring {
  background: hsla(193 95% 58% / 0.16);
  color: hsl(190 100% 84%);
}

:root[data-theme='light'] .expiring {
  color: hsl(196 70% 32%);
}

.active-expiry {
  background: hsla(152 71% 55% / 0.16);
  color: hsl(152 90% 80%);
}

:root[data-theme='light'] .active-expiry {
  color: hsl(152 60% 30%);
}

.empty-state {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 12px;
  min-height: 260px;
}

.empty-orb {
  width: 94px;
  height: 94px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, var(--accent), transparent 70%), linear-gradient(135deg, hsla(193 95% 58% / 0.28), hsla(269 90% 70% / 0.35));
  filter: blur(0.2px);
}

.hidden {
  display: none !important;
}

.record-modal {
  border: 0;
  padding: 0;
  background: transparent;
}

.record-modal::backdrop {
  background: hsla(228 70% 4% / 0.68);
  backdrop-filter: blur(10px);
}

.modal-card {
  width: min(860px, calc(100vw - 24px));
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, var(--panel-strong), var(--panel));
  color: var(--text);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.modal-header,
.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.modal-header {
  margin-bottom: 20px;
}

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

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

.total-preview {
  border-radius: 18px;
  background: linear-gradient(135deg, hsla(193 95% 58% / 0.18), hsla(269 90% 70% / 0.18));
  border: 1px solid hsla(193 95% 58% / 0.16);
  padding: 16px 18px;
  font-weight: 600;
}

.modal-footer {
  margin-top: 22px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-grid;
  place-items: center;
}

.mobile-record-list {
  display: none;
  gap: 14px;
}

.mobile-record-card {
  border-radius: 22px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, hsla(0 0% 100% / 0.08), hsla(0 0% 100% / 0.04));
  padding: 16px;
  display: grid;
  gap: 14px;
}

.mobile-record-head,
.mobile-record-foot,
.mobile-platform-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.mobile-platform-row {
  flex-wrap: wrap;
}

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

.mobile-info-chip {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 16px;
  background: hsla(0 0% 100% / 0.05);
  border: 1px solid hsla(0 0% 100% / 0.08);
}

.mobile-info-chip span,
.mobile-note {
  color: var(--muted);
  font-size: 0.82rem;
}

.mobile-info-chip strong {
  font-size: 0.92rem;
  line-height: 1.45;
}

.mobile-info-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.mobile-row-actions {
  justify-content: flex-end;
}

.mobile-note {
  margin: 0;
  line-height: 1.5;
}

.mobile-note.is-empty {
  opacity: 0.8;
}

@media (max-width: 1080px) {
  .hero-grid,
  .login-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

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

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 12px, 100%);
    padding: 16px 6px 42px;
  }

  .ambient {
    width: 220px;
    height: 220px;
    filter: blur(56px);
    opacity: 0.38;
  }

  .topbar,
  .controls,
  .table-panel,
  .hero-card,
  .kpi-card,
  .modal-card,
  .login-card,
  .login-hero,
  .auth-loading {
    border-radius: 22px;
    padding: 18px;
  }

  .topbar {
    gap: 16px;
    margin-bottom: 16px;
  }

  .topbar,
  .control-row,
  .table-panel-header,
  .modal-header,
  .modal-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
  }

  .topbar-actions > * {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  h1 {
    font-size: clamp(1.9rem, 7vw, 2.7rem);
  }

  h2 {
    font-size: clamp(1.4rem, 5vw, 1.9rem);
  }

  .hero-grid,
  .control-row,
  .login-grid {
    gap: 16px;
  }

  .hero-card {
    min-height: auto;
    gap: 16px;
  }

  .hero-pill-row,
  .action-cluster {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .hero-pill-row > *,
  .action-cluster > * {
    justify-content: center;
    text-align: center;
  }

  .kpi-grid,
  .filter-row,
  .form-grid,
  .mobile-record-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-card {
    min-height: 132px;
    padding: 18px;
  }

  .kpi-card h3 {
    margin: 12px 0 8px;
    font-size: clamp(1.6rem, 6vw, 2.2rem);
  }

  .controls,
  .table-panel {
    padding: 18px;
    margin-bottom: 16px;
  }

  .search-box {
    min-width: 100%;
    min-height: 52px;
    padding: 0 14px;
    border-radius: 18px;
  }

  .filter-row {
    gap: 12px;
  }

  .desktop-table-wrapper {
    display: none;
  }

  .mobile-record-list {
    display: grid;
  }

  .table-panel-header {
    gap: 12px;
    margin-bottom: 14px;
  }

  .record-name {
    font-size: 1.06rem;
  }

  .modal-card {
    width: min(100vw - 12px, 720px);
    padding: 18px;
  }

  .modal-header {
    margin-bottom: 16px;
  }

  .form-grid {
    gap: 12px;
  }

  .form-grid label.full-span,
  .full-span {
    grid-column: 1 / -1;
  }

  .modal-footer {
    margin-top: 18px;
  }

  .footer-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .footer-actions > * {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 560px) {
  .kpi-grid,
  .filter-row,
  .form-grid,
  .mobile-record-grid,
  .hero-pill-row,
  .action-cluster,
  .footer-actions {
    grid-template-columns: 1fr 1fr;
  }

  .filter-row label:nth-child(3),
  .filter-row label:nth-child(4),
  .form-grid label:nth-child(odd):last-of-type {
    grid-column: 1 / -1;
  }

  .mobile-record-head,
  .mobile-record-foot {
    flex-direction: column;
  }

  .mobile-row-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 430px) {
  .topbar-actions,
  .hero-pill-row,
  .action-cluster,
  .kpi-grid,
  .filter-row,
  .form-grid,
  .mobile-record-grid,
  .footer-actions {
    grid-template-columns: 1fr;
  }

  .topbar-actions > *,
  .footer-actions > * {
    width: 100%;
  }

  .mobile-info-chip {
    padding: 11px;
  }
}
