/*
  Kernex AppForge Mobile Responsive Layer
  Purpose:
  - Keep 8-screen workbench unchanged.
  - Reduce font sizes.
  - Improve mobile/tablet layout.
  - Prevent wide tables and fixed floating buttons from breaking mobile view.
*/

:root {
  --appforge-mobile-font-scale: 0.88;
  --appforge-mobile-radius: 14px;
  --appforge-mobile-gap: 10px;
}

/* Global font reduction */
html {
  font-size: 14px !important;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-size: 13px !important;
  line-height: 1.42 !important;
  overflow-x: hidden !important;
}

/* Reduce headings across all screens */
h1 { font-size: clamp(1.35rem, 4.5vw, 2.4rem) !important; line-height: 1.02 !important; }
h2 { font-size: clamp(1.45rem, 5.2vw, 2.75rem) !important; line-height: 1.02 !important; }
h3 { font-size: 0.96rem !important; }
h4 { font-size: 0.88rem !important; }

p,
li,
td,
th,
label,
input,
select,
textarea,
button,
a,
span,
div {
  font-size: 0.88rem;
}

small,
.pill,
.status,
.metric-label,
.nav-title {
  font-size: 0.72rem !important;
}

/* Reduce large KPI numbers */
.metric {
  font-size: clamp(1.35rem, 7vw, 2.2rem) !important;
  letter-spacing: -0.035em !important;
}

/* Reduce oversized hero sections */
.hero {
  padding: 16px !important;
  border-radius: 18px !important;
}

.hero h2,
.hero h1 {
  font-size: clamp(1.65rem, 7.5vw, 3rem) !important;
  line-height: 0.98 !important;
  letter-spacing: -0.045em !important;
}

.hero p {
  font-size: 0.86rem !important;
  line-height: 1.45 !important;
}

/* Reduce cards and controls */
.card {
  padding: 13px !important;
  border-radius: 16px !important;
}

button,
input,
select,
textarea {
  padding: 8px 10px !important;
  border-radius: 10px !important;
  min-height: 36px;
}

textarea {
  min-height: 110px !important;
}

/* Make grid layouts collapse gracefully */
.shell {
  max-width: 100vw !important;
  overflow-x: hidden !important;
}

main {
  min-width: 0 !important;
  max-width: 100vw !important;
}

.grid,
.layout,
.kpis,
.top,
.toolbar {
  min-width: 0 !important;
}

.table-wrap {
  max-width: 100% !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
}

table {
  font-size: 0.78rem !important;
}

th,
td {
  padding: 8px 9px !important;
}

/* Stabilize pre/json/log boxes */
.json,
.log,
pre,
code {
  font-size: 0.74rem !important;
  line-height: 1.35 !important;
  max-width: 100% !important;
  overflow-x: auto !important;
}

/* Left navigation/aside mobile behavior */
aside {
  overflow-x: hidden !important;
}

.nav-link {
  font-size: 0.82rem !important;
  padding: 8px 10px !important;
  border-radius: 11px !important;
}

.brand h1 {
  font-size: 0.95rem !important;
}

.brand p {
  font-size: 0.72rem !important;
}

.mark {
  width: 36px !important;
  height: 36px !important;
  border-radius: 13px !important;
}

/* Shared 8-screen app generator panel */
.stable8-panel {
  font-size: 0.78rem !important;
}

.stable8-panel input,
.stable8-panel select,
.stable8-panel textarea,
.stable8-panel button,
.stable8-link {
  font-size: 0.76rem !important;
}

.stable8-freeze {
  font-size: 0.72rem !important;
}

/* Floating links created by previous phases: make them less intrusive */
a[href="./write.html"][style*="position:fixed"],
a[href="./commit.html"][style*="position:fixed"],
a[href="./materialize.html"][style*="position:fixed"],
a[href="./relationships.html"][style*="position:fixed"],
a[href="./correction.html"][style*="position:fixed"],
a[href="./preview.html"][style*="position:fixed"],
a[href="./builder.html"][style*="position:fixed"] {
  font-size: 0.72rem !important;
  padding: 8px 10px !important;
  max-width: calc(100vw - 36px) !important;
  white-space: nowrap !important;
}

