:root {
  color-scheme: light;
  --bg: #eef6ff;
  --card: rgba(255, 255, 255, 0.76);
  --card-strong: rgba(255, 255, 255, 0.92);
  --text: #132238;
  --muted: #687386;
  --line: rgba(116, 139, 171, 0.24);
  --primary: #2563eb;
  --primary-dark: #1745aa;
  --green: #14a46c;
  --red: #e14b4b;
  --shadow: 0 24px 70px rgba(53, 96, 143, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  overflow-x: hidden;
}

body {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(91, 192, 255, 0.34), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(131, 232, 187, 0.42), transparent 32rem),
    linear-gradient(135deg, #f7fbff 0%, var(--bg) 100%);
}

body.menu-open {
  overflow: hidden;
}

.pull-refresh {
  --pull-progress: 0;
  --pull-offset: 0px;
  position: fixed;
  top: -48px;
  left: 50%;
  z-index: 60;
  min-width: 220px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 999px;
  padding: 10px 16px;
  overflow: hidden;
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 34px rgba(19, 34, 56, 0.16);
  font-size: 0.86rem;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transform: translate3d(-50%, var(--pull-offset), 0);
  transition: opacity 0.16s ease, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  pointer-events: none;
  will-change: transform, opacity;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.pull-refresh::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.2), rgba(75, 163, 255, 0.28));
  opacity: calc(0.18 + (var(--pull-progress) * 0.55));
  transform: scaleX(var(--pull-progress));
  transform-origin: left center;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.pull-refresh.is-visible {
  opacity: 1;
  transition-duration: 0.12s, 0s;
}

.pull-refresh.is-ready {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #4ba3ff);
}

button,
input,
select {
  font: inherit;
  min-width: 0;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #4ba3ff);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.25);
  font-weight: 800;
}

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

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

.glass-card {
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
}

.hero {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 18px;
  margin-bottom: 14px;
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand-icon {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  box-shadow: 0 10px 26px rgba(37, 99, 235, 0.22);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 6vw, 2.2rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.24rem;
}

.auth-card,
.panel {
  padding: 18px;
  margin-bottom: 14px;
}

.view-page[hidden] {
  display: none;
}

.stack-form [hidden] {
  display: none;
}

.page-heading {
  padding: 18px;
  margin-bottom: 14px;
}

.page-heading p:last-child {
  margin-bottom: 0;
  color: var(--muted);
}

.hint-text {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

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

.metric-card {
  min-width: 0;
  padding: 16px;
}

.metric-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.83rem;
}

.metric-card strong {
  display: block;
  font-size: 1.32rem;
  overflow-wrap: anywhere;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.stack-form + .players-list,
.stack-form + .ledger-list,
.stack-form + .services-list,
.stack-form + .directory-list,
.stack-form + .hint-text,
.stack-form + .correction-columns {
  margin-top: 18px;
}

.compact-form {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  align-items: end;
}

label {
  position: relative;
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

input,
select {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 48px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0 14px;
  color: var(--text);
  background: var(--card-strong);
  font-size: 16px;
  outline: none;
}

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

.date-field {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
  min-width: 0;
  height: 48px;
}

.date-picker-button {
  min-width: 48px;
  width: 48px;
  height: 48px;
  min-height: 48px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 16px;
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: none;
  font-size: 1rem;
}

.date-picker-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.native-date-input {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 2;
  width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: auto;
}

.player-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  z-index: 25;
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 18px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(19, 34, 56, 0.16);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.player-suggestions[hidden] {
  display: none;
}

.player-suggestions button {
  display: grid;
  gap: 3px;
  min-height: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(248, 252, 255, 0.9);
  box-shadow: none;
  text-align: left;
}

.player-suggestions span,
.player-suggestion-empty {
  color: var(--muted);
  font-size: 0.84rem;
}

.player-suggestion-empty {
  padding: 10px 12px;
}

.section-head {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin-bottom: 12px;
}

.finance-head {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.statement-head {
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
}

.statement-head h2 {
  margin: 0;
  line-height: 48px;
}

.section-head .secondary-button {
  align-self: end;
}

.statement-icon-button {
  align-self: center;
  justify-self: end;
}

.secondary-button {
  min-height: 44px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.12);
}

.statement-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.statement-title {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.statement-title h3,
.statement-title p {
  margin: 0;
}

.statement-title h3 {
  font-size: 1.18rem;
}

.period-picker {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 22px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 18px 42px rgba(19, 34, 56, 0.12);
}

.period-picker[hidden] {
  display: none;
}

.period-picker-head,
.period-calendar-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.period-picker h3 {
  margin: 0;
  font-size: 1rem;
}

.period-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 10px;
}

.period-calendar {
  display: grid;
  gap: 8px;
}

.period-calendar-head button {
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 14px;
}

.calendar-weekdays,
.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-weekdays span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-align: center;
}

.calendar-days button {
  position: relative;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0;
  color: var(--text);
  background: rgba(248, 252, 255, 0.86);
  box-shadow: none;
}

.calendar-days button.has-data::after {
  content: '';
  position: absolute;
  right: 7px;
  bottom: 6px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--green);
}

.calendar-days button.is-in-range {
  border-color: rgba(37, 99, 235, 0.2);
  background: rgba(37, 99, 235, 0.1);
}

.calendar-days button.is-selected {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), #4ba3ff);
}

