/* TSKEY — mobile / responsive layer (v1.2) */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Outer bundler shell — DO NOT vertically center (causes huge black gap on mobile) */
html, body {
  overflow-x: hidden;
}
body {
  display: block !important;
  align-items: unset !important;
  justify-content: unset !important;
  min-height: 100vh !important;
  padding-top: 0 !important; /* chrome sets its own offset via JS; media queries refine */
}

/* Bundler thumbnail / loading should not reserve space after hydrate */
#__bundler_thumbnail,
#__bundler_loading {
  pointer-events: none;
}

/* —— Global chrome —— */
#cortina-global-header {
  padding: 10px 12px 8px !important;
}
.cortina-infinity-heading {
  font-size: clamp(12px, 3.4vw, 16px) !important;
  padding: 0 4px;
}
#cortina-global-header .ci-subrow {
  gap: 8px !important;
}
#cortina-global-header a {
  white-space: nowrap;
}

#tskey-upgrade-badge {
  max-width: calc(100vw - 28px);
  font-size: 10px !important;
  padding: 8px 10px !important;
}

#tskey-env-banner {
  font-size: 10px !important;
  letter-spacing: 0.1em !important;
  padding: 5px 8px !important;
}

/* —— Industrial pages —— */
.ind-wrap {
  padding-left: 14px !important;
  padding-right: 14px !important;
}
.ind-card {
  padding: 14px 12px 10px !important;
  border-radius: 14px !important;
}
.ind-table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.ind-table thead,
.ind-table tbody,
.ind-table tr {
  display: table;
  width: 100%;
  table-layout: auto;
}
.ind-actions {
  flex-direction: column;
  align-items: stretch;
}
.ind-actions .ind-btn,
.ind-actions .ind-select {
  width: 100%;
  box-sizing: border-box;
}
.ind-grid {
  grid-template-columns: 1fr 1fr !important;
}

/* —— Login / index —— */
@media (max-width: 640px) {
  body {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
  .wrap {
    max-width: 100% !important;
  }
  .clock-panel {
    gap: 18px !important;
    padding: 20px 14px !important;
  }
  .analog {
    width: 110px !important;
    height: 110px !important;
  }
  .panel {
    padding: 18px 14px !important;
    border-radius: 14px !important;
  }
  h1 {
    font-size: clamp(22px, 7vw, 32px) !important;
  }
  #upgrade-note {
    left: 10px !important;
    right: 10px !important;
    max-width: none !important;
    bottom: 10px !important;
    font-size: 13px !important;
  }
}

/* —— Milestone bundled app — 100% mobile usable —— */
@media (max-width: 900px) {
  x-dc, [data-dc-root] {
    display: block !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }

  x-dc h1, [data-dc-root] h1, x-dc h1 * {
    font-size: clamp(22px, 6vw, 32px) !important;
    line-height: 1.15 !important;
  }
  x-dc h2, [data-dc-root] h2 {
    font-size: clamp(18px, 5vw, 24px) !important;
  }

  /* Root dashboard column */
  x-dc div[style*="max-width:1320px"],
  [data-dc-root] div[style*="max-width:1320px"] {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 8px 12px 96px !important;
    box-sizing: border-box !important;
    gap: 16px !important;
  }

  /* MAIN FIX: sidebar+main grid → single column stack */
  x-dc div[style*="minmax(290px"],
  x-dc div[style*="minmax(290px,330px)"],
  [data-dc-root] div[style*="minmax(290px"] {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: 1fr !important;
    gap: 14px !important;
    width: 100% !important;
    align-items: stretch !important;
  }

  /* Sticky ring card → normal flow */
  x-dc div[style*="position:sticky"],
  [data-dc-root] div[style*="position:sticky"] {
    position: relative !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Stream cards grid */
  x-dc div[style*="minmax(320px"],
  [data-dc-root] div[style*="minmax(320px"] {
    grid-template-columns: 1fr !important;
    width: 100% !important;
    gap: 12px !important;
  }

  /* Burn-up 3-col row */
  x-dc div[style*="200px 1fr 92px"],
  [data-dc-root] div[style*="200px 1fr 92px"] {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    width: 100% !important;
  }

  x-dc div[style*="display:flex"],
  [data-dc-root] div[style*="display:flex"] {
    flex-wrap: wrap !important;
    max-width: 100% !important;
  }

  x-dc div[style*="min-width:300px"],
  [data-dc-root] div[style*="min-width:300px"] {
    min-width: 0 !important;
    width: 100% !important;
  }

  /* Milestone nav pills */
  x-dc a[href^="/m"],
  [data-dc-root] a[href^="/m"],
  x-dc [data-m-nav] a,
  [data-dc-root] [data-m-nav] a {
    padding: 7px 11px !important;
    font-size: 12px !important;
  }

  /* Drawers full-bleed */
  x-dc div[style*="position:fixed"],
  [data-dc-root] div[style*="position:fixed"] {
    left: 0 !important;
    right: 0 !important;
    max-width: 100vw !important;
    width: 100% !important;
  }

  /* Graph behind content so it never masks dashboard */
  #tskey-bg-graph {
    z-index: 0 !important;
    opacity: 0.35 !important;
  }
}

@media (max-width: 640px) {
  /* Compact chrome — kill empty black band */
  #cortina-global-header {
    padding: 6px 10px 6px !important;
  }
  .cortina-infinity-heading {
    font-size: 11px !important;
    line-height: 1.3 !important;
  }
  #cortina-global-header .ci-subrow {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 6px !important;
    margin-top: 6px !important;
  }
  #cortina-global-header .ci-subrow > div {
    width: auto;
    max-width: 100%;
  }
  #cortina-global-header a,
  #tskey-role-chip,
  #tskey-request-chip {
    font-size: 10px !important;
    padding: 5px 8px !important;
  }
  #tskey-logout {
    width: auto;
    min-height: 34px !important;
    padding: 6px 10px !important;
    font-size: 11px !important;
  }
  #tskey-live {
    font-size: 10px !important;
  }

  /* JS also sets padding; force a tighter mobile offset */
  body.tskey-has-chrome {
    padding-top: 108px !important;
  }
  body.tskey-has-chrome.tskey-has-incident {
    padding-top: 140px !important;
  }

  .ind-grid {
    grid-template-columns: 1fr !important;
  }
  .ind-wrap {
    padding-top: 120px !important;
  }

  #tskey-upgrade-badge {
    display: none !important; /* free vertical space on phones */
  }

  /* SVG rings scale down */
  x-dc svg,
  [data-dc-root] svg {
    max-width: 100% !important;
    height: auto !important;
  }

  /* Week dial / range inputs */
  x-dc input[type="range"],
  [data-dc-root] input[type="range"] {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Soften huge padding on hero panels */
  x-dc div[style*="padding:28px"],
  x-dc div[style*="padding: 28px"],
  [data-dc-root] div[style*="padding:28px"] {
    padding: 16px 12px !important;
  }
}

@media (max-width: 400px) {
  .cortina-infinity-heading .ci-managed {
    display: inline;
  }
  #cortina-global-header {
    padding: 8px 8px 6px !important;
  }
}

/* Touch targets */
@media (pointer: coarse) {
  #cortina-global-header a,
  .ind-btn,
  #tskey-logout {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .ind-check {
    width: 22px !important;
    height: 22px !important;
  }
}


/* DESKTOP RESTORE milestone 2-col */
@media (min-width: 901px) {
  x-dc div[data-m-grid="main"],
  [data-dc-root] div[data-m-grid="main"] {
    grid-template-columns: minmax(290px, 330px) 1fr !important;
    display: grid !important;
  }
}
