/* ===== Pickle Manager — mobile-first ===== */
:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #0b1220;
  --accent: #22c55e;
  --accent-dim: #16a34a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --danger: #f87171;
  --warn: #fbbf24;
  --info: #60a5fa;
  --radius: 14px;
  --nav-h: 64px;
  --maxw: 480px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }
body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  /* Chừa chỗ cho thanh nav cố định + đệm để ô cuối không bị che. */
  padding-bottom: calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom));
}

/* ---- App bar ---- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: baseline;
  gap: .5rem;
  padding: 1rem 1rem .85rem;
  background: rgba(15, 23, 42, .9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  max-width: var(--maxw);
  margin: 0 auto;
}
.brand { font-weight: 700; font-size: 1.15rem; }
.appbar-sub { color: var(--muted); font-size: .8rem; margin-left: auto; }
.appbar-btn {
  margin-left: .6rem; align-self: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; font-size: 1.1rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.appbar-btn:active { transform: scale(.95); }
/* Khi chưa đăng nhập thì ẩn nút góp ý (appbar-sub đẩy về phải vẫn ổn). */
body.logged-out .appbar-btn { display: none; }

/* ---- View container ---- */
#view, #bview {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

h2.section { margin: .5rem 0 0; font-size: 1.05rem; }
.muted { color: var(--muted); }
.empty {
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
  font-style: italic;
}

/* ---- Stat cards ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem .6rem;
  text-align: center;
}
.stat .num { font-size: 1.25rem; font-weight: 700; }
.stat .num.money { color: var(--accent); font-size: 1.05rem; }
.stat .lbl { color: var(--muted); font-size: .72rem; margin-top: .15rem; }

/* ---- Generic card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
}

/* ---- Booking item ---- */
.booking {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  border-left: 4px solid var(--info);
}
.booking.done { border-left-color: var(--accent); opacity: .85; }
.booking.cancelled { border-left-color: var(--danger); opacity: .55; }
.booking .top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.booking .time { font-weight: 700; font-size: 1rem; }
.booking .court { color: var(--muted); font-size: .85rem; }
.booking .who { font-size: .92rem; }
.booking .who a { color: var(--info); text-decoration: none; }
.booking .price { color: var(--accent); font-weight: 600; }
.booking .acts { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .2rem; }
.booking .deposit-line .remain { color: var(--warn); font-weight: 600; font-size: .85rem; }

/* ---- Court item ---- */
.court {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
}
.court .meta .name { font-weight: 600; }
.court .meta .price { color: var(--accent); font-size: .85rem; }
.court.off { opacity: .55; }
.court .court-acts { display: flex; gap: .35rem; align-items: center; }

