:root {
  --primary: #00008b;
  --primary-light: #1a1aa8;
  --bg: #f4f6fb;
  --card: #fff;
  --danger: #c0392b;
  --success: #1e7e34;
  --text: #1a1a2e;
  --muted: #6c757d;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 139, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 380px;
}

.login-card h1 { margin: 0 0 0.25rem; color: var(--primary); }
.subtitle { color: var(--muted); margin: 0 0 1.5rem; }
.login-card label { display: block; font-size: 0.85rem; margin-top: 0.75rem; }
.login-card input[type=text],
.login-card input[type=password],
.login-card input[type=date] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-top: 0.25rem;
}
.checkbox { display: flex; align-items: center; gap: 0.5rem; }
.btn-primary {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.75rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}
.btn-primary:hover { background: var(--primary-light); }
.alert-error {
  background: #fde8e8;
  color: var(--danger);
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.footer-link { text-align: center; margin-top: 1rem; font-size: 0.9rem; }
.footer-link a { color: var(--primary); }

#app { min-height: 100vh; display: flex; flex-direction: column; }
.top-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.625rem;
  padding: 0.45rem 0.75rem;
  background: var(--primary);
  color: #fff;
  position: relative;
  z-index: 110;
}
.brand {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}
.brand img {
  display: block;
  width: 28px;
  height: 28px;
}
.available-limit {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  min-width: 0;
  margin-left: auto;
  line-height: 1.05;
}
.available-limit strong {
  font-size: 0.95rem;
  white-space: nowrap;
}
.available-limit small {
  margin-top: 0.15rem;
  color: rgba(255,255,255,0.75);
  font-size: 0.63rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.available-limit.is-low strong { color: #ffe08a; }
.available-limit.is-empty strong { color: #ffb4ab; }
.user-menu { position: relative; }
.user-menu-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: 0;
  color: #fff;
  padding: 0.1rem;
  border-radius: 999px;
  cursor: pointer;
}
.user-menu-toggle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.user-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
}
.user-name {
  max-width: 110px;
  overflow: hidden;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu-arrow { font-size: 0.7rem; }
.user-menu-panel {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  width: max-content;
  min-width: 180px;
  padding: 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  color: var(--text);
}
.user-menu-label {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--muted);
  font-size: 0.7rem;
}
.user-menu-panel strong {
  display: block;
  max-width: 220px;
  overflow: hidden;
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-logout {
  width: 100%;
  margin-top: 0.65rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid #d7d9e0;
  border-radius: 7px;
  background: #fff;
  color: var(--danger);
  cursor: pointer;
  text-align: left;
}
.btn-logout:hover { background: #fff5f5; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.main { flex: 1; padding: 1rem; padding-bottom: 4rem; }
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid #e0e0e0;
  z-index: 100;
}
.bottom-nav button,
.bottom-nav .legacy-link {
  flex: 1;
  padding: 0.75rem 0.25rem;
  border: none;
  background: none;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
}
.bottom-nav button.active { color: var(--primary); font-weight: 600; }
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
.game-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 2px solid transparent;
}
.game-card:not(.closed):hover { border-color: var(--primary); }
.game-card.closed { opacity: 0.65; cursor: default; }
.game-card h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.game-card .meta { margin: 0; font-size: 0.8rem; color: var(--muted); }
.game-card .amt { font-weight: 700; color: var(--primary); }
.badge {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  background: #eee;
  border-radius: 4px;
}
.panel { background: var(--card); padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.balance-panel {
  max-width: 820px;
  margin: 0 auto;
}
.balance-filter {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(90px, 0.35fr);
  align-items: end;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.balance-filter label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.balance-filter input {
  width: 100%;
  padding: 0.65rem;
  border: 1px solid #ccd3dd;
  border-radius: 8px;
  background: #fff;
}
.balance-filter .btn-primary { margin: 0; }
.account-copy {
  overflow: hidden;
  color: #20344c;
  border-radius: 12px;
  background: #fff;
}
.account-heading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.75rem 0.5rem 1.4rem;
  text-align: center;
}
.account-heading time,
.account-heading span { font-size: 1rem; }
.account-heading h2 {
  margin: 0.15rem 0 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}
.account-heading strong { font-size: 0.95rem; }
.balance-table-wrap { overflow-x: auto; }
.balance-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.95rem;
  font-weight: 700;
}
.balance-table th,
.balance-table td {
  padding: 0.7rem 0.65rem;
  border: 1px solid #cbd3dd;
  text-align: right;
}
.balance-table th {
  color: #fff;
  background: #6f7987;
  font-size: 0.85rem;
}
.balance-table th:first-child,
.balance-table td:first-child,
.balance-table th:nth-child(2),
.balance-table td:nth-child(2) { text-align: left; }
.balance-table th:first-child { width: 14%; }
.balance-table th:nth-child(2) { width: 30%; }
.balance-table tbody tr:nth-child(odd) { background: #f4f6f8; }
.balance-table tfoot {
  color: #fff;
  background: #6f7987;
}
.balance-table tfoot td { border-color: #4e5968; }
.balance-table .empty {
  padding: 1.5rem;
  text-align: center;
  font-weight: 400;
}
.balance-summary {
  display: grid;
  grid-template-columns: 28% 22% 28% 22%;
  margin-top: 1rem;
  border-top: 1px solid #cbd3dd;
  border-left: 1px solid #cbd3dd;
  font-size: 0.95rem;
  font-weight: 700;
}
.balance-summary > div {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0.65rem 0.75rem;
  border-right: 1px solid #cbd3dd;
  border-bottom: 1px solid #cbd3dd;
}
.summary-label { background: #e7edf4; }
.summary-value {
  justify-content: flex-end;
  color: #203044;
  background: #fff;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.summary-highlight,
.summary-net-label,
.summary-net-value { background: #fff3c4; }
.summary-net-value { font-size: 1.05rem; }
.summary-value.is-loss { color: #d32626; }
.summary-value.is-profit { color: var(--success); }
.summary-spacer { background: #fff; }
.game-tabs {
  display: flex;
  margin-top: 1rem;
  border-bottom: 1px solid #ddd;
}
.game-tabs button {
  flex: 1;
  padding: 0.75rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.game-tabs button.active {
  border-bottom-color: var(--primary);
  color: var(--primary);
}
.game-tab-content { padding: 1rem 0; }
.game-tab-content h3 { margin-top: 0; }
.jantri-panel h2 { margin-top: 0; }
.jantri-filters {
  display: grid;
  grid-template-columns: minmax(150px, 2fr) minmax(140px, 1fr) minmax(90px, 0.5fr);
  align-items: end;
  gap: 0.75rem;
}
.jantri-filters label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.jantri-filters select,
.jantri-filters input,
.jantri-cut input {
  width: 100%;
  padding: 0.65rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
}
.jantri-filters .btn-primary { margin: 0; }
.jantri-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0 0.75rem;
}
.jantri-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.jantri-cut {
  display: flex;
  gap: 0.4rem;
}
.jantri-cut button {
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  background: var(--primary);
  color: #fff;
  white-space: nowrap;
  cursor: pointer;
}
.jantri-summary {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.jantri-summary strong { color: var(--primary); }
.jantri-hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.jantri-grid {
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  width: 100%;
  margin-top: 1rem;
  gap: 2px;
}
.jantri-grid-gap {
  grid-column: 1 / -1;
  height: 8px;
  background: var(--bg);
  border-top: 1px solid #e1e4eb;
  border-bottom: 1px solid #e1e4eb;
}
.jantri-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.25rem;
  min-width: 0;
  min-height: 42px;
  padding: 0.2rem 0.05rem 0.3rem;
  border: none;
  border-right: 1px solid #b1441b;
  border-bottom: 1px solid #2f33b1;
  border-radius: 6px;
  background: #fff;
  text-align: center;
}
.jantri-cell span {
  display: block;
  color: #000;
  font-size: 0.6rem;
  font-weight: 600;
  line-height: 1;
}
.jantri-cell strong {
  display: block;
  overflow: hidden;
  margin-top: 0.2rem;
  min-height: 0.7rem;
  max-width: 100%;
  color: #126b29;
  font-family: Arial, sans-serif;
  font-size: clamp(0.62rem, 2.5vw, 0.82rem);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1.1;
}
.jantri-cell.has-value { background: #f3fff6; }
.jantri-row-total {
  background: #eef0ff;
  border-left: 2px solid var(--primary);
}
.jantri-row-total span,
.jantri-row-total strong {
  color: var(--primary);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 1rem; }
.data-table th, .data-table td { border: 1px solid #eee; padding: 0.4rem; text-align: left; }
.statement-panel {
  max-width: 900px;
  margin: 0 auto;
}
.statement-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.statement-heading h2 { margin: 0; }
.statement-heading p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}
.statement-refresh {
  width: auto;
  min-width: 120px;
  margin: 0;
  padding-inline: 1rem;
}
.statement-refresh:disabled {
  opacity: 0.65;
  cursor: wait;
}
.statement-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.statement-summary > div {
  display: grid;
  gap: 0.2rem;
  padding: 0.75rem;
  border: 1px solid #e2e6ee;
  border-radius: 8px;
  background: #f8f9fc;
}
.statement-summary span {
  color: var(--muted);
  font-size: 0.75rem;
}
.statement-summary strong {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.statement-table-wrap { overflow-x: auto; }
.statement-table {
  min-width: 600px;
  font-variant-numeric: tabular-nums;
}
.statement-table th {
  color: #fff;
  background: #6f7987;
  white-space: nowrap;
}
.statement-table th,
.statement-table td { padding: 0.65rem; }
.statement-table tbody tr:nth-child(even) { background: #f8f9fc; }
.statement-table .amount {
  text-align: right;
  white-space: nowrap;
}
.statement-debit { color: var(--danger); }
.statement-credit { color: var(--success); }
.empty { text-align: center; color: var(--muted); padding: 2rem; }

@media (max-width: 600px) {
  .user-name { display: none; }
  .balance-panel { padding: 0.5rem; }
  .account-heading { padding-bottom: 1rem; }
  .account-heading h2 { font-size: 1rem; }
  .account-heading time,
  .account-heading span,
  .account-heading strong { font-size: 0.78rem; }
  .balance-table { font-size: 0.72rem; }
  .balance-table th,
  .balance-table td { padding: 0.55rem 0.3rem; }
  .balance-table th { font-size: 0.65rem; }
  .balance-summary { font-size: 0.7rem; }
  .balance-summary > div {
    min-height: 38px;
    padding: 0.45rem 0.4rem;
  }
  .jantri-panel { padding: 0.5rem; }
  .jantri-filters { grid-template-columns: 1fr 1fr; }
  .jantri-filters .btn-primary { grid-column: 1 / -1; }
  .jantri-tools { align-items: stretch; flex-direction: column; }
  .jantri-cut { width: 100%; }
  .jantri-cut input { min-width: 0; }
  .statement-panel { padding: 0.75rem; }
  .statement-heading { align-items: flex-start; }
  .statement-heading h2 { font-size: 1.1rem; }
  .statement-refresh {
    min-width: auto;
    padding: 0.55rem 0.75rem;
    font-size: 0.85rem;
  }
  .statement-summary {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }
  .statement-summary > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
