/* =====================================================================
   SDZ responsive layer. Loaded LAST on every page (public site, auth pages, writer, player, manager and super admin),
   so it only adds to sdz.css, ux.css and the page styles. Presentation only: no data, route or permission changes.
   Breakpoints follow Bootstrap: xs < 576, sm >= 576, md >= 768, lg >= 992.
   ===================================================================== */

/* ---------- Safety net: nothing may push the page sideways ---------- */
body { overflow-x: clip; overflow-wrap: break-word; }
img, video { max-width: 100%; height: auto; }
canvas, svg { max-width: 100%; }
pre { white-space: pre-wrap; word-break: break-word; max-width: 100%; }
code, kbd { overflow-wrap: anywhere; }
.sdz-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.sdz-scroll > table { margin-bottom: 0; }
.dropdown-menu { max-width: calc(100vw - 1rem); }
.select2-container { max-width: 100%; }
.pagination { flex-wrap: wrap; justify-content: center; row-gap: .25rem; }
.card-header { flex-wrap: wrap; }
.table-stack td { overflow-wrap: anywhere; }
.modal-dialog { margin-left: auto; margin-right: auto; }
.modal-body { overflow-wrap: anywhere; }
.list-group-item.d-flex { flex-wrap: wrap; gap: .25rem .75rem; }
.stat-card > div:last-child { min-width: 0; }

/* Phone browsers: the sidebar and shell follow the visible screen, not the one behind the address bar. */
.sdz-shell { min-height: 100vh; min-height: 100dvh; }
.sdz-menu { padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px)); }

/* Touch screens: 16px fields stop iOS zooming in on focus, and buttons are easier to hit. */
@media (pointer: coarse) {
  .form-control, .form-select, .select2-container .select2-selection { font-size: 16px; }
  .btn--sm { min-height: 40px; padding-left: .8rem; padding-right: .8rem; }
  .page-link { min-width: 40px; min-height: 40px; display: inline-grid; place-items: center; }
  .dropdown-item { padding-top: .6rem; padding-bottom: .6rem; }
}

/* ---------- Public top bar (home, results, sign-up pages) ---------- */
.pub-nav { background: var(--sdz-surface); border-bottom: 1px solid var(--sdz-line); position: sticky; top: 0; z-index: 1030; padding-top: .4rem; padding-bottom: .4rem; }
.pub-nav .navbar-brand { margin-right: .75rem; display: inline-flex; align-items: center; color: var(--sdz-ink); }
.pub-links { display: flex; align-items: center; gap: .5rem; }
.pub-nav .btn { white-space: nowrap; }
.pub-toggle { width: 40px; height: 40px; min-height: 40px; padding: 0; display: inline-grid; place-items: center; font-size: 1.4rem; }
@media (max-width: 767.98px) {
  .pub-nav .navbar-collapse { flex-basis: 100%; }
  .pub-links { flex-direction: column; align-items: stretch; padding: .75rem 0 .35rem; gap: .5rem; }
  .pub-links .btn { width: 100%; min-height: 46px; display: flex; align-items: center; justify-content: center; font-size: .95rem; }
}

/* ---------- Home page ---------- */
/* Slides share one height, so the page below never jumps while the hero changes. */
.hero-carousel .carousel-inner { display: grid; }
.hero-carousel .carousel-item { display: block; grid-area: 1 / 1; float: none; margin: 0; width: 100%; visibility: hidden; pointer-events: none; }
.hero-carousel .carousel-item.active,
.hero-carousel .carousel-item-next,
.hero-carousel .carousel-item-prev { visibility: visible; pointer-events: auto; }

