/* ArticPulse Pro v1.0.1 — responsive para tablet y celular */

@media (max-width: 1050px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 50;
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 10px 16px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 28px rgba(0, 0, 0, .25);
  }

  .side-brand {
    margin: 0;
    min-height: 36px;
    white-space: nowrap;
  }

  .plant-badge,
  .side-foot {
    display: none;
  }

  .sidebar nav {
    display: flex;
    gap: 5px;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    padding-bottom: 2px;
  }

  .sidebar nav a {
    flex: 0 0 auto;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    padding: 9px 11px;
  }

  .sidebar nav a.active {
    box-shadow: inset 0 -3px 0 var(--cyan);
  }

  .content {
    max-width: none;
    padding: 22px 22px 42px;
  }

  .topbar {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .topbar > div:first-child {
    min-width: 0;
    flex: 1 1 360px;
  }

  .top-actions {
    flex: 1 1 auto;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

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

  .settings-grid,
  .license-grid,
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel-head {
    flex-wrap: wrap;
  }

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

@media (max-width: 820px) {
  .content {
    padding: 18px 16px 36px;
  }

  .topbar {
    gap: 14px;
    margin-bottom: 18px;
  }

  .topbar h1 {
    font-size: clamp(22px, 6vw, 27px);
    line-height: 1.12;
  }

  .topbar p {
    max-width: 60ch;
    line-height: 1.45;
  }

  .top-actions {
    display: flex !important;
    width: 100%;
    justify-content: flex-start;
    gap: 7px;
  }

  .top-actions .chip,
  .top-actions .btn {
    min-height: 40px;
  }

  .user-pill {
    min-height: 40px;
  }

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

  .panel {
    padding: 15px;
    border-radius: 13px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .panel-head .status {
    align-self: flex-start;
  }

  .legend {
    display: flex;
    flex-wrap: wrap;
  }

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

  .filter-grid {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-grid select:first-child {
    grid-column: 1 / -1;
  }

  .responsive-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .responsive-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tbody {
    padding: 8px;
  }

  .responsive-table tbody tr {
    margin: 0 0 10px;
    padding: 9px 11px;
    border: 1px solid #1a3852;
    border-radius: 12px;
    background: linear-gradient(180deg, #0a1c2e, #081725);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .13);
  }

  .responsive-table tbody tr:last-child {
    margin-bottom: 0;
  }

  .responsive-table td {
    min-height: 37px;
    padding: 8px 2px;
    display: grid;
    grid-template-columns: minmax(92px, 34%) minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #173049;
    overflow-wrap: anywhere;
  }

  .responsive-table td:last-child {
    border-bottom: 0;
  }

  .responsive-table td::before {
    color: #7892a8;
    font-size: 8px;
    font-weight: 900;
    letter-spacing: .65px;
    text-transform: uppercase;
  }

  .responsive-table td[colspan] {
    display: block;
    min-height: 0;
    text-align: center;
    border: 0;
  }

  .responsive-table td[colspan]::before {
    content: none;
  }

  .events-table td:nth-child(1)::before { content: "Fecha / hora"; }
  .events-table td:nth-child(2)::before { content: "Equipo"; }
  .events-table td:nth-child(3)::before { content: "Controlador"; }
  .events-table td:nth-child(4)::before { content: "Evento"; }
  .events-table td:nth-child(5)::before { content: "Severidad"; }
  .events-table td:nth-child(6)::before { content: "RSSI"; }

  .reefers-table td:nth-child(1)::before { content: "Unidad"; }
  .reefers-table td:nth-child(2)::before { content: "Controlador"; }
  .reefers-table td:nth-child(3)::before { content: "Ubicación"; }
  .reefers-table td:nth-child(4)::before { content: "Estado"; }
  .reefers-table td:nth-child(5)::before { content: "Wi-Fi"; }
  .reefers-table td:nth-child(6)::before { content: "Último reporte"; }
  .reefers-table td:nth-child(7)::before { content: "Telegram"; }
  .reefers-table td:nth-child(8)::before { content: "Acciones"; }

  .users-table td:nth-child(1)::before { content: "Nombre"; }
  .users-table td:nth-child(2)::before { content: "Usuario"; }
  .users-table td:nth-child(3)::before { content: "Rol"; }
  .users-table td:nth-child(4)::before { content: "Estado"; }
  .users-table td:nth-child(5)::before { content: "Último acceso"; }
  .users-table td:nth-child(6)::before { content: "Acciones"; }

  .table-actions {
    min-width: 0;
    width: 100%;
  }

  .table-actions .btn {
    min-height: 38px;
  }

  .form-row,
  .notify-toggle-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  input,
  select,
  .form-grid input,
  .form-grid select {
    min-height: 44px;
    font-size: 16px;
  }

  input[type="checkbox"] {
    min-height: 0;
    width: 20px !important;
    height: 20px;
  }

  .btn {
    min-height: 42px;
  }

  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-form .btn,
  .form-actions .btn,
  .test-form .btn {
    width: 100%;
  }

  .kv {
    grid-template-columns: minmax(105px, .75fr) minmax(0, 1.25fr);
  }

  .spark-chart {
    height: clamp(180px, 48vw, 230px);
  }
}

@media (max-width: 620px) {
  body:not(.login-body)::before {
    display: none;
  }

  .sidebar {
    padding: 9px max(10px, env(safe-area-inset-right)) 7px max(10px, env(safe-area-inset-left));
    display: block;
  }

  .side-brand {
    margin: 0 3px 7px;
  }

  .brand-fractal-wrap,
  .brand-fractal {
    width: 28px;
    height: 28px;
  }

  .sidebar nav {
    display: flex;
    grid-template-columns: none;
    padding-bottom: 3px;
  }

  .sidebar nav a {
    min-height: 38px;
    padding: 8px 10px;
    font-size: 11px;
  }

  .nav-icon {
    width: 17px;
  }

  .content {
    padding: 16px max(12px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .top-actions .chip {
    flex: 1 1 auto;
    text-align: center;
  }

  .top-actions .user-pill {
    flex: 1 1 100%;
    border-radius: 11px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .metric {
    min-width: 0;
    padding: 13px 11px;
    gap: 8px;
  }

  .metric-icon {
    display: none;
  }

  .metric span {
    font-size: 9px;
  }

  .metric strong {
    font-size: 24px;
  }

  .metric small {
    font-size: 8.5px;
    line-height: 1.3;
  }

  .health-strip {
    gap: 8px;
  }

  .health-strip > div {
    padding: 9px 10px;
  }

  .panel {
    padding: 13px;
  }

  .eq-top,
  .eq-footer {
    align-items: flex-start;
  }

  .eq-footer {
    flex-wrap: wrap;
  }

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

  .filter-grid select:first-child {
    grid-column: auto;
  }

  .filter-grid .btn {
    width: 100%;
  }

  .responsive-table tbody {
    padding: 6px;
  }

  .responsive-table tbody tr {
    padding: 8px 10px;
  }

  .responsive-table td {
    grid-template-columns: minmax(86px, 33%) minmax(0, 1fr);
  }

  .kv {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .login-body {
    display: block;
    min-height: 100dvh;
    overflow: auto;
    padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }

  .login-card {
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
    padding: 22px 18px;
    border-radius: 15px;
  }

  .login-fractal-stage {
    margin-bottom: 12px;
  }

  .login-fractal {
    width: 82px;
    height: 82px;
    border-radius: 21px;
  }

  .login-card .brand-lockup {
    margin-bottom: 16px;
  }
}

@media (max-width: 370px) {
  .side-brand span {
    font-size: 14px;
  }

  .metric-grid,
  .health-strip {
    grid-template-columns: minmax(0, 1fr);
  }

  .responsive-table td {
    display: block;
  }

  .responsive-table td::before {
    display: block;
    margin-bottom: 5px;
  }
}

/* Andon: conserva escritorio y cambia a lectura vertical bajo 900 px. */
@media (max-width: 900px) {
  html,
  body.andon-body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .andon-shell {
    height: auto;
    min-height: 100dvh;
  }

  .andon-header {
    grid-template-columns: minmax(0, 1fr);
    gap: 11px;
    padding: 12px 14px;
  }

  .andon-summary {
    grid-row: auto;
    grid-column: auto;
    width: 100%;
    justify-self: stretch;
  }

  .andon-summary > span {
    min-width: 0;
    flex: 1 1 25%;
    padding: 8px 5px;
  }

  .andon-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .andon-btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
  }

  .andon-health {
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 9px 14px;
  }

  .andon-page {
    width: 100%;
    margin-left: 0 !important;
  }

  .andon-board {
    display: block;
    padding: 0 14px;
  }

  .andon-table-head {
    display: none;
  }

  .andon-row {
    min-height: 0;
    grid-template-columns: 100px minmax(0, 1fr);
    gap: 8px 12px;
    padding: 12px 0;
  }

  .andon-row::before {
    left: -14px;
  }

  .andon-unit strong {
    font-size: 16px;
  }

  .andon-controller,
  .andon-rssi,
  .andon-report,
  .andon-telegram {
    grid-column: 2;
  }

  .andon-cell-label {
    display: inline;
    color: #6f879a;
    font-size: 8px;
    margin-right: 7px;
  }

  .andon-footer {
    padding: 9px 14px calc(9px + env(safe-area-inset-bottom));
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 540px) {
  .andon-header {
    padding-top: max(11px, env(safe-area-inset-top));
  }

  .andon-logo {
    width: 40px;
    height: 40px;
  }

  .andon-brand strong {
    font-size: 16px;
  }

  .andon-summary b {
    font-size: 19px;
  }

  .andon-clock {
    width: 100%;
  }

  .andon-actions .andon-btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .andon-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
  }

  .andon-state,
  .andon-unit,
  .andon-controller,
  .andon-rssi,
  .andon-report,
  .andon-telegram {
    grid-column: 1;
  }

  .andon-controller,
  .andon-rssi,
  .andon-report,
  .andon-telegram {
    padding-left: 15px;
  }
}
