/* Base responsive layer shared by administration and control screens. */
*, *::before, *::after { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
img, video, canvas, svg { max-width: 100%; }
button, input, select, textarea { max-width: 100%; }

@media (max-width: 767px) {
  body:has(.pwa-install-cta) { padding-bottom: 5rem; }
  .pwa-install-cta {
    right: 1rem !important;
    bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
    max-width: calc(100vw - 2rem);
    white-space: nowrap;
  }
}

/* Keep the administration header usable before the narrow mobile breakpoint. */
@media (max-width: 1200px) {
  .admin-header-inner {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    gap: .7rem !important;
    overflow: visible !important;
  }
  .admin-header-inner > .admin-header-brand,
  .admin-header-inner > .quick-links,
  .admin-header-inner > .admin-actions { min-width: 0; }
  .admin-header-inner > .quick-links { width: 100%; }
  .admin-header-inner > .admin-actions {
    width: 100%;
    margin-left: 0 !important;
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: .5rem;
  }
  .admin-header-inner .admin-greeting {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.2;
  }
}

/* Weekly summary: compact cards with total, first entry and last exit. */
@media (max-width: 767px) {
  .week-panel [x-html] {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem;
  }
  .week-panel [x-html] > .wk-card {
    width: 100% !important;
    min-width: 0;
    min-height: 126px;
  }
}

@media (max-width: 767px) {
  .admin-header-inner {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
    gap: .4rem !important;
    padding: .55rem .65rem !important;
    overflow: visible !important;
  }
  .admin-header-inner > .admin-header-brand {
    min-width: 0;
    width: 100%;
    justify-content: flex-start;
    gap: .65rem !important;
  }
  .admin-header-brand > .mobile-menu-toggle { order: -1; }
  .admin-header-brand .font-display { font-size: 1.12rem; line-height: 1.15; }
  .admin-header-inner > .quick-links {
    width: 100%;
  }
  .admin-header-inner > .admin-actions {
    width: 100%;
    margin-left: 0 !important;
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: .5rem;
  }
  .admin-header-inner .admin-greeting {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.2;
  }
  .admin-header-inner .admin-actions #themeToggle {
    white-space: nowrap;
    padding: .45rem .6rem;
    font-size: .85rem;
  }
  .admin-header-inner .admin-actions > a {
    white-space: nowrap;
    font-size: .9rem;
  }
  .admin-shell { display: block !important; padding: .75rem !important; }
  .admin-sidebar { margin-bottom: .85rem; }
  .admin-sidebar nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .25rem .5rem; padding: .75rem !important; }
  .admin-sidebar nav > .text-sm { grid-column: 1 / -1; margin-bottom: .1rem; }
  .admin-sidebar nav > .mt-6 { grid-column: 1 / -1; margin-top: .55rem !important; }
  .admin-sidebar nav a { min-height: 44px; padding: .55rem .65rem; font-size: .9rem; }
  .admin-sidebar nav a > span:first-child { width: 1.35rem; text-align: center; flex: 0 0 1.35rem; }
  .admin-main > .card-contrast, .admin-main section.card-contrast { padding: 1rem !important; }
  .admin-main .home-header { gap: .75rem; }
  .admin-main .home-header > div:last-child { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .admin-main .home-header > div:last-child .btn { width: 100%; }
  .admin-main .filters-registers-request input,
  .admin-main .filters-registers-request select,
  .admin-main .filters-registers-request textarea,
  .admin-main .filters-registers-request .buttonSendFiltersRegister { width: 100%; }
  .admin-main .tabbar { overflow-x: auto; flex-wrap: nowrap; padding-bottom: .35rem; scrollbar-width: thin; }
  .admin-main .tabbar .tab { flex: 0 0 auto; white-space: nowrap; }
  .table-shell, .admin-main .overflow-x-auto { max-width: 100%; -webkit-overflow-scrolling: touch; }
  .tbl-wide { min-width: 720px; }
  .admin-main .fc .fc-toolbar { flex-direction: column; align-items: stretch; gap: .45rem; }
  .admin-main .fc .fc-toolbar-chunk { display: flex; justify-content: center; flex-wrap: wrap; gap: .35rem; }
  .modal-panel, .admin-main [role="dialog"] > div { max-width: calc(100vw - 1rem) !important; max-height: calc(100dvh - 1rem) !important; }
  .admin-main [role="dialog"] > div { overflow-y: auto; padding: 1rem !important; }
  .quick-links { width: 100%; overflow-x: auto; padding-bottom: .15rem; }
  .quick-link { white-space: nowrap; }

  .kiosk-header-inner {
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    gap: .5rem !important;
  }
  .kiosk-header-inner > div:first-child {
    flex: 0 0 96px !important;
    min-width: 96px !important;
  }
  .kiosk-header-inner .kiosk-actions {
    width: auto !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    flex-wrap: nowrap !important;
    gap: .4rem !important;
  }
  .kiosk-header-inner .kiosk-actions .k-input {
    width: auto !important;
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }
  .kiosk-header-inner .kiosk-actions button {
    flex: 0 0 auto !important;
    min-height: 44px;
    padding-inline: .65rem !important;
  }
  .kiosk-main { padding: .75rem !important; }
  .kiosk-main .k-panel { padding: 1rem !important; }
  .kiosk-main .k-key { min-height: 48px; }
  .k-toast-fab { width: calc(100vw - 2rem); }
}

