/* CourtFlow admin -- front-desk tool. Legibility and quick taps on a tablet
   over decoration. Plain CSS, no framework (the app must work with no
   internet, so nothing loads from a CDN). */

:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #15803d;
  --accent-hover: #166534;
  --accent-ink: #ffffff;
  --warn-bg: #fef3c7;
  --warn-line: #fbbf24;
  --error: #dc2626;
  --ok: #16a34a;
  --range-accent: #ea580c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { line-height: 1.2; }
a { color: var(--accent); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 32px; width: 340px; max-width: 100%; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.login-logo { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 800; font-size: 20px; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; letter-spacing: -.02em; }
.login-card h1 { margin: 0 0 2px; font-size: 20px; }
.login-card form { text-align: left; margin-top: 20px; }
.login-card .hint { margin-top: 16px; font-size: 12px; color: var(--muted); background: #f8fafc; border-radius: 8px; padding: 8px; }

/* ---- Layout ---- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.01em; }
.topbar-brand .dot { width: 22px; height: 22px; border-radius: 7px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; display: none; font-size: 15px; }

.shell { display: flex; min-height: calc(100vh - 49px); }
.sidenav { width: 210px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item { text-align: left; background: none; border: none; border-radius: 8px; padding: 10px 12px; font-size: 14px; cursor: pointer; color: var(--muted); }
.nav-item:hover { background: #f1f5f9; color: var(--ink); }
.nav-item.active { background: var(--accent); color: #fff; }

.content { flex: 1; padding: 20px 24px; min-width: 0; }

@media (max-width: 800px) {
  .icon-btn { display: inline-block; }
  .sidenav { position: fixed; left: -240px; top: 49px; bottom: 0; transition: left .15s; z-index: 20; box-shadow: 2px 0 8px rgba(0,0,0,.1); }
  .sidenav.open { left: 0; }
  .content { padding: 16px; }
}

/* ---- Components ---- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.page-header h1 { margin: 0; font-size: 22px; }
.page-header .subtitle { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 15px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 12px 0; }

.grid { display: grid; gap: 12px; }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .grid-5, .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid-5, .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.stat-tile .label { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.stat-tile .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-tile .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tone-red .value { color: var(--error); }
.tone-green .value { color: var(--ok); }
.tone-amber .value { color: #b45309; }
.tone-accent .value { color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; text-transform: uppercase; font-size: 11px; letter-spacing: .03em; color: var(--muted); padding: 8px 10px; background: #f8fafc; border-bottom: 1px solid var(--line); }
td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
tr:hover td { background: #f8fafc; }
.text-right { text-align: right; }
.table-scroll { overflow-x: auto; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--ink); }
th.sort-active { color: var(--accent); }

.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; background: #e2e8f0; color: var(--ink); }
.pill-green { background: #dcfce7; color: #166534; }
.pill-red { background: #fee2e2; color: #991b1b; }
.pill-amber { background: #fef3c7; color: #92400e; }
.pill-blue { background: #dbeafe; color: #1e40af; }
.pill-slate { background: #e2e8f0; color: #334155; }
.pill-purple { background: #ede9fe; color: #6d28d9; }

.btn { display: inline-flex; align-items: center; gap: 6px; border-radius: 8px; padding: 8px 14px; font-size: 13.5px; font-weight: 600; border: 1px solid transparent; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--error); color: #fff; }
.btn-ghost { background: none; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
td.text-right a.btn-link, td.text-right button.btn-link {
  display: inline-block; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; text-decoration: none; font-size: 12.5px; font-weight: 600;
}
td.text-right a.btn-link:hover, td.text-right button.btn-link:hover { background: #f1f5f9; }
td.text-right a.btn-link + a.btn-link, td.text-right button.btn-link + button.btn-link { margin-left: 6px; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 10px; }
input, select, textarea {
  width: 100%; margin-top: 4px; padding: 8px 10px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-row { display: flex; gap: 12px; }
.form-row > label { flex: 1; }
@media (max-width: 520px) { .form-row { flex-direction: column; gap: 0; } }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.error { color: var(--error); font-size: 13px; }
.field-hint { font-weight: 400; color: var(--muted); font-size: 12px; }

/* ---- Banner ---- */
.banner { border-radius: 8px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 12px; }
.banner.error { background: #fee2e2; color: #991b1b; }
.banner.info { background: #dbeafe; color: #1e40af; }
.banner.warn { background: var(--warn-bg); color: #92400e; border: 1px solid var(--warn-line); }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; padding: 22px; width: 460px; max-width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.modal h2 { margin: 0 0 14px; font-size: 17px; }

/* ---- Toast ---- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13.5px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.error { background: var(--error); }

/* ---- Placeholder (unbuilt milestones) ---- */
.placeholder { text-align: center; padding: 60px 20px; color: var(--muted); }
.placeholder .big { font-size: 40px; margin-bottom: 8px; }

/* ---- Court dashboard ---- */
.court-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.court-tile { background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.court-tile.is-available { border-left-color: var(--ok); }
.court-tile.is-occupied  { border-left-color: var(--accent); }
.court-tile.is-maintenance { border-left-color: var(--muted); background: #f8fafc; }
.court-tile.is-overtime { border-left-color: var(--error); border-color: #fca5a5; background: #fef2f2; animation: court-flash 1.1s ease-in-out infinite; }
@keyframes court-flash { 0%,100% { background: #fef2f2; } 50% { background: #fee2e2; } }

.court-top { display: flex; justify-content: space-between; align-items: baseline; }
.court-name { font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.court-flag { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.court-customer { font-size: 13.5px; font-weight: 600; }
.court-timer { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--ink); }
.court-timer-idle { color: var(--line); }
.is-overtime .court-timer { color: var(--error); }
.court-meta { font-size: 12px; color: var(--muted); }
.court-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; align-items: center; }
.court-actions .btn { padding: 7px 12px; font-size: 12.5px; }
.court-actions .court-cancel { margin-left: auto; color: var(--muted); }

/* ---- Cash quick-fill buttons ---- */
.cash-quick { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin: 6px 0 0; }
.cash-quick .cq {
  border: 1px solid var(--line); background: #fff; border-radius: 7px;
  padding: 5px 12px; font-size: 12.5px; font-weight: 700; color: var(--ink); cursor: pointer;
}
.cash-quick .cq:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Calc box (session forms) ---- */
.calc-box { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 12px 0; font-size: 13.5px; }
.calc-box span { color: var(--muted); }
.calc-box strong { text-align: right; }
.calc-box strong:last-of-type { font-size: 16px; }

/* ---- Mini tables (modals) ---- */
.mini-table { font-size: 13px; }
.mini-table th { background: none; text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--muted); font-weight: 600; width: 120px; padding: 5px 8px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.mini-table td { padding: 5px 8px; }
.mini-table thead th { width: auto; }
.row-voided td { text-decoration: line-through; color: var(--muted); }
.modal h3 { margin: 0; }
.modal .mini-table { width: 100%; }
.modal--wide { width: 720px; max-width: 100%; }

/* ---- Action grid (inventory item actions) ---- */
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.action-grid .btn { justify-content: center; }
@media (max-width: 460px) { .action-grid { grid-template-columns: 1fr; } }

/* ---- Reports ---- */
.pnl-table td { padding: 7px 10px; border-bottom: 1px solid #f1f5f9; }
.pnl-table td:first-child { white-space: pre; }
.pnl-table .pnl-sub td { font-weight: 700; background: #f8fafc; }
.pnl-table .pnl-total td { font-weight: 800; font-size: 15px; border-top: 2px solid var(--ink); border-bottom: none; }
.bar { background: #eef2f7; border-radius: 999px; height: 10px; overflow: hidden; min-width: 80px; }
.bar span { display: block; height: 100%; background: var(--accent); }
tr.tr-total td, tr.tr-total th { border-top: 2px solid var(--line); background: #f8fafc; }

.text-center { text-align: center; }
.perm-matrix td, .perm-matrix th { vertical-align: middle; }
.perm-matrix td:first-child { max-width: 260px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tabs .tab { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs .tab:hover { color: var(--ink); }
.tabs .tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.report-actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 10px; flex-wrap: wrap; }

/* ---- Booking schedule ---- */
.court-next {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; width: 100%; text-align: left;
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 7px 10px;
  cursor: pointer; font-size: 12px; color: #166534; font-weight: 600; font-family: inherit;
}
.court-next:hover { background: #dcfce7; }
.court-next-cta { margin-left: auto; font-weight: 800; color: var(--accent); white-space: nowrap; }
.sched-block { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 5px 0; border-bottom: 1px solid #f1f5f9; }
.sched-block .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.sched-block.sb-booking .dot { background: var(--accent); }
.sched-block.sb-session .dot { background: #b45309; }
.sched-block .sb-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched-frees { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.sched-free { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; padding: 6px 10px; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; }
.sched-free span { color: #166534; font-weight: 600; }
.sched-free .btn-link {
  padding: 4px 14px; border: 1px solid var(--accent); border-radius: 999px;
  color: var(--accent); font-weight: 700; font-size: 11.5px; background: #fff; text-decoration: none;
}
.sched-free .btn-link:hover { background: var(--accent); color: #fff; }

.rental-out-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 0 3px 12px; font-size: 13px; }
.rental-out-row .btn-link {
  padding: 3px 12px; border: 1px solid var(--accent); border-radius: 999px;
  color: var(--accent); font-weight: 700; font-size: 11.5px; background: #fff;
}
.rental-out-row .btn-link:hover { background: var(--accent); color: #fff; }

/* ---- Tablet / phone pass (front-desk devices) ---- */
@media (max-width: 560px) {
  body { font-size: 14px; }
  .content { padding: 14px 12px; }
  .topbar { padding: 8px 10px; gap: 8px; }
  .topbar-brand { font-size: 15px; }
  #user-name { display: none; }
  .topbar-user { gap: 6px; }
  .topbar-user .btn { padding: 6px 10px; white-space: nowrap; }
  .page-header { align-items: stretch; }
  .page-header h1 { font-size: 19px; }
  .page-header > .btn, .page-header > button { width: 100%; justify-content: center; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; justify-content: center; white-space: nowrap; }
  .card { padding: 13px; }
  .toolbar { gap: 6px; }
  .toolbar label, .toolbar input, .toolbar select { font-size: 13px; }
  .toolbar input[type="date"] { flex: 1 1 130px; min-width: 0; }
  .modal-backdrop { padding: 16px 10px; }
  .modal { padding: 18px 14px; }
  .court-timer { font-size: 30px; }
  .court-actions .btn { flex: 1 1 auto; }
  .court-actions .court-cancel { flex: 0 0 auto; }
  .action-grid { grid-template-columns: 1fr; }
  .btn, .btn-link { min-height: 38px; }
  .report-actions { justify-content: stretch; }
  .report-actions .btn { flex: 1; justify-content: center; }

  /* --- List tables become stacked cards (labels filled in by labelizeTable) --- */
  .table-scroll { overflow-x: visible; }
  .table-scroll table,
  .table-scroll table tbody,
  .table-scroll table tr,
  .table-scroll table td { display: block; width: 100%; }
  .table-scroll table thead { display: none; }
  .table-scroll table tr {
    border: 1px solid var(--line); border-radius: 10px;
    padding: 4px 12px; margin-bottom: 10px; background: var(--panel);
  }
  .table-scroll table tr:last-child { margin-bottom: 0; }
  .table-scroll table tr:hover td { background: none; }
  .table-scroll table td {
    padding: 7px 0; border: none; border-bottom: 1px solid #f1f5f9;
    white-space: normal; text-align: right;
    display: flex; gap: 12px; justify-content: space-between; align-items: baseline;
  }
  .table-scroll table td:last-child { border-bottom: none; }
  .table-scroll table td::before {
    content: attr(data-label); flex: 0 0 40%; text-align: left;
    font-size: 10.5px; font-weight: 700; letter-spacing: .03em;
    text-transform: uppercase; color: var(--muted); line-height: 1.5;
  }
  /* first cell = the row's heading: full width, inline flow, no label prefix */
  .table-scroll table td:first-child {
    display: block; text-align: left; font-weight: 700; font-size: 13.5px;
    padding-top: 4px;
  }
  .table-scroll table td:first-child::before { display: none; }
  .table-scroll table td:first-child .muted { font-weight: 400; }
  /* cells with no header (action buttons) and colspan/empty cells: no label gutter */
  .table-scroll table td[data-label=""]::before { display: none; }
  .table-scroll table td[data-label=""] { justify-content: flex-end; gap: 6px; flex-wrap: wrap; padding-top: 9px; }
  .table-scroll table td.cell-span { justify-content: flex-start; color: var(--muted); }
  .table-scroll table td.cell-span::before { display: none; }
  .table-scroll table td:empty { display: none; }
  /* action buttons in a stacked row: comfortable tap targets */
  .table-scroll table td[data-label=""] .btn-link,
  .table-scroll table td[data-label=""] .btn {
    border: 1px solid var(--line); border-radius: 7px; padding: 7px 14px;
    background: #fff; font-weight: 600; min-height: 0; margin: 0;
  }
  .table-scroll td.text-right a.btn-link + a.btn-link,
  .table-scroll td.text-right button.btn-link + button.btn-link { margin-left: 0; }
  .perm-matrix td:first-child { font-size: 12.5px; font-weight: 600; }
  .perm-matrix td:first-child strong { font-size: 13px; }
}

/* ---- Print / "Save as PDF" ---- */
#print-mount { display: none; }
.print-stamp { display: none; font-size: 11px; color: #555; margin: 0 0 12px; }
@media print {
  body.printing { background: #fff; }
  body.printing > *:not(#print-mount) { display: none !important; }
  body.printing #print-mount { display: block !important; }
  #print-mount .print-stamp { display: block; }
  #print-mount .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  #print-mount .no-print, #print-mount [data-print], #print-mount .btn, #print-mount .btn-link { display: none !important; }
  #print-mount .bar { border: 1px solid #999; }
  #print-mount .bar span { background: #666; }
  @page { margin: 14mm; }
}
