:root {
    --available: #1f8f3a;
    --available-bg: #c8f0d2;
    --sel: #16783f;
    --sel-bg: #94e3a6;
    --booked: #d1373f;
    --booked-bg: #fbeaea;
    --mine: #d6337a;
    --mine-bg: #ffd6e8;
    --unavailable: #9aa0a6;
    --unavailable-bg: #f2f3f5;
    --line: #e2e4e8;
    --accent: #2f6fed;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Segoe UI, sans-serif;
    color: #23262b;
    background: #f7f8fa;
}

header {
    padding: 10px 10px 0;
    background: #fff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}

h1 { font-size: 16px; margin: 0 0 8px; text-align: center; }

#date-bar {
    display: flex;
    gap: 4px;
    padding-bottom: 6px;
}

.date-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 3px 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    text-align: center;
    line-height: 1.3;
    font: inherit;
    font-size: 12px;
}
.date-btn small { display: block; color: #8b9098; font-size: 11px; }
.date-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}
.date-btn.active small { color: #dfe8ff; }

main { padding: 16px 0; overflow-x: auto; }

table.grid {
    border-collapse: collapse;
    width: 100%;
    min-width: 560px;
    background: #fff;
    font-size: 12px;
}
table.grid tbody tr:nth-child(odd) td { background: #f4f6f8; }
table.grid th, table.grid td {
    border: 1px solid var(--line);
    padding: 4px 3px;
    text-align: center;
    white-space: nowrap;
}
table.grid thead th {
    background: #fafbfc;
    position: sticky;
    top: 0;
}
table.grid th.time-col, table.grid td.time-col {
    position: sticky;
    left: 0;
    background: #fafbfc;
    font-weight: 600;
    z-index: 2;
}
table.grid tbody tr:nth-child(odd) td.time-col {
    background: #f0f2f4;
}

.cell {
    border-radius: 4px;
    padding: 3px 2px;
    line-height: 1.3;
    min-height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cell .price { font-weight: 600; }
.cell .tag { font-size: 11px; }
.cell .warn-badge { font-size: 10px; width: 13px; height: 13px; }

.cell.available   { background: var(--available-bg);   color: var(--available); cursor: pointer; }
.cell.available.selected { background: var(--sel-bg); color: var(--sel); font-weight: 700; }
.cell.booked      { background: var(--booked-bg);      color: var(--booked); }
.cell.unavailable { background: var(--unavailable-bg); color: var(--unavailable); }

/* 本人预订：粉红背景 */
.cell.booked.mine { background: var(--mine-bg); color: var(--mine); font-weight: 700; }
.cell.clickable { cursor: pointer; }

/* 订单详情弹窗 */
#detail-modal[hidden] { display: none; }
#detail-modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-box {
    position: relative; background: #fff; border-radius: 12px; padding: 22px 24px;
    width: 340px; max-width: 92vw; box-shadow: 0 6px 30px rgba(0,0,0,.2);
}
.modal-close {
    position: absolute; top: 8px; right: 10px; border: none; background: none;
    font-size: 22px; line-height: 1; color: #9aa0a6; cursor: pointer;
}
#detail-body h3 { margin: 0 0 12px; font-size: 16px; }
#detail-body p { margin: 6px 0; font-size: 14px; }
.detail-court { font-size: 16px !important; }
.detail-code { margin: 12px 0; padding: 10px; background: #f2f6ff; border-radius: 8px; font-size: 15px; text-align: center; }
.detail-code b { font-size: 20px; letter-spacing: 2px; color: var(--accent); }
.detail-code.muted, .muted { color: #9aa0a6; }
.detail-qr { margin: 10px auto 0; width: 160px; }
.detail-qr svg { width: 100%; height: auto; display: block; }
.detail-total b { font-size: 18px; color: var(--booked); cursor: pointer; user-select: none; }
.detail-actions { margin-top: 16px; text-align: right; }
#detail-cancel {
    padding: 8px 18px; border: 1px solid var(--booked); color: var(--booked);
    background: #fff; border-radius: 6px; cursor: pointer; font-size: 14px;
}
#detail-cancel:disabled { opacity: .5; }


#grid-loading, #grid-error {
    padding: 40px;
    text-align: center;
    color: #8b9098;
}
#grid-error { color: var(--booked); }

.legend { display: flex; gap: 10px; margin: 8px 8px; font-size: 11px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* -- book bar -- */
#book-bar {
    position: sticky; bottom: 0; z-index: 20;
    background: #fff; border-top: 1px solid var(--line);
    padding: 8px 10px; display: flex; align-items: center; gap: 8px;
    flex-wrap: wrap; font-size: 13px;
}
#book-bar[hidden] { display: none; }   /* 盖过上面的 display:flex，使 hidden 生效 */
#book-summary { flex: 1 1 200px; }
#book-total { font-weight: 700; min-width: 80px; }
#book-clear { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
#book-submit { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 6px 18px; cursor: pointer; font-weight: 600; }
#book-submit:disabled { opacity: .5; }

/* -- tables (orders, admin) -- */
table.list { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }
table.list th { background: #fafbfc; }
.st-success td { color: #16783f; }
.st-failed td { color: var(--booked); }
.st-cancelled td { color: #9aa0a6; }

/* 未在球馆实际占场的警告徽标 */
.warn-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 15px; height: 15px; border-radius: 50%;
    background: #ff9800; color: #fff; font-size: 11px; font-weight: 700;
    line-height: 1; margin-left: 2px; vertical-align: middle;
}
.cancel-btn {
    padding: 3px 10px; border: 1px solid var(--booked); color: var(--booked);
    background: #fff; border-radius: 4px; cursor: pointer; font-size: 12px;
}
.cancel-btn:disabled { opacity: .5; }
.paid-btn {
    padding: 3px 10px; border: 1px solid var(--accent); color: var(--accent);
    background: #fff; border-radius: 4px; cursor: pointer; font-size: 12px;
    margin-right: 4px;
}
.paid-btn:disabled { opacity: .5; }

#reconcile-btn {
    font-size: 12px; font-weight: 400; padding: 3px 12px; margin-left: 8px;
    border: 1px solid var(--accent); color: var(--accent); background: #fff;
    border-radius: 4px; cursor: pointer;
}
#reconcile-btn:disabled { opacity: .5; }
#reconcile-result { font-size: 12px; font-weight: 400; color: #8b9098; }
.vs-ok { color: #16783f; }
.vs-warn { color: #ff9800; }
.vs-bad { color: var(--booked); font-weight: 700; }
.vs-none { color: #b0b4ba; }

/* 用户管理 / 改密表单 */
.create-user { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.create-user input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; font: inherit; }
.create-user button, .toggle-btn {
    padding: 5px 14px; background: var(--accent); color: #fff; border: none;
    border-radius: 4px; cursor: pointer; font-size: 13px;
}
.toggle-btn { background: var(--booked); }
.toggle-btn.on { background: #16783f; }

.name-inp { width: 90px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; font: inherit; }
.name-btn { padding: 4px 8px; margin-left: 4px; border: 1px solid var(--line); background: #fff; border-radius: 4px; cursor: pointer; }

.pw-form { display: flex; flex-direction: column; gap: 10px; max-width: 320px; }
.pw-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #555; }
.pw-form input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.pw-form button {
    padding: 9px; background: var(--accent); color: #fff; border: none;
    border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 600;
}
#view-orders, #view-recharge, #view-pricing, #view-users, #view-profile { padding: 0 10px; }
#view-recharge, #view-users, #view-profile { max-width: 900px; }
h2 { font-size: 15px; margin: 20px 0 10px; }

.auth-hint { text-align: center; color: #9aa0a6; font-size: 12px; margin-top: 14px; }

/* -- admin recharge inputs -- */
.rc-amt, .rc-note { width: 80px; padding: 4px; border: 1px solid var(--line); border-radius: 4px; }
.rc-note { width: 100px; }
.rc-btn { padding: 4px 10px; background: var(--accent); color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.bal { font-weight: 600; }
.empty { text-align: center; color: #8b9098; padding: 40px; }
.mono { font-family: monospace; font-size: 11px; }

/* -- user bar (header row 2) -- */
#userbar { display: flex; align-items: center; gap: 8px; padding-bottom: 6px; font-size: 13px; flex-wrap: wrap; }
#who { font-weight: 600; white-space: nowrap; }
#mainnav { display: flex; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
#mainnav::-webkit-scrollbar { display: none; }
#mainnav button { padding: 4px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font: inherit; font-size: 12px; white-space: nowrap; flex-shrink: 0; }
#mainnav button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#logout { color: var(--booked); }

/* -- auth page -- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card { width: 360px; max-width: 92vw; background: #fff; border-radius: 12px; padding: 24px; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.auth-card h1 { font-size: 18px; }
.auth-card label { display: block; margin-bottom: 12px; font-size: 13px; color: #555; }
.auth-card input { width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.auth-card button[type=submit] { width: 100%; padding: 10px; background: var(--accent); color: #fff; border: none; border-radius: 6px; font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 4px; }
.auth-error { color: var(--booked); font-size: 13px; margin: 6px 0 0; min-height: 18px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tabs button { flex: 1; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font: inherit; }
.auth-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

footer { padding: 12px 10px; text-align: center; color: #9aa0a6; font-size: 12px; }