.cash-statement-summary {
  margin-bottom: 12px;
}

.search {
  min-height: 44px;
}

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

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card-strong);
}

.segmented input {
  width: auto;
  min-height: auto;
  margin-right: 8px;
}

.players-list,
.ledger-list,
.services-list {
  display: grid;
  gap: 10px;
}

.correction-columns {
  display: grid;
  gap: 22px;
}

.correction-columns h3 {
  margin: 0 0 14px;
}

.correction-columns section + section {
  padding-top: 4px;
}

.correction-item {
  display: grid;
  gap: 12px;
}

.danger-button {
  justify-self: stretch;
  min-height: 42px;
  border: 1px solid rgba(225, 75, 75, 0.24);
  color: #9f2525;
  background: rgba(255, 245, 245, 0.9);
  box-shadow: none;
}

.pdf-frame {
  display: block;
  width: 100%;
  min-height: min(78vh, 900px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
}

.player-card,
.ledger-item,
.service-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.74);
}

.player-main,
.ledger-main {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  min-width: 0;
}

.player-name,
.ledger-title {
  margin: 0 0 4px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.player-phone,
.ledger-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.balance {
  flex: 0 1 auto;
  white-space: nowrap;
  font-weight: 950;
}

.balance.negative,
.amount.writeoff {
  color: var(--red);
}

.amount.topup {
  color: var(--green);
}

.amount.income {
  color: var(--green);
}

.amount.expense {
  color: var(--red);
}

.cash-card {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  margin-bottom: 14px;
  background: rgba(255, 255, 255, 0.74);
}

.cash-card span,
.cash-card small {
  color: var(--muted);
}

.cash-card strong {
  font-size: 1.5rem;
}

.finance-form {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  align-items: end;
}

.finance-form button {
  min-width: min(100%, 180px);
}

.service-update-form,
.directory-edit-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  align-items: end;
  gap: 12px;
}

.service-card {
  display: grid;
  gap: 10px;
}

.service-card-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  min-width: 0;
}

.directory-action {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.08);
  overflow: hidden;
}

.directory-action summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 12px 14px;
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.directory-action summary::-webkit-details-marker {
  display: none;
}

.directory-action summary::after {
  content: '+';
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary-dark);
  font-size: 1.25rem;
  line-height: 1;
}

.directory-action[open] summary::after {
  content: '−';
}

.directory-action form {
  padding: 0 14px 14px;
}

.directory-edit {
  min-width: 0;
}

