/* AccessHub v2 — Access Card Distribution & Funds Manager */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e6e8ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #16a34a;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fff7ed;
  --danger: #dc2626;
  --sky: #0284c7;
  --sky-soft: #e0f2fe;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
aside { background: #0f172a; color: #cbd5e1; padding: 24px 16px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; color: #fff; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid; place-items: center; color: #fff; font-size: 16px; flex-shrink: 0;
}
nav .nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: 8px; color: #cbd5e1;
  font-size: 14px; cursor: pointer; user-select: none;
  background: none; border: none; text-align: left; font-family: inherit;
}
nav .nav-item:hover { background: #1e293b; color: #fff; }
nav .nav-item.active { background: #1e293b; color: #fff; }
nav .nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: #475569; }
nav .nav-item.active .dot { background: #6366f1; }
.sidebar-footer { margin-top: 32px; padding: 12px 8px; font-size: 12px; color: #64748b; line-height: 1.6; border-top: 1px solid #1e293b; }

main { padding: 24px 32px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow-sm); }
.user-chip .avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #6366f1, #ec4899); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.user-chip .name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-chip .role { font-size: 11px; color: var(--muted); line-height: 1.2; }
.breadcrumbs { margin-bottom: 14px; font-size: 13px; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--primary); }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.stat .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; flex-wrap: wrap; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 8px; letter-spacing: -0.02em; }
.stat .delta { font-size: 12px; margin-top: 4px; color: var(--muted); }
.stat .delta.up { color: var(--success); }
.stat .delta.down { color: var(--danger); }
.stat .icon {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-size: 16px; margin-bottom: 10px;
}
.stat.green .icon { background: var(--success-soft); color: var(--success); }
.stat.amber .icon { background: var(--warning-soft); color: var(--warning); }
.stat.red .icon { background: #fee2e2; color: var(--danger); }

/* Card type strip */
.type-strip {
  display: flex; gap: 20px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 20px; box-shadow: var(--shadow-sm); margin-bottom: 16px; font-size: 13px; color: var(--muted);
}
.type-strip .type-item { display: flex; align-items: center; gap: 7px; }
.type-strip .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.type-strip .dot.member { background: var(--primary); }
.type-strip .dot.nonmember { background: var(--sky); }
.type-strip .dot.complimentary { background: var(--warning); }
.type-strip .money { color: var(--text); }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.search {
  display: flex; align-items: center; gap: 8px; background: #f1f5f9; border: 1px solid transparent;
  padding: 8px 12px; border-radius: 8px; flex: 1; min-width: 220px; max-width: 380px;
}
.search input { border: none; background: transparent; outline: none; width: 100%; font-size: 14px; font-family: inherit; }
.search span { color: var(--muted); font-size: 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 8px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: all 0.15s ease; font-family: inherit; text-decoration: none;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* Table */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.table-head { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.table-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.table-head .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 20px; font-size: 14px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfc; }
tfoot td { background: #fafbfc; font-size: 13px; border-top: 2px solid var(--border); }
.collector { display: flex; align-items: center; gap: 10px; }
.collector .ava { width: 30px; height: 30px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.pill.green { background: var(--success-soft); color: var(--success); }
.pill.amber { background: var(--warning-soft); color: var(--warning); }
.pill.sky { background: var(--sky-soft); color: var(--sky); }
.pill.muted { background: #f1f5f9; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.date-cell { white-space: nowrap; color: var(--muted); font-size: 13px; }
.money-cell { white-space: nowrap; font-weight: 600; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 500px;
  box-shadow: var(--shadow-md); overflow: hidden; max-height: 92vh; overflow-y: auto;
}
.modal header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.modal .body { padding: 20px 24px; display: grid; gap: 14px; }
.modal footer { padding: 16px 24px; background: #fafbfc; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
label { font-size: 13px; font-weight: 600; color: var(--text); }
.field { display: grid; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input, select {
  width: 100%; padding: 10px 12px; font-size: 14px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; outline: none; transition: border 0.15s ease;
  font-family: inherit;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.close { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 20px; padding: 0; line-height: 1; }
.hint { font-size: 12px; color: var(--muted); }
.total-preview { font-size: 13px; background: var(--primary-soft); border-radius: 8px; padding: 8px 12px; color: var(--text); }

/* Programme matching checkbox grid */
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.check-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.check-item input { width: auto; accent-color: var(--primary); cursor: pointer; }
.check-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: #0f172a; color: #fff;
  padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-md);
  font-size: 14px; transform: translateY(20px); opacity: 0; pointer-events: none;
  transition: all 0.25s ease; z-index: 60; max-width: 440px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast .ok { color: #4ade80; margin-right: 6px; }
.toast.error .ok { color: #f87171; }

/* Login */
.login-body {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #eef2ff 0%, #f5f7fb 45%, #ecfdf5 100%);
}
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-md); width: 100%; max-width: 400px; padding: 36px 32px 32px;
}
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.login-form { display: grid; gap: 14px; }
.login-btn { width: 100%; justify-content: center; margin-top: 6px; padding: 11px; }
.login-alert { border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.login-alert.err { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.login-alert.ok { background: var(--success-soft); color: var(--success); border: 1px solid #bbf7d0; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  aside { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  main { padding: 16px; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
