@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --ink: #161A23;
  --ink-soft: #565D6D;
  --bg: #F7F7F9;
  --surface: #FFFFFF;
  --border: #E3E4EA;
  --accent: #3B4FE0;
  --accent-ink: #2C3BC0;
  --accent-soft: #EEF0FD;
  --money-in: #1B8A5A;
  --money-in-soft: #E8F5EE;
  --warn: #B5561D;
  --warn-soft: #FBEEE4;
  --danger: #C23B3B;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 26, 35, 0.06), 0 4px 16px rgba(22, 26, 35, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.num, input[type="number"], .money {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

/* --- Shell layout --- */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--ink);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.sidebar .brand {
  font-weight: 600;
  font-size: 17px;
  padding: 0 8px 24px;
  letter-spacing: -0.01em;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar nav a {
  color: rgba(255,255,255,0.68);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }

.sidebar .user-box {
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: 12px;
}

.sidebar .user-box .name { font-size: 13px; font-weight: 500; color: #fff; }
.sidebar .user-box .role { font-size: 12px; color: rgba(255,255,255,0.5); text-transform: capitalize; margin-bottom: 10px; }

.sidebar .logout-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
}
.sidebar .logout-btn:hover { background: rgba(255,255,255,0.08); }

.main {
  flex: 1;
  padding: 40px 48px;
  max-width: 880px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

.page-sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0 0 32px;
}

/* --- Cards / surfaces --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

/* --- Form elements --- */
.field { margin-bottom: 20px; position: relative; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field input, .field select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input[readonly] { background: var(--bg); color: var(--ink-soft); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.05s ease;
}
.btn:hover { background: var(--accent-ink); }
.btn:active { transform: scale(0.98); }
.btn:disabled { background: var(--border); color: var(--ink-soft); cursor: not-allowed; }
.btn.full { width: 100%; }
.btn.danger { background: var(--danger); }

/* --- Autocomplete --- */
.autocomplete { position: relative; }
.autocomplete-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow-y: auto;
  z-index: 20;
  display: none;
}
.autocomplete-results.open { display: block; }
.autocomplete-results .result {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.autocomplete-results .result .id { color: var(--ink-soft); font-size: 12px; font-family: 'IBM Plex Mono', monospace; }
.autocomplete-results .result:hover,
.autocomplete-results .result.active { background: var(--accent-soft); }
.autocomplete-results .empty { padding: 12px 14px; color: var(--ink-soft); font-size: 13px; }

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 14px;
  font-weight: 500;
  margin-top: 8px;
}
.selected-chip button {
  background: none;
  border: none;
  color: var(--accent-ink);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  opacity: 0.6;
}
.selected-chip button:hover { opacity: 1; }

.quick-add-link {
  background: none; border: none; color: var(--accent); font-size: 13px;
  font-weight: 500; cursor: pointer; padding: 6px 0; font-family: inherit;
}
.quick-add-link:hover { text-decoration: underline; }
.quick-add-box {
  border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-top: 6px; background: var(--bg);
}

/* Label row that holds the field label plus its "+ Add new" trigger, out of the
   Player -> Game -> Amount tab flow so keyboard users move field to field. */
.field-label-row {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;
}
.field-label-row label { margin-bottom: 0; }
.quick-add-inline { position: relative; }
.quick-add-inline .quick-add-link { padding: 0; }
.quick-add-inline .quick-add-box {
  position: absolute; top: calc(100% + 6px); right: 0; width: 250px;
  margin-top: 0; z-index: 15; box-shadow: var(--shadow); background: #fff;
}
.quick-add-box input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit;
}

/* --- Alerts / toasts --- */
.alert {
  border-radius: 8px;
  padding: 13px 16px;
  font-size: 14px;
  margin-bottom: 20px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.danger { background: #FBE9E9; color: var(--danger); }
.alert.success { background: var(--money-in-soft); color: var(--money-in); }

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  padding: 13px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Stats grid (reports) --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.stat-card .label { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }
.stat-card .value { font-size: 26px; font-weight: 600; font-family: 'IBM Plex Mono', monospace; letter-spacing: -0.02em; }
.stat-card .delta { font-size: 13px; margin-top: 6px; font-weight: 500; }
.stat-card .delta.up { color: var(--money-in); }
.stat-card .delta.down { color: var(--danger); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-soft); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--border);
}
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data-table tr:last-child td { border-bottom: none; }