/* ---- Badges ---- */
.badge { padding: .12rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.badge.booked { background: #1e3a8a; color: #bfdbfe; }
.badge.done { background: #14532d; color: #bbf7d0; }
.badge.cancelled { background: #450a0a; color: #fecaca; }
.badge.off { background: #3f3f46; color: #d4d4d8; }
.badge.warn { background: #78350f; color: #fde68a; }
.badge.pending { background: #422006; color: #fdba74; }

/* ---- Lượt quá hạn chưa chốt (trang Hôm nay) ---- */
.overdue { display: flex; flex-direction: column; gap: .7rem; }
.overdue .section { color: var(--warn); }
.card.overdue-card { border-color: var(--warn); }

/* ---- Buttons ---- */
button { font: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .6rem 1rem;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #052e16;
  font-weight: 700;
  min-height: 44px;
}
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.sm { padding: .4rem .7rem; min-height: 38px; font-size: .85rem; border-radius: 8px; }
.btn.sm.ghost { font-weight: 600; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid #7f1d1d; }
.btn.danger:active { background: #7f1d1d; color: #fff; }
.btn.ok { background: var(--accent); color: #052e16; }
.btn.warn { background: transparent; color: var(--warn); border: 1px solid var(--warn); }
.btn.warn:active { background: var(--warn); color: #422006; }

/* ---- Date strip ---- */
.datestrip {
  display: flex; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .5rem .6rem;
}
.datestrip .arrow {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: 8px; font-size: 1.1rem;
}
.datestrip .cur { flex: 1; text-align: center; }
.datestrip .cur .d { font-weight: 700; }
.datestrip .cur .w { color: var(--muted); font-size: .78rem; }
.datestrip input[type=date] {
  position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;
}

/* ---- FAB ---- */
.fab {
  position: fixed;
  right: max(1rem, calc(50vw - var(--maxw) / 2 + 1rem));
  bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom));
  z-index: 25;
  height: 54px; padding: 0 1.3rem;
  border-radius: 27px; border: none;
  background: var(--accent); color: #052e16;
  font-weight: 800; font-size: .95rem;
  box-shadow: 0 6px 20px rgba(34, 197, 94, .35);
}

/* ---- Bottom nav ---- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(15, 23, 42, .96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
.nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
  background: none; border: none; color: var(--muted);
  font-size: .72rem; font-weight: 600;
}
.nav-item .ico { font-size: 1.25rem; filter: grayscale(.4); }
.nav-item.active { color: var(--accent); }
.nav-item.active .ico { filter: none; }

/* ---- Bottom sheet ---- */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .55);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: var(--maxw); margin: 0 auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--border);
  padding: 1rem 1.1rem calc(1.2rem + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h3 { margin: .2rem 0 1rem; display: flex; align-items: center; gap: .5rem; }
.sheet .grab { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto .8rem; }

/* ---- Form ---- */
.field { margin-bottom: .8rem; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .3rem; }
.field-row { display: flex; gap: .6rem; }
.field-row .field { flex: 1; }
input, select, textarea {
  width: 100%; font: inherit;
  padding: .7rem .75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { min-height: 60px; resize: vertical; }
.switch { display: flex; align-items: center; gap: .5rem; }
.switch input { width: auto; min-height: auto; }

.total-hint {
  background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: 10px; padding: .6rem .75rem; margin-bottom: .9rem;
  display: flex; justify-content: space-between; align-items: center;
}
.total-hint .v { color: var(--accent); font-weight: 700; font-size: 1.1rem; }
.sheet-actions { display: flex; gap: .6rem; margin-top: .4rem; }
.sheet-actions .btn { flex: 1; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 1.2rem + env(safe-area-inset-bottom));
  z-index: 60;
  background: #0b1220; border: 1px solid var(--border);
  color: var(--text); padding: .7rem 1rem; border-radius: 10px;
  max-width: 90vw; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  font-size: .9rem; transition: opacity .25s, transform .25s;
}
.toast.err { border-color: #7f1d1d; }
.toast.ok { border-color: var(--accent-dim); }

.hidden { display: none !important; }

/* ---- Trang đặt sân công khai ---- */
body.public { padding-bottom: 1.5rem; }
body.public .appbar { justify-content: center; }
.share-box {
  display: flex; gap: .5rem; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .55rem .7rem; margin-top: .5rem;
}
.share-box code {
  flex: 1; font-size: .8rem; color: var(--info);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.qr-wrap { display: flex; justify-content: center; margin: .4rem 0 .8rem; }
.qr-img {
  width: 220px; height: 220px; background: #fff; padding: 10px;
  border-radius: 12px; display: block;
}

/* ---- Màn đăng nhập / đăng ký ---- */
body.logged-out { padding-bottom: 0; }
body.logged-out .bottomnav,
body.logged-out .appbar-sub { display: none !important; }
.auth { max-width: 360px; margin: 1.5rem auto 0; }
.auth-logo { font-size: 3rem; text-align: center; line-height: 1; }
.auth-title { text-align: center; margin: .3rem 0 .1rem; }
.auth-tag { text-align: center; margin: 0 0 .4rem; }
.auth .segmented { margin: 1rem 0; }
.auth .field { margin-bottom: .9rem; }

/* ---- Segmented control ---- */
.segmented {
  display: flex; gap: .25rem; padding: .25rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px;
}
.segmented button {
  flex: 1; padding: .5rem; border: none; border-radius: 8px;
  background: transparent; color: var(--muted); font-weight: 600;
}
.segmented button.on { background: var(--accent); color: #052e16; }

/* ---- Thống kê ---- */
.stat-hero {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem; text-align: center;
}
.stat-hero .big { font-size: 1.9rem; font-weight: 800; color: var(--accent); }
.stat-hero .cap { color: var(--muted); font-size: .85rem; }
/* Ô doanh thu tích luỹ — phân biệt với ô doanh thu kỳ (dự kiến) ở trên. */
.stat-hero.lifetime { background: var(--surface-2); border-color: var(--accent-dim); }
.stat-hero.lifetime .big { font-size: 1.5rem; }
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.mini { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .7rem .5rem; text-align: center; }
.mini .n { font-weight: 700; }
.mini .l { color: var(--muted); font-size: .72rem; }

.chart {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem .8rem .6rem;
}
.chart { overflow: hidden; } /* chặn nhãn tràn ra ngoài mép thẻ */
/* Grid minmax(0,1fr): các cột luôn chia đều & co lại vừa khung, không tràn
   dù có nhiều ngày (flex shrink không ổn định khi 30+ cột). */
.chart .bars {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  align-items: end;
  gap: 8px;
  height: 152px;
}
.chart .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; }
.chart .val { font-size: .6rem; font-weight: 700; color: var(--muted); white-space: nowrap; line-height: 1; min-height: .65rem; }
.chart .bar {
  width: 100%; max-width: 54px; min-height: 3px; border-radius: 5px 5px 0 0;
  background: linear-gradient(var(--accent), var(--accent-dim));
}
.chart .col.empty .bar { background: var(--border); opacity: .6; }
.chart .col.today .bar { outline: 2px solid var(--info); outline-offset: 1px; }
.chart .xl { font-size: .66rem; color: var(--muted); white-space: nowrap; }
.chart .col.today .xl { color: var(--info); font-weight: 700; }
.chart .cap { text-align: center; color: var(--muted); font-size: .78rem; margin-top: .5rem; }

/* ---- Lịch lưới khung giờ ---- */
.grid-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); -webkit-overflow-scrolling: touch; }
.tgrid { display: grid; position: relative; }
.tgrid .gcell {
  border-bottom: 1px solid rgba(51,65,85,.5);
  border-right: 1px solid rgba(51,65,85,.5);
}
.tgrid .gcell.slot { cursor: pointer; }
.tgrid .gcell.slot:hover { background: rgba(34,197,94,.08); }
.tgrid .ghead {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface-2); text-align: center; font-weight: 700; font-size: .8rem;
  padding: .45rem .2rem; border-bottom: 1px solid var(--border); border-right: 1px solid rgba(51,65,85,.5);
}
.tgrid .gtime {
  position: sticky; left: 0; z-index: 2;
  background: var(--surface-2); color: var(--muted); font-size: .68rem;
  padding: 2px 4px; text-align: right; border-right: 1px solid var(--border);
}
.tgrid .gcorner { position: sticky; left: 0; top: 0; z-index: 4; background: var(--surface-2); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.tgrid .gbook {
  z-index: 1; margin: 1px; border-radius: 6px; padding: 3px 5px; overflow: hidden;
  font-size: .7rem; line-height: 1.25; cursor: pointer; border-left: 3px solid;
  background: #1e3a8a33; border-left-color: var(--info); color: #dbeafe;
}
.tgrid .gbook.done { background: #14532d33; border-left-color: var(--accent); color: #bbf7d0; }
.tgrid .gbook.cancelled { background: #45050533; border-left-color: var(--danger); color: #fecaca; text-decoration: line-through; opacity: .7; }
.tgrid .gbook .gb-t { font-weight: 700; }
.tgrid .gbook .gb-c { opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Confirm dialog ---- */
.dialog-scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem;
  animation: pop .16s ease;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.dialog .d-icon { font-size: 2rem; text-align: center; }
.dialog h4 { margin: .5rem 0 .3rem; text-align: center; font-size: 1.1rem; }
.dialog p { margin: 0 0 1.1rem; text-align: center; color: var(--muted); font-size: .92rem; }
.dialog .d-actions { display: flex; gap: .6rem; }
.dialog .d-actions .btn { flex: 1; }
/* Trong hộp xác nhận, nút nguy hiểm là hành động chính -> nền đỏ đặc. */
.dialog .d-actions .btn.danger { background: var(--danger); color: #3f0d0d; border: none; }
.dialog .d-actions .btn.danger:active { background: #ef4444; }

/* ---- Hoá đơn khổ nhỏ (58mm) ---- */
.receipt {
  background: #fff; color: #111;
  width: 280px; max-width: 100%;
  margin: 0 auto; padding: 14px 16px;
  font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: 12.5px; line-height: 1.5;
  border-radius: 6px;
}
.receipt .r-center { text-align: center; }
.receipt .r-shop { font-size: 15px; font-weight: 700; }
.receipt .r-title { font-weight: 700; letter-spacing: 1px; margin: 6px 0; }
.receipt hr { border: none; border-top: 1px dashed #888; margin: 8px 0; }
.receipt .r-row { display: flex; justify-content: space-between; gap: 8px; }
.receipt .r-row .lbl { color: #444; }
.receipt .r-total { font-size: 15px; font-weight: 700; }
.receipt .r-paid { text-align: center; font-weight: 700; margin-top: 4px; }
.receipt .r-paid.yes { color: #15803d; }
.receipt .r-paid.no { color: #b45309; }
.receipt .r-foot { text-align: center; margin-top: 8px; color: #555; }
.receipt .r-sign { display: flex; gap: 12px; margin-top: 10px; text-align: center; }
.receipt .r-sign > div { flex: 1; font-weight: 700; font-size: 11px; padding-top: 4px; }
.receipt .r-sign span { font-weight: 400; font-size: 10px; color: #666; }

/* ---- Báo cáo doanh thu (xuất PDF qua in trình duyệt) ---- */
.report {
  background: #fff; color: #111; border-radius: 8px; padding: 16px; font-size: 12px;
}
.report .rp-head { text-align: center; margin-bottom: 12px; }
.report .rp-shop { font-weight: 700; font-size: 15px; }
.report .rp-title { font-weight: 700; margin-top: 8px; letter-spacing: 1px; }
.report .rp-sub { color: #555; }
.report .rp-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.report .rp-table th, .report .rp-table td { border: 1px solid #ccc; padding: 4px 6px; text-align: left; }
.report .rp-table th { background: #16a34a; color: #fff; white-space: nowrap; }
.report .rp-table tr.cancelled td { color: #999; text-decoration: line-through; }
.report .rp-totals { margin-top: 12px; }
.report .rp-totals > div { display: flex; justify-content: space-between; padding: 2px 0; }
.report .rp-grand { border-top: 2px solid #111; font-size: 14px; font-weight: 700; margin-top: 4px; padding-top: 4px; }
.report .rp-meta { color: #555; font-size: 10px; margin-top: 8px; text-align: center; }

/* Khi in: chỉ hiện phần tử .printable (hoá đơn hoặc báo cáo), ẩn còn lại. */
@media print {
  body { background: #fff; padding: 0; }
  body > *:not(#sheet), .sheet > *:not(.printable), .grab, .sheet-actions { display: none !important; }
  #sheet { position: static; max-width: none; box-shadow: none; border: none; padding: 0; max-height: none; animation: none; overflow: visible; }
  .receipt.printable { width: 58mm; border-radius: 0; padding: 0; font-size: 11px; }
  .report.printable { width: 100%; border-radius: 0; padding: 0; }
}

@media (min-width: 520px) {
  .appbar { border-radius: 0 0 var(--radius) var(--radius); }
}
