/*
 * Setup mobile foundation
 * This sheet is deliberately loaded last. It turns the desktop console into a
 * compact operational surface instead of trying to squeeze its columns into a
 * phone viewport. It contains layout-only overrides: no action, endpoint or
 * permission behaviour lives here.
 */

@media (max-width: 980px) {
  html, body { max-width: 100%; overflow-x: clip; }
  .app-shell, .workspace, .workspace-section, .ops-workspace { min-width: 0; }
  .workspace { width: 100%; padding: 18px 16px 42px; }

  /* The drawer must always sit above cards, but never above a confirmation. */
  .rail { z-index: 240; }
  .sidebar-overlay { z-index: 230; }
  .modal { z-index: 300; }
  .profile-menu { z-index: 260; }

  .ws-topbar { margin-bottom: 18px; }
  .ops-header-actions, .data-panel-head > div:last-child, .panel-head > div:last-child {
    max-width: 100%;
  }
  .ops-table-wrap { -webkit-overflow-scrolling: touch; }
  .ops-table { min-width: 620px; }
}

@media (max-width: 700px) {
  .workspace { padding: 12px 12px 34px; }

  /* App bar: one clear line for navigation/context and one for tools. */
  .ws-topbar {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    grid-template-areas: "menu heading profile" "tools tools tools";
    gap: 11px 10px;
    margin: 0 0 18px;
    padding: 11px;
    border: 1px solid rgba(125, 211, 252, .16);
    border-radius: 18px;
    background: linear-gradient(145deg, #172b40, #0b1526);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 18px 36px -29px rgba(34, 211, 238, .82);
  }
  .btn-menu-mobile { grid-area: menu; width: 44px; height: 44px; }
  .ws-topbar .topbar-heading { grid-area: heading; min-width: 0; }
  .ws-topbar .topbar-heading .eyebrow {
    overflow: hidden;
    margin-bottom: 3px;
    color: #82dfea;
    font-size: 8px;
    letter-spacing: .095em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .ws-topbar h1 { overflow: hidden; font-size: 21px; text-overflow: ellipsis; white-space: nowrap; }
  .ws-topbar .topbar-context { grid-area: profile; justify-content: flex-end; min-width: 0; margin: 0 !important; padding: 0 !important; border: 0 !important; background: none !important; }
  .profile-context .user-chip { gap: 0; padding: 4px; border-color: rgba(34, 211, 238, .38); border-radius: 13px; background: linear-gradient(145deg, rgba(34, 211, 238, .16), rgba(15, 23, 42, .82)); }
  .profile-context .user-meta, .profile-context .profile-chevron { display: none; }
  .profile-context .user-chip .user-avatar { width: 34px; height: 34px; border-radius: 10px; }
  .ws-topbar .user { grid-area: tools; display: flex; width: 100%; min-height: 0; margin: 0 !important; padding: 10px 0 0 !important; border: 0 !important; border-top: 1px solid rgba(148, 163, 184, .14) !important; justify-content: flex-end; }
  .ws-topbar .user #updated-at { display: none; }
  .ws-topbar .refresh-btn { width: 42px; min-width: 42px; height: 40px; border-radius: 12px; }
  body.profile-menu-open::after {
    content: "";
    position: fixed;
    z-index: 250;
    inset: 0;
    background: rgba(2, 7, 16, .72);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
  }
  .profile-menu {
    position: fixed;
    z-index: 270;
    top: auto;
    right: 12px !important;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px !important;
    min-width: 0;
    max-height: min(360px, calc(100dvh - 104px));
    overflow-y: auto;
    border-color: rgba(103, 232, 249, .34);
    border-radius: 22px;
    background: linear-gradient(155deg, #1a2a3e, #0b1322 72%) !important;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    box-shadow: 0 28px 70px -22px rgba(0, 0, 0, .96), inset 0 1px 0 rgba(255, 255, 255, .13), 0 0 0 1px rgba(34, 211, 238, .08);
  }
  .profile-menu::before { content: ""; display: block; width: 40px; height: 4px; margin: -3px auto 13px; border-radius: 99px; background: rgba(148, 163, 184, .5); }
  .profile-menu-kicker { color: #8eeaf6; }
  .profile-menu > b { color: #f5fbff; }
  .profile-menu > small { color: #aec0d4; }
  .profile-menu-actions { border-top-color: rgba(148, 163, 184, .2); }
  .profile-action { min-height: 42px; color: #d6e4f1; }
  .profile-menu .btn-logout { min-height: 42px; }

  /* Overview: readable metric cards, no compressed desktop columns. */
  #workspace-overview > .intro { gap: 12px; margin: 2px 2px 16px; }
  #workspace-overview > .intro h2 { font-size: clamp(27px, 9vw, 35px); line-height: 1.05; }
  #workspace-overview > .intro p { font-size: 14px; line-height: 1.55; }
  #workspace-overview .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  #workspace-overview .kpi { min-height: 138px; padding: 14px; border-radius: 16px; }
  #workspace-overview .kpi-value { font-size: 29px; }
  #workspace-overview .kpi-trend { display: none; }
  #workspace-overview .grid, .grid-access { gap: 12px; margin-top: 12px; }
  .panel-head, .data-panel-head, .ops-header { align-items: flex-start; gap: 10px; }
  .panel-head, .data-panel-head { flex-wrap: wrap; }
  .panel-head > *, .data-panel-head > *, .ops-header > * { min-width: 0; }
  .panel-head h3, .data-panel-title h3, .ops-header h3 { font-size: 16px; }
  .panel-head span, .data-panel-head > div > span { line-height: 1.35; }

  /* Deploys keep their hierarchy, but every target and CTA gets full room. */
  #repositories.repo-groups { gap: 14px; padding: 10px 10px 14px; }
  .deploy-group { padding: 11px; border-radius: 16px; }
  .deploy-group-head { align-items: flex-start; gap: 9px; }
  .deploy-group-head h4 { font-size: 16px; }
  .grp-chips { width: 100%; margin-left: 0; justify-content: flex-start; overflow-x: auto; padding-bottom: 1px; }
  .grp-chip { white-space: nowrap; }
  .repo-grid { gap: 9px; }
  .repository { padding: 13px; border-radius: 14px; }
  .repo-head { align-items: stretch; flex-direction: column; gap: 12px; }
  .repo-actions { width: 100%; flex-direction: row; align-items: center; justify-content: space-between; }
  .repo-actions .btn { min-height: 38px; padding: 8px 11px; }
  .repo-trace { align-items: flex-start; }
  .repo-trace b { line-height: 1.35; }
  .repo-sub { line-height: 1.65; }
  .auto-tag-flow, .manual-tag { margin-top: 3px; }
  .details { padding: 13px; font-size: 12px; overflow-wrap: anywhere; }
  .details code { overflow-wrap: anywhere; }
  .details-actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .details-actions .btn, .details-actions .transport-btn { width: 100%; min-height: 43px; justify-content: center; }
  .restore-hint { line-height: 1.45; }

  /* Operational screens use vertical actions; tables retain a deliberate swipe rail. */
  .ops-workspace { gap: 12px; margin-top: 0; }
  .ops-card, .data-panel, .glass-panel { padding: 14px; border-radius: 17px; }
  .ops-header-actions { width: 100%; flex-wrap: wrap; }
  .ops-header-actions .btn { flex: 1 1 150px; min-height: 40px; justify-content: center; }
  .ops-kpi-grid { gap: 9px; }
  .ops-table-wrap { position: relative; margin: 0 -2px; border-radius: 12px; }
  .ops-table-wrap::after { content: "Deslizá para ver más"; position: sticky; left: 0; display: block; width: max-content; margin: 0 0 7px 10px; color: #75ddea; font-size: 9px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
  .ops-table th, .ops-table td { padding: 10px 12px; }
  .maintenance-coverage { padding: 11px; }
  .maintenance-flow { display: none; }
  .maintenance-session-grid { padding: 12px; }
  .maint-actions-row { align-items: stretch; }
  .maint-actions-row .btn { width: 100%; min-height: 43px; }
  .cal-layout { gap: 13px; }
  .cal { min-width: 0; }
  .bk-groups { grid-template-columns: 1fr; }
  .bk-summary { align-items: flex-start; flex-direction: column; }
  .bk-summary > .btn { width: 100%; }
  .alert-command-center { padding: 15px; border-radius: 17px; }
  .alert-center-actions { width: 100%; }
  .alert-center-actions .btn { margin-left: auto; }
  .alert-active-item { align-items: start; }
  .alert-active-index { grid-column: 2; justify-self: start; }

  /* Utilities and forms: large targets, no side-by-side controls below 700px. */
  #workspace-utilities .ops-card { padding: 14px; }
  .util-command-deck { padding: 14px; border-radius: 16px; }
  .util-command-head { gap: 10px; }
  .util-controls, .util-head { width: 100%; flex-wrap: wrap; }
  .util-controls .search-field, .util-controls .gsel, .util-controls .btn { flex: 1 1 100%; width: 100%; }
  .util-logs-disclosure summary, .util-config-disclosure summary { min-height: 78px; padding: 14px; }
  .util-disclosure-state { flex: 0 0 auto; }
  .util-logs-content, .util-config-content { padding: 13px; }

  /* Dialogs must fit the visible mobile viewport, including browser UI. */
  .modal { align-items: end; padding: 8px; }
  .modal-card, .profile-modal-card { width: 100%; max-height: calc(100dvh - 16px); border-radius: 20px 20px 16px 16px; }
  .modal-body { max-height: calc(100dvh - 220px); overflow-y: auto; overscroll-behavior: contain; }
  .modal-header { padding: 17px 16px 14px; }
  .modal-body { padding: 16px; }
  .modal-footer { position: sticky; bottom: 0; padding: 12px 16px max(16px, env(safe-area-inset-bottom)); background: rgba(11, 18, 31, .96); }
  .modal-footer .btn { min-height: 42px; }
  .profile-details > div { align-items: flex-start; flex-direction: column; gap: 3px; }
  .profile-details b { max-width: 100%; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .profile-verified { margin-left: 0; }
}

@media (max-width: 430px) {
  .workspace { padding-right: 10px; padding-left: 10px; }
  .ws-topbar { grid-template-columns: 42px minmax(0, 1fr) 42px; padding: 9px; }
  .btn-menu-mobile { width: 42px; height: 42px; }
  .ws-topbar h1 { font-size: 20px; }
  .ws-topbar .topbar-heading .eyebrow { display: none; }
  #workspace-overview .kpis { grid-template-columns: 1fr; }
  #workspace-overview .kpi { min-height: 126px; }
  .repo-actions { align-items: stretch; flex-direction: column; }
  .repo-actions .pill { align-self: flex-start; }
  .repo-actions .btn { width: 100%; justify-content: center; }
  .ops-header-actions .btn { flex-basis: 100%; }
  .dr-toolkit, .dr-tool-card, .channel-card, .alert-pref-box { padding: 13px; }
  .deployment-live { align-items: flex-start; line-height: 1.4; }
}

@media (prefers-reduced-motion: reduce) {
  .rail, .sidebar-overlay, .modal-card, .repository, .dmeter-track i { animation: none !important; transition: none !important; }
}