/* Tablet */
@media (max-width: 1180px) {
  html { font-size: 13.5px !important; }

  .shell {
    display: block !important;
  }

  aside {
    position: relative !important;
    top: auto !important;
    height: auto !important;
    max-height: none !important;
    width: 100% !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--line, rgba(120,190,255,.22)) !important;
    padding: 12px !important;
  }

  main {
    padding: 12px !important;
  }

  .top,
  .layout,
  .kpis {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .toolbar {
    justify-content: flex-start !important;
  }
}

/* Mobile */
@media (max-width: 760px) {
  html { font-size: 12.5px !important; }

  body {
    font-size: 12px !important;
  }

  main,
  aside {
    padding: 10px !important;
  }

  .hero {
    padding: 13px !important;
  }

  .hero h1,
  .hero h2 {
    font-size: clamp(1.45rem, 8.5vw, 2.15rem) !important;
  }

  .hero p {
    font-size: 0.8rem !important;
  }

  .card {
    padding: 11px !important;
  }

  .kpis {
    grid-template-columns: 1fr 1fr !important;
  }

  .metric {
    font-size: 1.45rem !important;
  }

  .metric-label {
    font-size: 0.68rem !important;
  }

  .brand {
    margin-bottom: 10px !important;
  }

  .nav-title {
    margin: 12px 0 6px !important;
  }

  .nav-link {
    padding: 7px 8px !important;
    margin-bottom: 4px !important;
  }

  label {
    font-size: 0.68rem !important;
  }

  input,
  select,
  textarea,
  button {
    font-size: 0.82rem !important;
    padding: 7px 9px !important;
    min-height: 34px !important;
  }

  table {
    min-width: 720px !important;
    font-size: 0.72rem !important;
  }

  th,
  td {
    padding: 7px 8px !important;
  }

  .status,
  .pill {
    font-size: 0.64rem !important;
    padding: 3px 6px !important;
  }

  .json {
    max-height: 340px !important;
    min-height: 180px !important;
  }

  .log {
    height: 210px !important;
  }

  /* Move freeze badge to bottom top-safe region */
  .stable8-freeze {
    top: auto !important;
    right: 10px !important;
    bottom: 10px !important;
    font-size: 0.66rem !important;
    padding: 6px 8px !important;
    opacity: 0.82;
  }

  /* Mobile generator panel becomes bottom sheet */
  .stable8-panel {
    left: 8px !important;
    right: 8px !important;
    bottom: 44px !important;
    width: auto !important;
    max-width: none !important;
    border-radius: 16px !important;
  }

  .stable8-head {
    padding: 9px 10px !important;
  }

  .stable8-body {
    padding: 10px !important;
  }

  .stable8-body textarea {
    min-height: 78px !important;
  }

  .stable8-actions {
    gap: 6px !important;
  }

  .stable8-actions button,
  .stable8-link {
    font-size: 0.68rem !important;
    padding: 7px 8px !important;
  }

  /* Previous floating screen links are too many on mobile; compress them */
  a[href="./write.html"][style*="position:fixed"],
  a[href="./commit.html"][style*="position:fixed"],
  a[href="./materialize.html"][style*="position:fixed"],
  a[href="./relationships.html"][style*="position:fixed"],
  a[href="./correction.html"][style*="position:fixed"],
  a[href="./preview.html"][style*="position:fixed"],
  a[href="./builder.html"][style*="position:fixed"] {
    right: 8px !important;
    left: auto !important;
    bottom: auto !important;
    top: auto !important;
    position: static !important;
    display: inline-flex !important;
    margin: 4px 4px 4px 0 !important;
    font-size: 0.66rem !important;
    padding: 6px 8px !important;
    box-shadow: none !important;
  }

  /* Make inserted fixed links appear within document flow if present */
  body > a[style*="position:fixed"] {
    position: static !important;
    display: inline-flex !important;
    margin: 4px 4px 4px 10px !important;
    transform: none !important;
  }
}

/* Small mobile */
@media (max-width: 430px) {
  html { font-size: 12px !important; }

  .kpis {
    grid-template-columns: 1fr !important;
  }

  .hero h1,
  .hero h2 {
    font-size: 1.55rem !important;
  }

  .metric {
    font-size: 1.35rem !important;
  }

  table {
    min-width: 680px !important;
  }

  .toolbar {
    gap: 6px !important;
  }

  .toolbar button,
  .toolbar select,
  .toolbar input {
    width: 100%;
  }
}