/* Dark mobile drawer: continuous navy surface instead of the light page panel. */
@media (max-width: 767px) {
  html.dark .admin-sidebar {
    background: #0b1220 !important;
    color: #f8fafc;
    box-shadow: 12px 0 30px rgba(0, 0, 0, .42);
  }

  html.dark .admin-sidebar nav,
  html.dark .admin-sidebar > .card-contrast {
    background: #111827 !important;
    border: 1px solid rgba(148, 163, 184, .16) !important;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .24);
  }

  html.dark .admin-sidebar nav a {
    color: #e5e7eb;
  }

  html.dark .admin-sidebar nav a.active {
    color: #f8fafc !important;
    background: rgba(140, 198, 63, .18) !important;
    box-shadow: inset 3px 0 0 #8cc63f;
  }

  html.dark .admin-sidebar nav a:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, .07);
  }

  html.dark .admin-sidebar .mobile-menu-close {
    background: #f8fafc;
    color: #0f172a;
    border-color: #cbd5e1;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
  }
}

@media (min-width: 768px) and (max-width: 1100px) {
  .admin-header-inner { flex-wrap: wrap; overflow: visible !important; }
  .admin-header-inner > .admin-actions { margin-left: auto !important; }
  .admin-shell { gap: 1rem !important; }
  .admin-sidebar { grid-column: span 4 / span 4 !important; }
  .admin-main { grid-column: span 8 / span 8 !important; min-width: 0; }
  .admin-sidebar nav { padding: .75rem !important; }
  .admin-sidebar nav a { font-size: .88rem; }
}

.mobile-menu-toggle,
.mobile-menu-close,
.mobile-menu-backdrop { display: none; }

.control-header-cta,
.control-dashboard-cta {
  background: #ffe000 !important;
  color: #111827 !important;
  border: 2px solid #f4c900;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(245, 190, 0, .28);
}

.control-header-cta:hover,
.control-dashboard-cta:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
}

.control-dashboard-cta { white-space: nowrap; }

.brand-mark {
  display: block;
  width: 78px !important;
  height: 36px !important;
  max-width: 78px !important;
  max-height: 36px !important;
  object-fit: contain !important;
  object-position: center;
  flex: 0 0 78px;
}

