/* =====================================================================
   SDZ UX layer. Loaded AFTER sdz.css, so it only adds to it.
   Flexibility : collapsible sidebar, table density, filter presets and chips, keyboard shortcuts.
   Comfort     : phone bottom navigation, stacked tables on phones, sticky save bar, dark-mode polish.
   Nothing in this file changes data or server behaviour.
   ===================================================================== */

:root {
  --sdz-link: var(--sdz-primary);
  --sdz-sidebar-w-mini: 76px;
  --sdz-bottomnav-h: 62px;
  --sdz-cell-y: .65rem;
  --sdz-safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-density="compact"] { --sdz-cell-y: .28rem; }
html { -webkit-text-size-adjust: 100%; }
a { color: var(--sdz-link); }
body.menu-open { overflow: hidden; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------------------------------------------------------------------
   Dark mode polish. sdz.css swaps the tokens; these fix the Bootstrap
   components that kept their light colours (menus, modals, alerts, ...).
   --------------------------------------------------------------------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --sdz-link: #9aa4ff;
}
:root[data-theme="dark"] .btn--outline--primary { color: var(--sdz-link); border-color: var(--sdz-link); }
:root[data-theme="dark"] .btn--outline--primary:hover { background: var(--sdz-primary); color: #fff; border-color: var(--sdz-primary); }
:root[data-theme="dark"] .dropdown-menu,
:root[data-theme="dark"] .modal-content,
:root[data-theme="dark"] .popover { background: var(--sdz-surface); color: var(--sdz-ink); border-color: var(--sdz-line); }
:root[data-theme="dark"] .dropdown-item { color: var(--sdz-ink); }
:root[data-theme="dark"] .dropdown-item:hover,
:root[data-theme="dark"] .dropdown-item:focus { background: rgba(255,255,255,.07); color: #fff; }
:root[data-theme="dark"] .dropdown-item.text-danger { color: #f5a3a3 !important; }
:root[data-theme="dark"] .dropdown-divider,
:root[data-theme="dark"] .modal-header,
:root[data-theme="dark"] .modal-footer,
:root[data-theme="dark"] .list-group-item,
:root[data-theme="dark"] .card-footer,
:root[data-theme="dark"] .border,
:root[data-theme="dark"] .border-top,
:root[data-theme="dark"] .border-bottom { border-color: var(--sdz-line) !important; }
:root[data-theme="dark"] .card-footer { background: transparent; }
:root[data-theme="dark"] .list-group-item { color: var(--sdz-ink); }
:root[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
:root[data-theme="dark"] .bg-light { background: rgba(120,130,170,.12) !important; color: var(--sdz-ink) !important; }
:root[data-theme="dark"] .bg-white { background: var(--sdz-surface) !important; color: var(--sdz-ink); }
:root[data-theme="dark"] .text-dark { color: var(--sdz-ink) !important; }
:root[data-theme="dark"] .input-group-text { background: rgba(120,130,170,.14); border-color: var(--sdz-line); color: var(--sdz-muted); }
:root[data-theme="dark"] .form-control::placeholder { color: var(--sdz-muted); opacity: .8; }
:root[data-theme="dark"] .form-control:disabled,
:root[data-theme="dark"] .form-control[readonly] { background: rgba(120,130,170,.1); color: var(--sdz-muted); }
:root[data-theme="dark"] .form-select { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23aab2d6' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); }
:root[data-theme="dark"] .form-check-input { background-color: var(--sdz-surface); border-color: var(--sdz-line); }
:root[data-theme="dark"] .form-check-input:checked { background-color: var(--sdz-primary); border-color: var(--sdz-primary); }
:root[data-theme="dark"] .nav-pills .nav-link { color: var(--sdz-ink); }
:root[data-theme="dark"] .nav-pills .nav-link.active { background: var(--sdz-primary); color: #fff; }
:root[data-theme="dark"] .page-link { background: var(--sdz-surface); border-color: var(--sdz-line); color: var(--sdz-link); }
:root[data-theme="dark"] .page-item.active .page-link { background: var(--sdz-primary); border-color: var(--sdz-primary); color: #fff; }
:root[data-theme="dark"] .page-item.disabled .page-link { background: transparent; color: var(--sdz-muted); }
:root[data-theme="dark"] .badge--success { color: #6ee7a0; }
:root[data-theme="dark"] .badge--warning { color: #fbbf5a; }
:root[data-theme="dark"] .badge--danger  { color: #fca5a5; }
:root[data-theme="dark"] .badge--primary { color: #b4baff; }
:root[data-theme="dark"] .bg-soft-primary { color: #b4baff; }
:root[data-theme="dark"] .bg-soft-success { color: #6ee7a0; }
:root[data-theme="dark"] .bg-soft-warning { color: #fbbf5a; }
:root[data-theme="dark"] .bg-soft-danger  { color: #fca5a5; }
:root[data-theme="dark"] .bg-soft-info    { color: #7dd3fc; }
:root[data-theme="dark"] .badge.bg-light { background: rgba(120,130,170,.25) !important; }
:root[data-theme="dark"] .alert-success { --bs-alert-color: #9be3b5; --bs-alert-bg: rgba(22,163,74,.16);  --bs-alert-border-color: rgba(22,163,74,.38); }
:root[data-theme="dark"] .alert-warning { --bs-alert-color: #f7c56b; --bs-alert-bg: rgba(217,119,6,.18);  --bs-alert-border-color: rgba(217,119,6,.4); }
:root[data-theme="dark"] .alert-info    { --bs-alert-color: #8fd3f4; --bs-alert-bg: rgba(14,165,233,.16); --bs-alert-border-color: rgba(14,165,233,.38); }
:root[data-theme="dark"] .alert-danger  { --bs-alert-color: #f5a3a3; --bs-alert-bg: rgba(220,38,38,.18);  --bs-alert-border-color: rgba(220,38,38,.4); }
:root[data-theme="dark"] .select2-container--default .select2-selection--single,
:root[data-theme="dark"] .select2-dropdown { background: var(--sdz-surface); border-color: var(--sdz-line); }
:root[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered { color: var(--sdz-ink); }
:root[data-theme="dark"] .select2-results__option { color: var(--sdz-ink); }
:root[data-theme="dark"] .ball { color: #14193a; }
:root[data-theme="dark"] .ball--machine { color: #14193a; }
.bg-soft-info { background: rgba(14,165,233,.14); color: #0369a1; }

/* ---------------------------------------------------------------------
   Sidebar: collapsible to an icon rail on desktop (remembered per browser).
   --------------------------------------------------------------------- */
.sdz-brand-mini { display: none; }
.sdz-collapse { display: none; }
.sdz-menu a { position: relative; }
.sdz-menu .lbl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 992px) {
  .sdz-collapse { display: inline-flex; }
  .sdz-sidebar { transition: width .2s ease, flex-basis .2s ease; }
  html[data-sidebar="collapsed"] .sdz-sidebar { width: var(--sdz-sidebar-w-mini); flex-basis: var(--sdz-sidebar-w-mini); overflow-x: hidden; }
  html[data-sidebar="collapsed"] .sdz-brand { justify-content: center; padding-left: 0; padding-right: 0; }
  html[data-sidebar="collapsed"] .sdz-brand-full,
  html[data-sidebar="collapsed"] .sdz-menu-search,
  html[data-sidebar="collapsed"] .sdz-menu .lbl { display: none; }
  html[data-sidebar="collapsed"] .sdz-brand-mini { display: grid; }
  html[data-sidebar="collapsed"] .sdz-menu { padding-left: .5rem; padding-right: .5rem; }
  html[data-sidebar="collapsed"] .sdz-menu a { justify-content: center; padding: .72rem 0; }
  html[data-sidebar="collapsed"] .sdz-menu .group { font-size: 0; padding: 0; margin: .5rem .4rem; border-top: 1px solid rgba(255,255,255,.12); }
  html[data-sidebar="collapsed"] .sdz-menu .count { position: absolute; top: 3px; right: 6px; margin: 0; font-size: .6rem; padding: 0 .38rem; line-height: 1.35; }
}

/* ---------------------------------------------------------------------
   Phone bottom navigation (pinned items + "More").
   --------------------------------------------------------------------- */
.sdz-bottomnav { display: none; }
@media (max-width: 991.98px) {
  body.has-bottomnav .sdz-content { padding-bottom: calc(var(--sdz-bottomnav-h) + var(--sdz-safe-b) + 1rem); }
  .sdz-bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035; display: flex;
    background: var(--sdz-surface); border-top: 1px solid var(--sdz-line);
    padding-bottom: var(--sdz-safe-b); box-shadow: 0 -6px 18px rgba(20,25,58,.08);
  }
  .sdz-bottomnav a, .sdz-bottomnav button {
    flex: 1 1 0; min-width: 0; height: var(--sdz-bottomnav-h); padding: 0 .25rem;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .12rem;
    background: none; border: 0; color: var(--sdz-muted); font-size: .68rem; font-weight: 600;
    text-decoration: none; position: relative; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  }
  .sdz-bottomnav i { font-size: 1.45rem; line-height: 1; }
  .sdz-bottomnav span.t { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sdz-bottomnav a.active { color: var(--sdz-link); }
  .sdz-bottomnav a.active::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--sdz-primary); }
  .sdz-bottomnav .is-primary i { width: 44px; height: 44px; margin-top: -16px; border-radius: 50%; display: grid; place-items: center; font-size: 1.55rem; background: var(--sdz-primary); color: #fff; box-shadow: 0 6px 14px rgba(79,70,229,.4); }
  .sdz-bottomnav .is-primary { color: var(--sdz-ink); }
  .sdz-bottomnav .count { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--sdz-accent); color: #14193a; border-radius: 999px; font-size: .62rem; font-weight: 800; padding: 0 .38rem; line-height: 1.35; }
  /* On the ticket page the sticky save bar replaces the bottom navigation. */
  body.ticket-entry .sdz-bottomnav { display: none; }
  body.ticket-entry.has-bottomnav .sdz-content { padding-bottom: calc(5.5rem + var(--sdz-safe-b)); }
}

/* ---------------------------------------------------------------------
   Page header, tables, density.
   --------------------------------------------------------------------- */
@media (max-width: 575.98px) {
  .sdz-crumb h1 { font-size: 1.2rem; }
  .sdz-crumb > div { width: 100%; }
  .sdz-crumb > div .btn { flex: 1 1 auto; }
}
.table--light > :not(caption) > * > * { padding-top: var(--sdz-cell-y); padding-bottom: var(--sdz-cell-y); }
.table--light tbody tr:hover > * { --bs-table-accent-bg: rgba(120,130,170,.08); }
tr[data-href] { cursor: pointer; }
.table--light tr.row-attention > :first-child { box-shadow: inset 4px 0 0 var(--sdz-warning); }

/* Phone layout: each row becomes a labelled card. Opt in with class table-stack and data-label on every <td>. */
@media (max-width: 767.98px) {
  .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { position: relative; padding: .7rem 1rem; border-bottom: 1px solid var(--sdz-line); }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack td { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: .22rem 0 !important; border: 0; text-align: right; box-shadow: none !important; }
  .table-stack td::before { content: attr(data-label); flex: 0 0 36%; text-align: left; color: var(--sdz-muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding-top: .2rem; }
  .table-stack td:not([data-label])::before { display: none; }
  .table-stack td[data-primary] { display: block; text-align: left; font-size: 1.02rem; padding-bottom: .35rem !important; padding-right: 2rem !important; }
  .table-stack td[data-primary]::before { display: none; }
  .table-stack td[data-select] { position: absolute; top: .7rem; right: 1rem; width: auto; padding: 0 !important; }
  .table-stack td[data-actions] { justify-content: flex-start; padding-top: .5rem !important; }
  .table-stack td[data-actions]::before { display: none; }
  .table-stack td[data-actions] > * { width: 100%; justify-content: flex-start !important; }
  .table-stack td[colspan] { display: block; text-align: center; }
  .table-stack td[colspan]::before { display: none; }
}

/* ---------------------------------------------------------------------
   Clickable stat cards and quick actions.
   --------------------------------------------------------------------- */
.stat-link { display: block; height: 100%; color: inherit; text-decoration: none; }
.stat-link:hover { color: inherit; }
.stat-link .stat-card { position: relative; transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; }
.stat-link:hover .stat-card, .stat-link:focus-visible .stat-card { transform: translateY(-2px); border-color: var(--sdz-primary); box-shadow: 0 8px 20px rgba(20,25,58,.12) !important; }
.stat-link .stat-card::after { content: "\f105"; font-family: "Line Awesome Free"; font-weight: 900; position: absolute; right: .9rem; top: 50%; transform: translateY(-50%); color: var(--sdz-muted); opacity: 0; transition: opacity .15s ease; }
.stat-link:hover .stat-card::after { opacity: 1; }
.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.quick-action { display: flex; align-items: center; gap: .7rem; min-height: 58px; padding: .8rem 1rem; background: var(--sdz-surface); color: var(--sdz-ink); border: 1px solid var(--sdz-line); border-radius: var(--sdz-radius); text-decoration: none; font-weight: 700; transition: border-color .15s ease, transform .15s ease; }
.quick-action i { font-size: 1.7rem; color: var(--sdz-link); }
.quick-action:hover { border-color: var(--sdz-primary); color: var(--sdz-ink); transform: translateY(-1px); }
.quick-action.is-primary { background: var(--sdz-primary); border-color: var(--sdz-primary); color: #fff; }
.quick-action.is-primary i { color: #fff; }
.quick-action .count { margin-left: auto; background: var(--sdz-accent); color: #14193a; border-radius: 999px; font-size: .72rem; font-weight: 800; padding: .1rem .55rem; }
kbd.hint { background: rgba(255,255,255,.22); color: inherit; border-radius: 5px; padding: 0 .35rem; font-size: .7rem; font-weight: 700; margin-left: .25rem; }
.bar-row { position: relative; }
.bar-row .bar { position: absolute; top: 0; bottom: 0; left: 0; background: rgba(79,70,229,.1); border-radius: 0 6px 6px 0; pointer-events: none; }
.bar-row > *:not(.bar) { position: relative; }

/* Live countdown to a draw closing */
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.countdown.is-soon { color: var(--sdz-warning); }
.countdown.is-urgent { color: var(--sdz-danger); animation: sdz-pulse 1.4s ease-in-out infinite; }
.countdown.is-closed { color: var(--sdz-muted); font-weight: 600; }
@keyframes sdz-pulse { 50% { opacity: .55; } }

/* Header closing clock (writers): next closing time counting down, with a list of every open game */
.cclock .cc-btn { display: inline-flex; align-items: center; gap: .4rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cclock .cc-btn .cc-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; font-weight: 600; opacity: .85; }
.cclock .cc-btn .cc-left { font-weight: 800; letter-spacing: .02em; }
.cclock .cc-btn.is-soon { color: var(--sdz-warning); border-color: var(--sdz-warning); }
.cclock .cc-btn.is-urgent { color: var(--sdz-danger); border-color: var(--sdz-danger); }
.cclock .cc-btn.is-urgent .cc-left { animation: sdz-pulse 1.4s ease-in-out infinite; }
.cclock .cc-btn.is-none { color: var(--sdz-muted); border-color: var(--sdz-line); }
:root[data-theme="dark"] .cclock .cc-btn.is-soon { color: #fbbf5a; border-color: #fbbf5a; }
:root[data-theme="dark"] .cclock .cc-btn.is-urgent { color: #fca5a5; border-color: #fca5a5; }
.cclock .dropdown-menu { min-width: min(290px, 92vw); padding: .35rem 0; }
.cclock .cc-item { padding: .5rem .9rem; border-bottom: 1px solid var(--sdz-line); }
.cclock .cc-item:last-of-type { border-bottom: 0; }
.cclock .cc-item.is-current { background: rgba(79,70,229,.12); box-shadow: inset 3px 0 0 var(--sdz-primary); }
.cclock .cc-item.is-closed { opacity: .5; }
.cclock .cc-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.cclock .cc-line { font-size: .78rem; line-height: 1.5; }
.cclock .cc-line i { color: var(--sdz-link); vertical-align: -1px; }
.cclock .cc-item .cc-left { font-variant-numeric: tabular-nums; font-weight: 800; white-space: nowrap; }

/* ---------------------------------------------------------------------
   Filters: preset chips, active-filter chips, collapsible on phones.
   --------------------------------------------------------------------- */
.chip-btn { min-height: 30px; padding: .15rem .75rem; background: transparent; color: var(--sdz-ink); border: 1px solid var(--sdz-line); border-radius: 999px; font-size: .78rem; font-weight: 600; touch-action: manipulation; }
.chip-btn:hover, .chip-btn.is-on { border-color: var(--sdz-primary); color: var(--sdz-link); background: rgba(79,70,229,.09); }
.filter-presets { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.filter-chips { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin: -.4rem 0 1rem; }
.filter-chips .chip { display: inline-flex; align-items: center; gap: .4rem; padding: .15rem .35rem .15rem .75rem; background: rgba(79,70,229,.11); color: var(--sdz-link); border: 0; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.filter-chips .chip .x { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: rgba(79,70,229,.2); line-height: 1; }
.filter-toggle { display: none; }
@media (max-width: 767.98px) {
  .filter-toggle { display: inline-flex; align-items: center; gap: .4rem; margin-bottom: .6rem; align-self: flex-start; }
  form[data-filter-form]:not(.is-open) .filter-extra,
  form[data-filter-form]:not(.is-open) .filter-presets { display: none; }
  form[data-filter-form].is-open .filter-toggle { margin-bottom: .75rem; }
}

/* ---------------------------------------------------------------------
   New Ticket page: typed entry, quick amounts, bigger touch targets, sticky save bar.
   --------------------------------------------------------------------- */
.qa-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .55rem; }
.num-grid button { touch-action: manipulation; transition: background-color .1s ease, transform .08s ease; }
.num-grid button:active:not(:disabled) { transform: scale(.92); }
@media (pointer: coarse) {
  .num-grid { gap: 6px; }
  .num-grid button { min-height: 40px; font-size: .95rem; }
}
.sdz-submitbar { display: none; }
@media (max-width: 991.98px) {
  body.ticket-entry .sdz-submitbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035; display: flex; align-items: center; gap: .75rem;
    padding: .6rem 1rem calc(.6rem + var(--sdz-safe-b)); background: var(--sdz-surface);
    border-top: 1px solid var(--sdz-line); box-shadow: 0 -6px 18px rgba(20,25,58,.12);
  }
  .sdz-submitbar .sum { flex: 1 1 auto; min-width: 0; line-height: 1.15; }
  .sdz-submitbar .sum small { display: block; color: var(--sdz-muted); font-size: .7rem; }
  .sdz-submitbar .sum strong { font-size: 1.2rem; font-weight: 900; }
  .sdz-submitbar .btn { flex: 0 0 auto; padding-left: 1.1rem; padding-right: 1.1rem; min-height: 46px; }
  body.submitbar-on #submitBtn { display: none; }
}

/* ---------------------------------------------------------------------
   Buttons that are busy (set by ux.js on form[data-once]).
   --------------------------------------------------------------------- */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; top: 50%; left: 50%; width: 1em; height: 1em; margin: -.5em 0 0 -.5em; border: 2px solid #fff; border-right-color: transparent; border-radius: 50%; animation: sdz-spin .6s linear infinite; }
.btn--outline--primary.is-loading::after { border-color: var(--sdz-primary); border-right-color: transparent; }
@keyframes sdz-spin { to { transform: rotate(360deg); } }

@media print { .sdz-bottomnav, .sdz-submitbar, .filter-presets, .filter-chips, .filter-toggle { display: none !important; } }
