/* ==========================================================================
 * FILE: wfm-responsive.css
 * Project AEGIS — Phase 3A Gateway Sidebar Isolation & WFM Auto-Responsive UI
 * Complete & Untruncated
 * ========================================================================== */

/* 1. STRICT [hidden] & GATEWAY SIDEBAR ISOLATION */
[hidden],
.shell[hidden],
#appShell[hidden],
#publicSite[hidden],
.view[hidden],
#liveSessionMonitor[hidden] {
  display: none !important;
}

body.aegis-gateway-mode #appShell,
body.aegis-gateway-mode #mainSidebarNav,
body.aegis-gateway-mode #btnWfmDrawerToggle,
body.aegis-gateway-mode #btnWfmMobileMenu,
body.aegis-gateway-mode #wfmDrawerBackdrop {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* 2. GLOBAL VIEWPORT & SAFE-AREA CONTAINMENT */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  max-width: 100vw;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

img,
svg,
canvas,
video,
iframe {
  max-width: 100%;
}

/* 3. SAFETY BANNER & STICKY TOPBAR */
.safety {
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px 16px !important;
  line-height: 1.45 !important;
  word-break: break-word;
}

.topbar {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  flex-wrap: wrap !important;
  gap: 10px 14px !important;
  padding: 12px 18px !important;
  position: sticky;
  top: 0;
  z-index: 1040;
  width: 100%;
}

.wfm-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.wfm-drawer-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 10px !important;
  background: rgba(56, 189, 248, 0.1) !important;
  border: 1px solid rgba(56, 189, 248, 0.35) !important;
  color: #38bdf8 !important;
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0 !important;
}

#userLabel {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.76rem;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 5px 10px;
  border-radius: 8px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 4. GATEWAY PUBLIC CONTAINER (#publicSite) */
#publicSite.public {
  width: calc(100% - 28px) !important;
  max-width: 1120px !important;
  margin: 24px auto !important;
  padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 28px) !important;
}

#publicSite.public h1 {
  font-size: clamp(1.75rem, 5.2vw, 2.8rem) !important;
  line-height: 1.15 !important;
}

#publicFeatures.grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)) !important;
  gap: 16px !important;
}

/* 5. DESKTOP WFM SHELL (> 1024px) */
#appShell:not([hidden]) {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  align-items: start;
  width: 100%;
  max-width: 100vw;
  min-height: calc(100dvh - 110px);
}

#mainSidebarNav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

#mainSidebarNav button {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 8px !important;
  width: 100% !important;
  text-align: left !important;
  min-height: 42px;
}

.wfm-drawer-mobile-head {
  display: none;
}

#wfmDrawerBackdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1190;
}

#wfmDrawerBackdrop.active {
  display: block;
}

/* 6. WFM MAIN WORKSPACE, GRIDS, CARDS & VISUAL TELEMETRY BARS */
#content {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: clamp(14px, 2.5vw, 26px);
  padding-bottom: calc(36px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  outline: none;
}

.panel-head {
  display: flex !important;
  justify-content: space-between !important;
  align-items: flex-start !important;
  flex-wrap: wrap !important;
  gap: 12px 16px !important;
  padding: clamp(14px, 2.2vw, 18px) clamp(14px, 2.5vw, 22px) !important;
}

.panel-head h2 {
  font-size: clamp(1.15rem, 3.4vw, 1.45rem) !important;
  line-height: 1.25 !important;
  margin: 0 0 4px 0 !important;
}

.grid-4 {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 14px !important;
}

.grid-2,
.grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 16px !important;
}

.card,
.kpi-card,
.filter-bar {
  min-width: 0 !important;
  max-width: 100% !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kpi-val {
  font-size: clamp(1.2rem, 2.6vw, 1.65rem) !important;
  line-height: 1.2 !important;
}

/* Auto-scaling WFM Telemetry Graphs Strip */
.wfm-telemetry-graphs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.wfm-graph-box {
  background: rgba(15, 16, 21, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 14px;
  padding: 14px 16px;
  min-width: 0;
}

.wfm-graph-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.wfm-graph-track {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.wfm-graph-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

.wfm-graph-sub {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 6px;
}

/* 7. FILTER BARS, FORMS & CONTROLS */
.filter-bar {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 165px), 1fr)) !important;
  gap: 12px !important;
  align-items: end !important;
  margin-bottom: 18px !important;
}