/* --- Login page --- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
}
.login-card {
  width: 360px;
  background: #fff;
  border-radius: 14px;
  padding: 36px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card h1 { font-size: 19px; margin: 0 0 4px; }
.login-card .sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 24px; }

.error-text { color: var(--danger); font-size: 13px; margin-top: 4px; }

/* --- Transactions / profile pages --- */
.main.wide { max-width: 1120px; }

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filters-bar .field { margin-bottom: 0; min-width: 160px; position: relative; }
.filters-bar .field.grow { flex: 1; min-width: 220px; }
.filters-bar label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-soft); margin-bottom: 6px; }
.filters-bar input, .filters-bar select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
.filters-bar .btn.ghost {
  background: none; border: 1px solid var(--border); color: var(--ink-soft);
  padding: 9px 16px; font-size: 14px; font-weight: 500;
}
.filters-bar .btn.ghost:hover { background: var(--bg); }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; text-transform: capitalize;
}
.pill.deposit { background: var(--money-in-soft); color: var(--money-in); }
.pill.payout { background: var(--warn-soft); color: var(--warn); }

.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 16px; font-size: 13px; color: var(--ink-soft);
}
.pagination .btn.ghost {
  background: none; border: 1px solid var(--border); color: var(--ink);
  padding: 7px 14px; font-size: 13px;
}
.pagination .btn.ghost:disabled { color: var(--ink-soft); cursor: not-allowed; opacity: 0.5; }

table.data-table th.sortable { cursor: pointer; user-select: none; }
table.data-table th.sortable:hover { color: var(--ink); }
table.data-table td.num, table.data-table th.num { text-align: right; }
table.data-table a.row-link { color: var(--accent); text-decoration: none; font-weight: 500; }
table.data-table a.row-link:hover { text-decoration: underline; }

.edit-link, .history-link, .delete-link {
  background: none; border: none; color: var(--accent); font-size: 13px;
  font-weight: 500; cursor: pointer; padding: 0; font-family: inherit;
}
.edit-link:hover, .history-link:hover { text-decoration: underline; }
.edit-link + .history-link, .edit-link + .delete-link, .history-link + .delete-link { margin-left: 10px; }
.delete-link { color: var(--danger); }
.delete-link:hover { text-decoration: underline; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(22,26,35,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal {
  background: #fff; border-radius: 12px; padding: 28px; width: 420px; max-width: 92vw;
  max-height: 86vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h2 { font-size: 17px; margin: 0 0 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn.secondary { background: var(--border); color: var(--ink); }

.history-entry {
  border-bottom: 1px solid var(--border); padding: 10px 0; font-size: 13px;
}
.history-entry:last-child { border-bottom: none; }
.history-entry .meta { color: var(--ink-soft); margin-bottom: 4px; }
.history-entry .diff { font-family: 'IBM Plex Mono', monospace; font-size: 12px; }

/* Wraps every rendered <table> so wide tables scroll horizontally instead of
   squeezing or breaking the page layout on narrow screens. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table.data-table { min-width: 560px; }

.mobile-menu-btn { display: none; }
.sidebar-overlay { display: none; }

/* --- Mobile --- */
@media (max-width: 768px) {
  .shell { flex-direction: column; }

  .mobile-menu-btn {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 14px; left: 14px; z-index: 60;
    width: 40px; height: 40px; border: none; border-radius: 8px;
    background: var(--ink); color: #fff; font-size: 18px; cursor: pointer;
  }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 55;
    width: 240px; transform: translateX(-100%);
    transition: transform 0.2s ease; overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay {
    display: block; position: fixed; inset: 0; z-index: 50;
    background: rgba(22,26,35,0.45); opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }

  .main, .main.wide, .main.reports {
    max-width: 100%; padding: 72px 16px 32px;
  }

  .stat-grid { grid-template-columns: 1fr; }
  .tables { grid-template-columns: 1fr; }

  .login-card { width: min(360px, 90vw); padding: 28px; }

  .modal { padding: 20px; }

  .card { padding: 18px; }
}