.home-hero h1 { font-size: clamp(2rem, 7vw, 3rem); }
.home-hero h2 { font-size: clamp(1.6rem, 5.5vw, 2.5rem); }
.demo-panel { background: linear-gradient(135deg, var(--sdz-side), #272f6b); border-radius: var(--sdz-radius); padding: 1rem .5rem .75rem; }

@media (max-width: 991.98px) {
  .home-hero { padding-bottom: 3.25rem; }
  .hero-art { max-width: 300px; }
}
@media (max-width: 575.98px) {
  .home-hero { padding: 1.6rem 0 2.9rem; }
  .home-hero .lead { font-size: 1rem; }
  .hero-chip { font-size: .72rem; }
  .hero-copy .btn-lg { flex: 1 1 100%; padding: .7rem 1rem; font-size: 1rem; }
  .hero-copy .age-badge { margin-left: auto; }
  .hero-copy .hero-latest { padding: .75rem; }
  .hero-controls { margin-top: 1.1rem; }
  .hero-controls .carousel-indicators [data-bs-target] { width: 20px; margin-right: 3px; }
  .hero-controls .carousel-indicators .active { width: 34px; }
  .hc-btn, .tc-btn { width: 38px; height: 38px; min-height: 38px; }
  .hero-wave { height: 40px; }
  .fb { opacity: .12; transform-origin: center; }
  .home-section { padding-top: 1.7rem; }
  .home-section h2 { font-size: 1.1rem; }
  .home-stats { margin-top: -1.2rem; }
  .stat-tile { padding: .75rem .25rem; }
  .stat-tile i { font-size: 1.3rem; }
  .stat-tile .num { font-size: 1.35rem; }
  .stat-tile .lbl { font-size: .7rem; }
  .open-chip { flex-wrap: wrap; }
  .open-chip .countdown { flex: 0 0 100%; display: flex; justify-content: space-between; align-items: baseline; padding-top: .5rem; border-top: 1px dashed var(--sdz-line); }
  .result-card .card-body > .d-flex:first-child { flex-wrap: wrap; gap: .15rem .75rem; }
  .step-num { right: -1rem; }
  .shuffler .balls { gap: .4rem; }
  .shuffler .ball { width: clamp(38px, 12.5vw, 52px); height: clamp(38px, 12.5vw, 52px); font-size: 1rem; }
  .shuffler .btn { width: 100%; }
  .testi-card { padding: 1.75rem 1.1rem 1.25rem; }
  .testi-card blockquote { font-size: 1rem; }
  .cta-card .btn { flex: 1 1 100%; }
  .play-safe { padding: .75rem .9rem; }
  .to-top { right: .75rem; }
}
@media (max-width: 359.98px) {
  .home-hero h1 { font-size: 1.75rem; }
  .stat-tile .num { font-size: 1.2rem; }
}
/* Landscape phones: short screens get a tighter hero. */
@media (max-height: 480px) and (orientation: landscape) {
  .home-hero { padding: 1.25rem 0 2.5rem; }
  .pub-nav { position: static; }
}

/* ---------- Portal top bar (writer, player, manager, super admin) ---------- */
@media (max-width: 575.98px) {
  .sdz-topbar { gap: .4rem; padding: .45rem .65rem; }
  .sdz-topbar .btn--sm { min-width: 38px; min-height: 38px; padding-left: .5rem; padding-right: .5rem; }
  .sdz-topbar .dropdown > .btn { max-width: 7.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cclock .cc-btn .cc-name { display: none; }
  .cclock .cc-btn { padding-left: .5rem; padding-right: .5rem; font-size: .78rem; }
  /* The closing-times list opens as a full-width sheet under the top bar, so it can never run off the screen edge. */
  .cclock .dropdown-menu {
    position: fixed !important; top: 3.6rem !important; left: .5rem !important; right: .5rem !important; bottom: auto !important;
    transform: none !important; width: auto; min-width: 0; max-width: none; max-height: calc(100dvh - 8rem); overflow-y: auto;
  }
  .sdz-content { padding: .75rem; }
  .sdz-crumb h1 { overflow-wrap: anywhere; }
  .stat-card { padding: .8rem .85rem; gap: .7rem; }
  .stat-icon { width: 40px; height: 40px; flex-basis: 40px; font-size: 1.3rem; }
  .stat-card .figure { font-size: 1.15rem; overflow-wrap: anywhere; }
  .card-body { padding: .9rem; }
  .card-body.p-4 { padding: 1.1rem !important; }
  .card-body > .d-flex.justify-content-between:not(.flex-nowrap) { flex-wrap: wrap; gap: .5rem; }
  .btn-group { flex-wrap: wrap; }
  .modal-dialog { margin: .5rem; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer > .btn { flex: 1 1 auto; }
}
/* Two stat cards side by side on a small phone: icon above the figure, so a long amount is never squeezed. */
@media (max-width: 420px) {
  .col-6 .stat-card { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .col-6 .stat-card .stat-icon { width: 36px; height: 36px; flex-basis: 36px; font-size: 1.2rem; }
  .col-6 .stat-card .figure { font-size: 1.05rem; }
}
@media (max-width: 991.98px) {
  .sdz-sidebar { width: min(300px, 86vw); max-width: 86vw; height: 100vh; height: 100dvh; }
  .sdz-topbar .dropdown-menu { min-width: min(260px, 92vw); }
}

/* ---------- Ticket entry (writers and players): number grid sized for small screens ---------- */
@media (max-width: 380px) {
  .num-grid { grid-template-columns: repeat(7, 1fr); gap: 5px; }
}
@media (pointer: coarse) and (max-width: 380px) {
  .num-grid button { min-height: 0; }
}

/* ---------- Auth pages (sign in, register, two-factor) ---------- */
@media (max-width: 575.98px) {
  .auth-wrap { padding: .75rem; }
  .auth-card { padding: 1.25rem; }
}
@media (max-height: 640px) {
  .auth-wrap { place-items: start center; }
}

/* ---------- Tables that cannot stack still scroll sideways inside their own box ---------- */
@media (max-width: 767.98px) {
  .table:not(.table-stack) th, .table:not(.table-stack) td { white-space: nowrap; }
  .table:not(.table-stack) td.text-wrap, .table:not(.table-stack) td[style*="white-space"] { white-space: normal; }
}

@media print { .pub-nav, .mobile-cta, .to-top, .scroll-bar { display: none !important; } }

/* =====================================================================
   Manager portal on phones and tablets. Presentation only: no data, route or permission changes.
   Rules marked (all portals) are generic fixes; the rest are scoped to body[data-portal="manager"].
   ===================================================================== */

/* (all portals) Fields in two-column filter rows may shrink below their default width (date pickers on small iPhones). */
.sdz-content .row > [class*="col"] > .form-control,
.sdz-content .row > [class*="col"] > .form-select { min-width: 0; max-width: 100%; }
input[type="date"].form-control, input[type="time"].form-control { min-width: 0; }

/* (all portals) Notches and rounded screen corners: bars and content stay clear of the side insets (matters in landscape). */
@supports (padding: max(0px)) {
  @media (max-width: 991.98px) {
    .sdz-topbar  { padding-left: max(.65rem, env(safe-area-inset-left, 0px)); padding-right: max(.65rem, env(safe-area-inset-right, 0px)); }
    .sdz-content { padding-left: max(.9rem, env(safe-area-inset-left, 0px)); padding-right: max(.9rem, env(safe-area-inset-right, 0px)); }
    .sdz-bottomnav { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
  }
  @media (max-width: 575.98px) {
    .sdz-content { padding-left: max(.75rem, env(safe-area-inset-left, 0px)); padding-right: max(.75rem, env(safe-area-inset-right, 0px)); }
  }
}

/* (all portals) Landscape phones are short: a slimmer bottom bar and a top bar that scrolls away, so content gets the height. */
@media (max-height: 480px) and (orientation: landscape) and (max-width: 991.98px) {
  :root { --sdz-bottomnav-h: 46px; }
  .sdz-topbar { position: static; }
  .sdz-bottomnav a, .sdz-bottomnav button { flex-direction: row; gap: .4rem; }
  .sdz-bottomnav i { font-size: 1.25rem; }
  .sdz-bottomnav .count { position: static; }
  .sdz-bottomnav .is-primary i { margin-top: 0; width: 32px; height: 32px; font-size: 1.2rem; box-shadow: none; }
}

/* (all portals) Pop-up forms on phones: the body scrolls inside the screen and the buttons stay in reach. */
@media (max-width: 575.98px) {
  .modal-dialog { max-width: none; }
  .modal-dialog-centered { min-height: calc(100% - 1rem); }
  .modal-content { max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); }
  .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
}

/* (all portals) Long text boxes and detail toggles inside stacked table cards never run wider than the card. */
.table-stack pre { max-width: 100% !important; }
.table-stack details > summary { min-height: 36px; display: inline-flex; align-items: center; }

/* Dashboard shortcuts: two per row on a phone, so the figures below are not pushed off the first screen. */
@media (max-width: 575.98px) {
  body[data-portal="manager"] .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  body[data-portal="manager"] .quick-action { min-width: 0; min-height: 54px; padding: .55rem .7rem; gap: .5rem; font-size: .85rem; line-height: 1.2; }
  body[data-portal="manager"] .quick-action i { font-size: 1.4rem; flex: 0 0 auto; }
  body[data-portal="manager"] .quick-action:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* Status tabs (Payouts): one swipeable row instead of wrapping onto several lines. */
@media (max-width: 767.98px) {
  body[data-portal="manager"] .nav-pills { flex-wrap: nowrap; overflow-x: auto; gap: .35rem; padding-bottom: .35rem; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  body[data-portal="manager"] .nav-pills::-webkit-scrollbar { display: none; }
  body[data-portal="manager"] .nav-pills .nav-item { flex: 0 0 auto; }
  body[data-portal="manager"] .nav-pills .nav-link { white-space: nowrap; min-height: 40px; display: flex; align-items: center; gap: .3rem; }
}

/* Tables become compact cards on a phone: each value sits under its small label, in as many columns as fit
   (one column on very narrow screens). The name or ticket stays on top, and the buttons get the full width below. */
@media (max-width: 767.98px) {
  body[data-portal="manager"] .table-stack tbody tr,
  body[data-portal="manager"] .table-stack tfoot tr {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); column-gap: 1rem; row-gap: .5rem; align-items: start;
  }
  body[data-portal="manager"] .table-stack td { text-align: left !important; }
  body[data-portal="manager"] .table-stack td[data-label] { display: flex; flex-direction: column; justify-content: flex-start; gap: .1rem; padding: 0 !important; min-width: 0; }
  body[data-portal="manager"] .table-stack td[data-label]::before { flex: 0 0 auto; padding-top: 0; font-size: .68rem; }
  body[data-portal="manager"] .table-stack td[data-primary],
  body[data-portal="manager"] .table-stack td[data-actions],
  body[data-portal="manager"] .table-stack td[colspan] { grid-column: 1 / -1; }
  body[data-portal="manager"] .table-stack td[data-empty] { display: none; }
  body[data-portal="manager"] .table-stack td[data-actions] { padding-top: .25rem !important; }
  /* Payout approval: the reference box and the button each take the full width. */
  body[data-portal="manager"] .table-stack td[data-actions] form.d-flex { flex-wrap: wrap; justify-content: stretch !important; }
  body[data-portal="manager"] .table-stack td[data-actions] form .form-control { max-width: none !important; flex: 1 1 100%; }
  body[data-portal="manager"] .table-stack td[data-actions] form .btn { flex: 1 1 100%; }
  body[data-portal="manager"] .table-stack td[data-actions] .btn { min-height: 44px; }
}