.filter-bar > div,
.row > div {
  min-width: 0;
}

.filter-bar input,
.filter-bar select,
#wfmModal input,
#wfmModal select,
#wfmModal textarea,
#authModal input {
  width: 100%;
  max-width: 100%;
  min-height: 40px;
}

/* 8. OPERATIONAL CALENDAR (.cal-grid) */
.cal-grid {
  display: grid !important;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.cal-day {
  background: #11131a;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px;
  min-height: 92px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cal-day-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  color: #94a3b8;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 4px;
}

.cal-event {
  font-size: 0.72rem;
  line-height: 1.3;
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.14);
  color: #e0f2fe;
  word-break: break-word;
  white-space: normal;
}

/* 9. SCROLLABLE TABLES & DIALOG MODALS */
.scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
}

dialog#authModal {
  width: min(94vw, 430px) !important;
  max-width: 94vw !important;
  max-height: calc(100dvh - 32px) !important;
  overflow-y: auto !important;
  margin: auto !important;
  padding: 22px !important;
}

dialog#wfmModal {
  width: min(95vw, 780px) !important;
  max-width: 95vw !important;
  max-height: calc(100dvh - 28px) !important;
  overflow-y: auto !important;
  margin: auto !important;
  padding: 18px !important;
}

/* ==========================================================================
 * 10. TABLET & MOBILE DRAWER BREAKPOINT (<= 1024px)
 * ========================================================================== */
@media (max-width: 1024px) {
  body.aegis-wfm-mode .wfm-drawer-toggle {
    display: inline-flex !important;
  }

  #appShell:not([hidden]) {
    display: block !important;
    width: 100% !important;
  }

  #mainSidebarNav {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(300px, 85vw) !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    z-index: 1200 !important;
    transform: translateX(-105%) !important;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    padding: calc(16px + env(safe-area-inset-top, 0px)) 14px calc(28px + env(safe-area-inset-bottom, 0px)) 14px !important;
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.85) !important;
  }

  body.aegis-wfm-drawer-open #mainSidebarNav {
    transform: translateX(0) !important;
  }

  .wfm-drawer-mobile-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 6px 12px 6px;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .cal-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ==========================================================================
 * 11. MOBILE PHONE APPLICATION FIT & TABLE-TO-CARD REFLOW (<= 768px)
 * ========================================================================== */
