:root {
  color-scheme: light;
  --bg: #f4f7ff;
  --panel: #ffffff;
  --text: #16213d;
  --muted: #5c6784;
  --border: #dbe3f2;
  --brand: #2452d4;
  --brand-strong: #1b3f9f;
  --ok-bg: #e8f8ee;
  --ok-text: #1f6e3c;
  --err-bg: #ffecef;
  --err-text: #9f2f3a;
  --positive-bg: #e8f8ee;
  --positive-text: #1f6e3c;
  --negative-bg: #ffecef;
  --negative-text: #9f2f3a;
  --paid-bg: #def4e8;
  --paid-text: #1f5f47;
  --tracker-tint: #f2f7ff;
  --tracker-border: #cfddfb;
  --tracker-shadow: 0 16px 38px rgba(27, 63, 159, 0.09);
}

* {
  box-sizing: border-box;
}

[x-cloak] {
  display: none !important;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top right, #e7efff 0, var(--bg) 42%);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(7px);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.2px;
  flex: 0 0 auto;
}

.header-child-form {
  flex: 1 1 280px;
  max-width: 320px;
}

.header-child-select {
  min-height: 38px;
  padding-top: 7px;
  padding-bottom: 7px;
}

.menu-button {
  display: none;
  border: none;
  background: #eaf0ff;
  color: var(--brand);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.nav-link {
  border: none;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
}

.nav-link:hover,
.nav-link.active {
  color: var(--brand);
  background: #eaf0ff;
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  min-height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
}

.nav-meta {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.nav-button {
  cursor: pointer;
}

.nav-group {
  position: relative;
}

.nav-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 160px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 14px 34px rgba(17, 32, 72, 0.12);
  padding: 6px;
  display: grid;
  gap: 4px;
}

.dropdown-link {
  color: var(--text);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
}

.dropdown-link:hover {
  background: #edf2ff;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 28px;
  display: grid;
  gap: 16px;
}

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

.auth-card {
  width: min(460px, 100%);
}

.auth-card h1 {
  margin: 0 0 8px;
}

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

.dashboard-content {
  display: grid;
  gap: 16px;
}

.page-header h1 {
  margin: 0;
}

.page-header p {
  margin: 8px 0 0;
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.card h2 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1.08rem;
}

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

.alerts {
  display: grid;
  gap: 8px;
}

.alert {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.alert.success {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.alert.error {
  background: var(--err-bg);
  color: var(--err-text);
}

.dashboard-grid,
.config-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.top-focus-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

.top-focus-grid.has-actions {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr);
}

.actions-column {
  display: grid;
  gap: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
}

.tracker-spotlight {
  padding: 18px;
  border-color: var(--tracker-border);
  background: linear-gradient(180deg, #ffffff 0%, var(--tracker-tint) 100%);
  box-shadow: var(--tracker-shadow);
}

.tracker-spotlight > h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.tracker-spotlight > h2::after {
  content: "Live";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: #184f96;
  background: #dceaff;
  border: 1px solid #bdd6ff;
}

.week-form {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
}

.stacked-form {
  display: grid;
  gap: 8px;
}

.inline-role-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.inline-role-form .button {
  min-height: 40px;
  padding: 8px 10px;
}

label {
  font-size: 0.9rem;
  color: var(--muted);
}

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

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

button,
.button {
  display: inline-block;
  border: none;
  border-radius: 8px;
  text-decoration: none;
  min-height: 44px;
  padding: 10px 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}

button:hover,
.button:hover {
  background: var(--brand-strong);
}

button:disabled,
.button:disabled {
  background: #b9c6ea;
  cursor: not-allowed;
}

.button.ghost {
  background: #edf2ff;
  color: var(--brand);
}

.menu-trigger {
  min-height: 38px;
  padding: 7px 12px;
}

.inline-menu {
  position: relative;
}

.menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 180px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 14px 34px rgba(17, 32, 72, 0.12);
  padding: 6px;
  display: grid;
  gap: 4px;
  z-index: 12;
}

.menu-item-button {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  min-height: 38px;
}

.menu-item-button:hover {
  background: #edf2ff;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.token-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eaf0ff;
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 700;
}

.token-pill.positive {
  background: var(--positive-bg);
  color: var(--positive-text);
}

.token-pill.negative {
  background: var(--negative-bg);
  color: var(--negative-text);
}

.token-pill.preview {
  background: #ffe6dc;
  color: #b65b63;
}

.token-pill.paid {
  background: var(--paid-bg);
  color: var(--paid-text);
}

.segmented-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segment {
  background: #edf2ff;
  color: var(--brand);
  border: 1px solid #d5e1ff;
}

.segment.active {
  border-color: transparent;
}

.segment.active.positive {
  background: var(--positive-bg);
  color: var(--positive-text);
}

.segment.active.negative {
  background: var(--negative-bg);
  color: var(--negative-text);
}

.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid #7c89aa;
  border-bottom: 2px solid #7c89aa;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.rule-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.custom-token-control {
  display: grid;
  gap: 8px;
}

.amount-stepper {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  align-items: center;
}

.step-btn {
  padding: 0;
  height: 42px;
  font-size: 1.2rem;
  line-height: 1;
}

.step-value {
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 42px;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.circle-preview {
  display: grid;
  gap: 6px;
}

.token-circles {
  --token-size: 22px;
  --token-gap: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: var(--token-gap);
  min-height: var(--token-size);
  justify-content: center;
  width: min(100%, calc(16 * var(--token-size) + 15 * var(--token-gap)));
  margin-inline: auto;
  border: 1px dashed #c8d8fb;
  border-radius: 14px;
  background: linear-gradient(180deg, #f6f9ff 0%, #f0f6ff 100%);
  padding: 12px;
}

.token-circle {
  width: var(--token-size);
  height: var(--token-size);
  border-radius: 999px;
  background: #d6e2ff;
  border: 1px solid #a6beff;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

.token-circles.large .token-circle {
  --token-size: 26px;
  --token-gap: 12px;
}

.token-circle.positive {
  background: #c8efda;
  border-color: #7dc8a0;
}

.token-circle.negative {
  background: #ffd9de;
  border-color: #ef9eaa;
}

.token-circle.preview {
  background: #ffd8cb;
  border-color: #efb1a0;
}

.token-circle.paid {
  background: #d8f1e4;
  border-color: #93cdb3;
}

.token-circle.preview.positive {
  background: #ddf5e7;
  border-color: #addfc3;
}

.token-circle.preview.negative {
  background: #ffe3e6;
  border-color: #f6b9c0;
}

.money-sub {
  color: var(--muted);
  font-size: 0.83rem;
}

.value-stack {
  display: grid;
  gap: 2px;
}

.balance-grid {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 2px 2px 6px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  justify-content: center;
}

.balance-card {
  border: 1px solid #d3def7;
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  box-shadow: 0 10px 24px rgba(26, 47, 99, 0.06);
  flex: 0 0 min(340px, calc(100vw - 44px));
  scroll-snap-align: start;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.balance-card.selected {
  border-color: #7ea7ff;
  box-shadow: 0 14px 28px rgba(36, 82, 212, 0.2);
  transform: translateY(-1px);
}

.balance-card h3 {
  margin: 0 0 8px;
  font-size: 1.02rem;
  letter-spacing: 0.01em;
}

.balance-card.spotlight h3 {
  font-size: 1.08rem;
}

.balance-meta {
  margin: 0 0 9px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.balance-card .hint {
  line-height: 1.35;
}

.balance-card .hint + .hint {
  margin-top: 3px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.activity-stack {
  display: grid;
  gap: 16px;
}

.overview-stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 14px;
}

.overview-stat {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcff;
  padding: 10px 12px;
}

.overview-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.overview-value {
  margin: 6px 0 2px;
  font-size: 1.08rem;
  font-weight: 700;
}

.overview-value.positive {
  color: var(--positive-text);
}

.overview-subhead {
  margin: 0 0 10px;
  font-size: 0.96rem;
}

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

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

.log-table td:nth-child(5),
.log-table td:nth-child(6) {
  font-variant-numeric: tabular-nums;
}

.activity-table td:nth-child(4),
.payouts-table td:nth-child(3) {
  white-space: normal;
  min-width: 180px;
}

.activity-table td:nth-child(1),
.activity-table td:nth-child(5),
.activity-table td:nth-child(6),
.payouts-table td:nth-child(1),
.payouts-table td:nth-child(4),
.payouts-table td:nth-child(5) {
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18, 30, 64, 0.48);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
}

.modal-card {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
}

.close-btn {
  min-height: 38px;
  padding: 7px 11px;
}

@media (max-width: 820px) {
  .topbar-inner {
    padding: 10px 14px;
    flex-wrap: wrap;
  }

  .brand {
    font-size: 0.98rem;
  }

  .menu-button {
    display: inline-flex;
    order: 2;
    margin-left: auto;
  }

  .nav {
    order: 4;
    width: 100%;
    display: none;
    flex-direction: column;
    align-items: flex-start;
    padding-bottom: 6px;
    gap: 4px;
    margin-left: 0;
  }

  .nav.show {
    display: flex;
  }

  .nav-dropdown {
    position: static;
    box-shadow: none;
    width: 100%;
    margin-top: 6px;
  }

  .nav-meta {
    padding: 6px 10px;
    white-space: normal;
  }

  .menu-dropdown {
    right: auto;
    left: 0;
  }

  .container {
    padding: 14px;
  }

  .header-child-form {
    order: 3;
    width: 100%;
    max-width: none;
  }

  .header-child-select {
    min-height: 40px;
  }

  .top-focus-grid {
    grid-template-columns: 1fr;
  }

  .top-focus-grid.has-actions,
  .top-focus-grid.no-actions {
    grid-template-columns: 1fr;
  }

  .tracker-spotlight {
    padding: 14px;
  }

  .balance-card {
    padding: 12px;
  }

  .balance-card h3 {
    font-size: 0.98rem;
  }

  .balance-meta {
    margin-bottom: 10px;
  }

  .token-circles.large {
    --token-size: 24px;
    --token-gap: 10px;
  }

  .token-circles {
    width: min(100%, calc(16 * var(--token-size) + 15 * var(--token-gap)));
  }

  .balance-grid {
    display: grid;
    grid-template-columns: 1fr;
    overflow: visible;
    padding: 0;
    justify-content: stretch;
    gap: 10px;
  }

  .balance-card {
    width: 100%;
    flex: initial;
  }

  .week-form .button,
  .week-form button {
    width: 100%;
    text-align: center;
  }

  .week-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "prev next"
      "date date"
      "go go";
    gap: 8px;
    overflow: visible;
  }

  .week-prev {
    grid-area: prev;
  }

  .week-next {
    grid-area: next;
  }

  .week-date {
    grid-area: date;
  }

  .week-go {
    grid-area: go;
  }

  .modal-card {
    width: min(540px, 100%);
  }
}

@media (max-width: 560px) {
  .container {
    padding: 12px;
    gap: 12px;
  }

  .dashboard-content {
    gap: 12px;
  }

  .card {
    padding: 13px;
  }

  .auth-shell {
    min-height: auto;
  }

  .page-header p {
    font-size: 0.92rem;
  }

  .week-form {
    gap: 6px;
  }

  .week-form input[type="date"] {
    min-width: 0;
  }

  .amount-stepper {
    grid-template-columns: 44px 1fr 44px;
  }

  .step-btn {
    height: 44px;
  }

  .token-circles.large {
    --token-size: 22px;
    --token-gap: 9px;
  }

  .balance-grid {
    gap: 8px;
  }

  .balance-card {
    padding: 11px;
  }

  .activity-table td:nth-child(4),
  .payouts-table td:nth-child(3) {
    min-width: 220px;
  }

  .modal-backdrop {
    padding: 0;
    place-items: end stretch;
  }

  .modal-card {
    width: 100%;
    max-height: 88vh;
    border-radius: 16px 16px 0 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .card-head,
  .modal-head {
    align-items: flex-start;
  }

  .menu-trigger,
  .close-btn {
    min-height: 36px;
    padding: 6px 10px;
  }
}

@media (max-width: 700px) {
  .responsive-table {
    min-width: 0;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
    background: #fff;
  }

  .responsive-table tr:last-child {
    margin-bottom: 6px;
  }

  .responsive-table td {
    border-bottom: none;
    padding: 6px 0;
    white-space: normal;
    display: grid;
    grid-template-columns: minmax(110px, 0.95fr) 1.4fr;
    gap: 10px;
    align-items: start;
    text-align: right;
  }

  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
  }

  .responsive-table td[data-label="Type"] .token-pill {
    justify-self: end;
  }

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

  .inline-role-form .button {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
    margin-bottom: 6px;
  }
}