.directory-edit summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.directory-edit summary::-webkit-details-marker {
  display: none;
}

.directory-card-info {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.directory-card-info > span {
  display: block;
  min-width: 0;
}

.directory-card-side {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.directory-card .amount,
.directory-card .balance {
  white-space: nowrap;
}

.edit-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary-dark);
}

.edit-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.directory-edit form {
  margin-top: 12px;
}

.directory-grid {
  display: grid;
  gap: 10px;
}

.directory-grid button {
  display: grid;
  gap: 5px;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.1);
  text-align: left;
}

.directory-grid strong {
  font-size: 1rem;
}

.directory-grid span {
  color: var(--muted);
  font-size: 0.88rem;
}

.directory-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.directory-action + .directory-list,
.directory-action + .services-list {
  margin-top: 14px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.quick-actions.one-action {
  grid-template-columns: minmax(0, 1fr);
}

.quick-actions button {
  min-width: 0;
  min-height: 40px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: none;
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.menu-button,
.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  min-width: 48px;
  min-height: 48px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: none;
}

.menu-button {
  gap: 5px;
  padding: 10px;
}

.menu-button span {
  display: block;
  width: 22px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.icon-button {
  border-radius: 16px;
  font-size: 1.5rem;
  line-height: 1;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(19, 34, 56, 0.24);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.app-menu {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 40;
  width: min(calc(100vw - 24px), 360px);
  max-width: calc(100vw - 24px);
  padding: 18px;
  transform: translateX(calc(100% + 24px));
  transition: transform 0.22s ease;
}

.app-menu.is-open {
  transform: translateX(0);
}

.menu-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  margin-bottom: 14px;
}

.menu-list {
  display: grid;
  gap: 10px;
}

.menu-list button {
  min-width: 0;
  justify-content: flex-start;
  min-height: 50px;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: none;
  text-align: left;
  overflow-wrap: anywhere;
}

.menu-list button[aria-current="page"] {
  border-color: rgba(37, 99, 235, 0.34);
  color: var(--primary-dark);
  background: rgba(225, 240, 255, 0.86);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 18px;
  left: 16px;
  z-index: 50;
  max-width: 560px;
  margin: 0 auto;
  border-radius: 18px;
  padding: 14px 16px;
  color: #fff;
  background: rgba(19, 34, 56, 0.94);
  box-shadow: 0 18px 42px rgba(19, 34, 56, 0.28);
}

.empty {
  margin: 0;
  color: var(--muted);
}

@media (min-width: 680px) {
  .app-shell {
    padding-top: 24px;
  }

  .section-head:not(.finance-head, .statement-head) {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .correction-columns {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

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

@media print {
  body {
    background: #fff;
  }

  .hero,
  .menu-button,
  .app-menu,
  .menu-overlay,
  .pull-refresh,
  .toast,
  .statement-actions,
  .period-picker,
  .view-page:not([data-view="cash-ledger"]) {
    display: none !important;
  }

  .app-shell,
  .panel,
  .glass-card {
    max-width: none;
    padding: 0;
    border: 0;
    background: #fff;
    box-shadow: none;
  }

  #appView,
  #cashLedgerSection {
    display: block !important;
  }

  .ledger-item,
  .metric-card,
  .statement-details {
    break-inside: avoid;
    background: #fff;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  .hero,
  .auth-card,
  .panel {
    border-radius: 22px;
    padding: 14px;
  }

  .brand-icon {
    width: 48px;
    height: 48px;
    border-radius: 15px;
  }

  .eyebrow {
    font-size: 0.66rem;
    letter-spacing: 0.05em;
  }

  .summary-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

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

  .metric-card {
    padding: 12px;
  }

  .metric-card strong {
    font-size: 1.08rem;
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }

  .ledger-main,
  .player-main {
    flex-direction: column;
  }

  .balance,
  .amount {
    white-space: normal;
  }
}