@media (max-width: 768px) {
  /* Prevent iOS WebKit input zoom & ensure touch-friendly targets */
  input,
  select,
  textarea,
  button {
    font-size: 16px !important;
  }

  .btn-sm,
  #mainSidebarNav button {
    font-size: 0.84rem !important;
    min-height: 38px;
  }

  .brand {
    font-size: 1.15rem !important;
    line-height: 1.2;
  }

  .brand small {
    display: block !important;
    margin-left: 0 !important;
    font-size: 0.7rem !important;
    margin-top: 2px;
  }

  #userLabel {
    max-width: 100%;
    width: 100%;
    order: 4;
    text-align: center;
  }

  #liveSessionMonitor {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 10px 14px !important;
    gap: 8px !important;
  }

  #liveSessionMonitor button {
    width: 100%;
  }

  .grid-2,
  .grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px !important;
  }

  .card,
  .kpi-card,
  .filter-bar {
    padding: 14px !important;
    border-radius: 14px !important;
  }

  /* Constrain any inline-width controls inside panel headers */
  .panel-head > div,
  #wfmReportActionsBar > div,
  #wfmRosterActionsBar > div,
  #wfmCalendarControls > div,
  #wfmFinancialActionsBar > div,
  #wfmHolidayActionsBar > div {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  #selReportType,
  #selReportPeriod,
  #inpRosterDate,
  #inpCalBaseDate {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100%;
  }

  /* Mobile stacked card reflow for all WFM & Modal data tables */
  .scroll {
    overflow-x: visible;
  }

  .scroll table,
  .scroll thead,
  .scroll tbody,
  .scroll th,
  .scroll td,
  .scroll tr {
    display: block !important;
    width: 100% !important;
  }

  .scroll table {
    background: transparent !important;
    border: none !important;
  }

  .scroll thead {
    display: none !important;
  }

  .scroll tbody tr {
    background: #11131a !important;
    border: 1px solid rgba(56, 189, 248, 0.18) !important;
    border-radius: 14px !important;
    margin-bottom: 12px !important;
    padding: 6px 0 !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  }

  .scroll tbody td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 9px 14px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.05) !important;
    text-align: right !important;
    font-size: 0.84rem !important;
  }

  .scroll tbody td:first-child {
    border-top: none !important;
  }

  .scroll tbody td::before {
    content: attr(data-label);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #94a3b8;
    text-align: left;
    flex: 0 0 38%;
    max-width: 42%;
    padding-top: 2px;
  }

  .scroll tbody td[colspan]::before {
    display: none !important;
  }

  .cal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cal-grid:has(> .cal-day:only-child) {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* 12. COMPACT PHONE PORTRAIT (<= 400px) */
@media (max-width: 400px) {
  .grid-4 {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
/* ===================== Release 4.4.1: gateway sign-in page sized for phones ===================== */
@media (max-width: 640px) {
  .safety { font-size: 0.68rem !important; line-height: 1.35 !important; padding: calc(4px + env(safe-area-inset-top, 0px)) 12px 4px !important; }
  .topbar { padding: 8px 12px !important; }
  .topbar .brand { font-size: 1rem !important; }
  .topbar button.primary { padding: 8px 14px !important; font-size: 0.9rem !important; }
  .public { padding: 16px 14px !important; }
  #publicSite.public h1 { font-size: 1.45rem !important; line-height: 1.2 !important; }
  #publicSite.public { margin: 12px auto !important; padding: 16px 14px !important; }
  .public > p, .public .card p { font-size: 0.9rem !important; line-height: 1.5 !important; }
  .public .notice { font-size: 0.8rem !important; padding: 10px 12px !important; }
  .public .card { padding: 14px !important; }
  .public .card h3 { font-size: 1rem !important; }
  .public .grid { gap: 10px !important; }
}

/* WFM -> Platform Admin -> AEGIS Miles (4.6) */
#wfmMilesContent .wm-form { display: grid; gap: 8px; margin-top: 10px; }
#wfmMilesContent .wm-form label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; }
#wfmMilesContent .wm-form label.wm-check { flex-direction: row; align-items: center; gap: 8px; }
#wfmMilesContent .wm-inline { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
#wfmMilesContent tr.wm-sel td { background: rgba(56,189,248,.08); }
#wfmMilesContent .wm-list { margin: 0; padding-left: 18px; font-size: .88rem; }
.wm-qr-overlay { position: fixed; inset: 0; z-index: 9000; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; padding: 16px; }
.wm-qr { background: #fff; color: #111; border-radius: 14px; padding: 18px; width: min(340px, 100%); text-align: center; }
.wm-qr svg { width: 100%; height: auto; } .wm-qr code { font-size: 1rem; }

/* ===================== Release 4.8 (iPhone screenshots, 22 Nov): compact WFM on phones ===================== */
/* nothing scrolls underneath the clock / Dynamic Island in the iPhone app */
body::before { content: ''; position: fixed; left: 0; right: 0; top: 0; height: env(safe-area-inset-top, 0px); background: #0a0b0f; z-index: 5000; pointer-events: none; }
@media (max-width: 768px) {
  /* header: brand + buttons on one row; one "Main Portal" button, not two */
  .topbar { display: flex !important; flex-wrap: wrap !important; align-items: center !important; gap: 6px 8px !important; padding: 6px 10px !important; }
  .topbar .brand { font-size: 0.98rem !important; flex: 1 1 auto; min-width: 0; }
  .topbar .brand small { font-size: 0.62rem !important; }
  .topbar button { padding: 6px 10px !important; font-size: 0.8rem !important; min-height: 34px; }
  #userLabel { display: none !important; }
  #liveSessionMonitor { padding: 5px 10px !important; gap: 4px !important; font-size: 0.7rem !important; }
  #liveSessionMonitor > div:last-child { display: none !important; }
  #liveSessionMonitor span { font-size: 0.7rem !important; line-height: 1.35; }
  .wfm-mobile-drawer-bar { padding: 6px 10px !important; gap: 8px !important; }
  .wfm-native-drawer-btn { padding: 6px 14px !important; font-size: 0.85rem !important; min-height: 36px; }
  .wfm-drawer-hint { display: none !important; }

  /* headings and cards sized for a phone */
  .shell h2, #appShell h2 { font-size: 1.1rem !important; line-height: 1.25 !important; }
  #appShell h3 { font-size: 0.98rem !important; }
  #appShell .meta, #appShell p { font-size: 0.82rem !important; }
  #appShell .card { padding: 12px !important; }

  /* number boxes: two per row, compact */
  #appShell .grid-4, #appShell .grid-3, #appShell .kpi-grid { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  #appShell .kpi-card { padding: 10px !important; border-radius: 12px !important; }
  #appShell .kpi-label { font-size: 0.6rem !important; letter-spacing: 0.02em !important; line-height: 1.3; }
  #appShell .kpi-val { font-size: 1.1rem !important; margin-top: 2px !important; }
  #appShell .kpi-sub { font-size: 0.68rem !important; }

  /* filters: two per row */
  #appShell .filter-bar { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; }
  #appShell .filter-bar > * { min-width: 0; }
  #appShell .filter-bar label { font-size: 0.72rem !important; }

  /* calendar: empty days are short */
  .cal-day { min-height: 54px !important; padding: 7px !important; gap: 3px !important; }
  .cal-day-head { font-size: 0.72rem !important; }
  .cal-event { font-size: 0.7rem !important; }

  /* table cards (roster, attendance…): values wrap inside the card instead of running off the screen */
  .scroll { overflow-x: hidden !important; }
  .scroll tbody td { white-space: normal !important; overflow-wrap: anywhere; word-break: break-word; min-width: 0; font-size: 0.8rem !important; padding: 7px 12px !important; }
  .scroll tbody td > * { min-width: 0; max-width: 100%; }
  .scroll tbody td::before { flex: 0 0 36% !important; max-width: 36% !important; font-size: 0.6rem !important; }
  .scroll tbody td:empty::after, .scroll tbody td:has(> :only-child:empty) { content: '—'; }
}
@media (max-width: 768px) { .scroll table, #appShell .scroll table { min-width: 0 !important; width: 100% !important; } }
@media (max-width: 768px) {
  .scroll tbody td { display: grid !important; grid-template-columns: 36% minmax(0, 1fr) !important; gap: 2px 10px !important; column-gap: 10px !important; row-gap: 2px !important; align-items: start !important; text-align: right !important; }
  .scroll tbody td::before { grid-column: 1; grid-row: 1 / span 6; max-width: none !important; }
  .scroll tbody td > * { grid-column: 2; }
  .scroll tbody td[colspan] { display: block !important; text-align: center !important; }
}

/* v4.11 WFM: Vozqa Shop orders */
.wfm-shop-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.wfm-shop-order { padding: 0 !important; margin-bottom: 8px; overflow: hidden; }
.wfm-shop-row { width: 100%; display: grid; grid-template-columns: 1.1fr 1.3fr auto; gap: 10px; align-items: center; text-align: left; background: none; border: 0; color: inherit; padding: 12px 14px; cursor: pointer; font: inherit; }
.wfm-shop-order.open .wfm-shop-row { border-bottom: 1px solid rgba(255,255,255,.08); }
.wfm-shop-detail { padding: 12px 14px 14px; }
.wfm-shop-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.wfm-shop-ship { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.wfm-shop-ship select, .wfm-shop-ship input { padding: 6px 8px; min-height: 34px; }
@media (max-width: 640px) { .wfm-shop-row { grid-template-columns: 1fr 1fr; } .wfm-shop-row > span:last-child { grid-column: 1 / -1; } }