.admin-header-inner .admin-greeting {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.admin-header-inner .user-greeting-text { display: none !important; }

.admin-header-inner .user-brand-icon {
  display: block !important;
  width: 34px !important;
  height: 28px !important;
  max-width: 34px !important;
  max-height: 28px !important;
  object-fit: contain !important;
}

.kiosk-logo {
  display: block;
  width: 96px !important;
  height: 96px !important;
  max-width: 96px !important;
  max-height: 96px !important;
  object-fit: contain !important;
  object-position: center;
  flex: 0 0 96px;
}

.theme-icon-button {
  width: 48px !important;
  min-width: 48px !important;
  height: 44px;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  line-height: 1;
}

.theme-icon-button svg {
  width: 24px;
  height: 24px;
  display: block;
}

@media (min-width: 1201px) {
  .admin-header-inner {
    display: flex !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    overflow: visible !important;
    min-width: 0;
  }

  .admin-header-inner > .admin-header-brand {
    display: flex !important;
    align-items: center;
    flex: 0 1 auto;
    min-width: 0;
  }

  .admin-header-brand .font-display {
    white-space: nowrap;
    font-size: clamp(1rem, 1.45vw, 1.35rem);
  }

  .admin-header-inner > .quick-links {
    flex: 0 0 auto;
    width: auto;
  }

  .admin-header-inner > .admin-actions {
    flex: 0 0 auto;
    margin-left: auto !important;
    white-space: nowrap;
  }

  .admin-header-inner .admin-greeting {
    white-space: nowrap;
  }
}

@media (max-width: 767px) {
  .admin-header-brand {
    width: 100%;
    justify-content: space-between;
  }

  .mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 38px;
    flex: 0 0 42px;
    border: 1px solid var(--border, #dbe2ea);
    border-radius: .8rem;
    background: var(--surface-1, #fff);
    color: var(--text, #0f172a);
    font-size: 1.35rem;
    line-height: 1;
  }

  .mobile-menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(15, 23, 42, .48);
  }

  .admin-sidebar {
    display: block !important;
    position: fixed !important;
    inset: 0 auto 0 0;
    z-index: 80;
    width: min(88vw, 360px);
    max-width: 360px;
    margin: 0 !important;
    padding: .75rem;
    overflow-y: auto;
    background: var(--surface-0, #f8fafc);
    box-shadow: 12px 0 30px rgba(15, 23, 42, .18);
    transform: translateX(-105%);
    transition: transform .2s ease;
  }

  .admin-sidebar.mobile-menu-open { transform: translateX(0); }

  .mobile-menu-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: .75rem;
    right: .75rem;
    z-index: 2;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border, #dbe2ea);
    border-radius: 50%;
    background: var(--surface-1, #fff);
    color: var(--text, #0f172a);
    font-size: 1.6rem;
    line-height: 1;
  }

  .admin-sidebar nav {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: .25rem !important;
    padding: 3.5rem .65rem .75rem !important;
  }

  .admin-sidebar nav > .text-sm {
    display: block;
    font-size: 1.1rem;
    margin-bottom: .45rem;
  }

  .admin-sidebar nav > .mt-6 { margin-top: 1rem !important; }
  .admin-sidebar nav a { min-height: 48px; font-size: .98rem; }
  .admin-sidebar > .card-contrast { margin-top: .75rem !important; }

  .admin-main .home-header > div:last-child {
    grid-template-columns: 1fr 1fr;
  }
  .admin-main .home-header > div:last-child .control-dashboard-cta {
    grid-column: 1 / -1;
    width: 100%;
    text-align: center;
  }
}

/* Compact single-line administration header on responsive layouts. */
@media (max-width: 1200px) {
  .admin-header-inner {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: .45rem !important;
    padding: .5rem .65rem !important;
    min-width: 0;
  }

  .admin-header-inner > .admin-header-brand {
    display: flex !important;
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
    justify-content: flex-start;
    gap: .45rem !important;
  }

  .admin-header-brand .font-display {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(.92rem, 2.3vw, 1.25rem);
  }

  .admin-header-inner > .quick-links {
    flex: 0 0 auto;
    width: auto !important;
    overflow: visible;
  }

  .admin-header-inner .quick-link {
    padding: .45rem .7rem;
    font-size: .78rem;
    white-space: nowrap;
  }

  .admin-header-inner > .admin-actions {
    display: flex !important;
    flex: 0 0 auto;
    width: auto !important;
    margin-left: 0 !important;
    gap: .35rem;
  }

  .admin-header-inner .admin-actions #themeToggle {
    width: 40px;
    height: 38px;
    padding: 0;
    font-size: 0;
  }

  .admin-header-inner .theme-label { font-size: 0; }
  .admin-header-inner .theme-label:first-child::before {
    content: '🌙';
    font-size: 1.15rem;
  }
  .admin-header-inner .theme-label:nth-child(2)::before {
    content: '☀️';
    font-size: 1.15rem;
  }

  .admin-header-inner .admin-greeting {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    font-size: 1.1rem;
    opacity: 1;
  }

  .admin-header-inner .user-greeting-text { display: none; }
  .admin-header-inner .user-icon { display: inline-block; }
  .admin-header-inner .user-brand-icon {
    width: 34px;
    height: 28px;
    object-fit: contain;
  }
  .admin-header-inner .admin-actions > a { display: none; }
}
