/*
 * Responsive layer for tablets and phones.
 * Loaded last so it can override the desktop rules in the other files.
 * Breakpoints: 900px (slide-in menu), 700px (card tables, compact switcher), 600px (phones).
 */

html {
  -webkit-text-size-adjust: 100%;
}
body {
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button,
a,
.cb,
.cd,
.sk,
.svc {
  touch-action: manipulation;
}
.site {
  overflow-x: clip;
}
img,
svg,
canvas {
  max-width: 100%;
}

/* ---------- Prototype switcher ---------- */
.ctl .ctl-toggle {
  display: none;
}
:root {
  --ctl-h: 0px;
}

/* ---------- Navbar: slide-in menu on tablets and phones ---------- */
.nav-toggle,
.nav-ov,
.lk-head {
  display: none;
}
.brand > div {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .nav {
    gap: 12px;
  }
  .brand {
    flex: 1;
    min-width: 0;
  }
  .nav-toggle {
    display: grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.28);
  }
  .nav-ov {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
  }
  .nav.open {
    z-index: 100;
  } /* above the prototype switcher while the menu is open */
  .nav.open .nav-ov {
    opacity: 1;
    visibility: visible;
  }
  .lk {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 90;
    width: min(290px, 86vw);
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px calc(20px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, #0a2e0c 0%, #164e20 60%, #0d3d10 100%);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.35);
    transform: translateX(-105%);
    transition: transform 0.28s ease;
    visibility: hidden;
  }
  .nav.open .lk {
    transform: none;
    visibility: visible;
  }
  .lk-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.4rem 0.8rem;
    color: #a5d6a7;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .lk-close {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
  }
  .lk .nl {
    min-height: 48px;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    font-size: 1rem;
  }
  .lk .nl.o,
  .lk .nl.s {
    justify-content: center;
    margin-top: 8px;
  }
  body.menu-open {
    overflow: hidden;
  }
}

/* ---------- Tablets and phones: tables become card lists ---------- */
@media (max-width: 700px) {
  :root {
    --ctl-h: 46px;
  }
  .ctl {
    padding: 0;
    --ctl-h: 46px;
  }
  .ctl .ctl-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 46px;
    padding: 0 16px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #fff;
    font-size: 13px;
    text-align: left;
  }
  .ctl .ctl-toggle b {
    color: #4ade80;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .ctl .ctl-toggle span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #e2e8f0;
  }
  .ctl .ctl-toggle svg {
    transition: transform 0.2s;
  }
  .ctl.open .ctl-toggle svg {
    transform: rotate(180deg);
  }
  .ctl .in {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 70vh;
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 6px 14px 16px;
    background: #090d16;
    border-bottom: 3px solid #2e7d32;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
  }
  .ctl.open .in {
    display: flex;
  }
  .ctl .row b {
    display: none;
  }
  .ctl .in button {
    padding: 8px 15px;
    font-size: 13px;
  }

  .nav {
    position: sticky;
    top: var(--ctl-h);
    z-index: 40;
  }

  .dt thead {
    display: none;
  }
  .dt,
  .dt tbody,
  .dt tr,
  .dt td {
    display: block;
    width: 100%;
  }
  .dt tr {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  }
  .dt td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.4rem 0;
    border: 0;
    text-align: right;
  }
  .dt td[data-l]::before {
    content: attr(data-l);
    flex: none;
    text-align: left;
    color: #94a3b8;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .dt td:not([data-l]) {
    display: block;
    padding-top: 0.6rem;
  }
  .dt td:not([data-l]) .br {
    display: flex;
    justify-content: center;
    width: 100%;
    min-height: 44px;
  }
  .dt td[data-l='Actions'] {
    display: block;
    padding-top: 0.6rem;
    text-align: left;
  }
  .dt td[data-l='Actions']::before {
    display: block;
    margin-bottom: 6px;
  }
  .dt td[data-l='Actions'] .br {
    min-height: 40px;
    margin: 0 6px 6px 0;
  }
  .lc .lh {
    padding: 0.9rem 1rem;
  }
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  body {
    padding-bottom: 0;
  }
  input,
  select,
  textarea,
  .fc,
  .fcn {
    font-size: 16px;
  } /* stops iOS zoom on focus */
  .pgw {
    padding: 16px 14px 20px;
  }
  .h2 {
    font-size: 1.05rem;
  }
  .uc {
    padding: 16px;
  }
  .tp2 {
    flex-wrap: wrap;
  }
  .dr {
    flex-wrap: wrap;
  }
  .two {
    grid-template-columns: 1fr;
  }
  .cv {
    height: 220px;
  }
  .stats[style*='repeat(3'] {
    grid-template-columns: 1fr !important;
  }

  /* landing page */
  .hero {
    padding: 2.6rem 1.2rem 2.4rem;
    border-radius: 0 0 20px 20px;
  }
  .hero p {
    font-size: 0.95rem;
  }
  .hb {
    flex-direction: column;
  }
  .pill-l,
  .pill-o {
    width: 100%;
    min-height: 48px;
  }
  .sec {
    padding: 2rem 1rem;
  }
  .svc {
    padding: 1.05rem;
  }

  /* dashboards */
  .hr {
    padding: 1.1rem;
    border-radius: 16px;
  }
  .hr h3 {
    font-size: 1.1rem;
  }
  .av {
    width: 48px;
    height: 48px;
    font-size: 1.3rem;
    border-radius: 14px;
  }
  .sk {
    min-height: 100px;
    padding: 0.85rem;
  }
  .sk .v {
    font-size: 1.6rem;
  }
  .cb {
    min-height: 40px;
  }
  .vb,
  .btn {
    min-height: 50px;
  }
  .cta {
    min-height: 50px;
  }
  .btn.w {
    width: 100%;
  }

  /* sign in / register: full-screen sheet with a green header, like the real site */
  .auth {
    padding: 0;
    align-items: flex-start;
    background: #fff;
    min-height: calc(100vh - var(--ctl-h));
  }
  .ac,
  .ac.wd {
    max-width: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
    padding: 0 1.2rem 2rem;
  }
  .al {
    margin: 0 -1.2rem 1.4rem;
    padding: 2.2rem 1.2rem 1.8rem;
    border-radius: 0 0 26px 26px;
    background: linear-gradient(140deg, #1b5e20, #2e7d32);
  }
  .al h3,
  .al p,
  .al svg {
    color: #fff;
  }
  .al h3 {
    font-size: 1.35rem;
  }
  .otp {
    gap: 6px;
  }
  .otp input {
    width: 40px;
    height: 50px;
  }
  .alk {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  /* modals become bottom sheets */
  .ov {
    padding: 0;
    align-items: flex-end;
  }
  .md {
    max-width: none;
    max-height: 88vh;
    border-radius: 22px 22px 0 0;
    animation: sheet-up 0.25s ease;
  }
  .mf {
    flex-wrap: wrap;
    padding-bottom: calc(0.8rem + env(safe-area-inset-bottom, 0px));
  }
  .mf .bs {
    flex: 1;
    min-height: 44px;
  }
  .cq button {
    flex: 1 1 45%;
    height: 44px;
  }

  /* floating assistant button and footer */
  .cbt {
    width: 52px;
    height: 52px;
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  .fb {
    padding-bottom: calc(1.25rem + 60px);
  }
  .toast {
    bottom: calc(82px + env(safe-area-inset-bottom, 0px));
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* landscape phones and notches */
@media (max-width: 900px) and (orientation: landscape) {
  .hero {
    padding-top: 1.6rem;
    padding-bottom: 1.6rem;
  }
  .auth {
    align-items: flex-start;
  }
}
@supports (padding: max(0px)) {
  @media (max-width: 900px) {
    .nav,
    .pgw,
    .sec,
    .fg,
    .fb {
      padding-left: max(14px, env(safe-area-inset-left));
      padding-right: max(14px, env(safe-area-inset-right));
    }
  }
}
@media (prefers-reduced-motion: reduce) {
  .lk,
  .nav-ov,
  .md {
    transition: none;
    animation: none;
  }
}

@media (max-width: 600px) {
  .auth-logo {
    height: 84px;
    padding: 6px 10px;
    border-radius: 16px;
    background: #fff;
  }
  .hero-logo {
    height: 84px;
  }
}
