/* Mantencion CTO | Mobile presentation layer. Desktop styles are unchanged. */
.cto-mobile-menu-bar,
.cto-mobile-agenda,
.cto-mobile-calendar-switch,
.cto-mobile-scroll-hint { display: none; }

@media screen and (max-width: 767px) {
  html, body { width: 100%; max-width: 100%; overflow-x: clip; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { min-width: 0 !important; }
  body > header {
    height: auto !important;
    min-height: 74px !important;
    width: 100% !important;
    padding: 12px 14px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  body > header > .brand {
    display: flex !important;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    align-items: center !important;
    justify-content: flex-start;
    gap: 10px !important;
  }
  body > header > .brand img, body > header .brand-logo-header {
    width: 108px !important;
    height: 47px !important;
    flex: 0 0 108px;
    object-fit: contain;
  }
  body > header .brand > div { min-width: 0; }
  body > header .brand h1 { font-size: 18px !important; line-height: 1.24 !important; }
  body > header .brand p { font-size: 11px !important; line-height: 1.35 !important; }
  body > header > div:last-child:not(.brand) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border-top: 1px solid #eef2f7;
    padding-top: 9px;
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px !important;
    text-align: left !important;
  }
  body > header > div:last-child:not(.brand) > div {
    min-width: 0;
    overflow-wrap: anywhere;
    flex: 1 1 155px;
  }
  body > header a[href="/logout/"] {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }
  /* Safe fallback if scripts are blocked: the original menu remains accessible. */
  body > nav {
    flex-wrap: wrap !important;
    gap: 0 !important;
    padding: 4px 8px !important;
    max-width: 100%;
  }
  body > nav a { padding: 12px 13px !important; font-size: 13px !important; }
  body.cto-mobile-ready > nav.cto-mobile-nav:not(.is-open) { display: none !important; }
  body.cto-mobile-ready > nav.cto-mobile-nav.is-open {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0 !important;
    padding: 5px 12px 12px !important;
    box-shadow: 0 7px 14px rgba(15,44,80,.08);
  }
  body.cto-mobile-ready > nav.cto-mobile-nav.is-open a {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 12px 13px !important;
    border-bottom: 1px solid #edf2f8 !important;
    border-radius: 7px;
  }
  body.cto-mobile-ready > nav.cto-mobile-nav.is-open a.active {
    background: #edf5ff;
    color: #0873e8;
    border-left: 3px solid #0873e8;
  }
  body.cto-mobile-ready > .cto-mobile-menu-bar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 1px solid #e0e7f0;
    background: white;
    color: #536985;
  }
  .cto-mobile-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 1px solid #d2e0f1;
    border-radius: 10px;
    background: #edf5ff;
    color: #082a63;
    padding: 9px 14px;
    min-height: 44px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
  }
  .cto-mobile-menu-section { font-size: 12px; font-weight: 700; text-align: right; }
  body > main, main {
    max-width: 100% !important;
    min-width: 0;
    padding: 19px 13px 38px !important;
  }
  .navegacion-principal { padding-left: 12px !important; padding-right: 12px !important; }
  .title-row, .top-row, .table-head, .table-header,
  .page-head, .heading-row, .panel-header {
    flex-wrap: wrap !important;
    gap: 12px !important;
    min-width: 0;
  }
  .title h2, .title-row h2, main > h1, main h1 {
    font-size: clamp(25px, 7vw, 31px) !important;
    line-height: 1.16;
    overflow-wrap: break-word;
  }
  .title-row, .top-row { align-items: flex-start !important; }
  .subtitle { font-size: 13px !important; line-height: 1.55; }
  .eyebrow { font-size: 11px !important; letter-spacing: 1px !important; }
  .panel, .card, .search-card, .table-panel, .section,
  .status, .filters, .warning, .login-side {
    max-width: 100%;
    min-width: 0 !important;
    overflow-wrap: break-word;
  }
  .panel, .search-card, .table-panel, .section { padding: 17px 14px !important; }
  .dashboard-grid, .layout, .split, .commune-grid, .form-grid,
  .management-layout, .main-grid, .detail-grid {
    grid-template-columns: minmax(0,1fr) !important;
  }
  .dashboard-grid > *, .layout > *, .split > *, .commune-grid > *,
  .cards > *, .kpis > * { min-width: 0 !important; }
  .cards, .kpis {
    grid-template-columns: repeat(2,minmax(0,1fr)) !important;
    gap: 10px !important;
  }
  .cards .card, .kpis .kpi { padding: 14px 12px !important; min-width: 0; }
  .card-value, .kpi-value, .value {
    font-size: clamp(22px, 6.1vw, 30px) !important;
    overflow-wrap: anywhere;
  }
  .card-label, .kpi-label, .card-desc, .kpi-desc {
    line-height: 1.4 !important;
    overflow-wrap: anywhere;
  }
  .filters {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
    align-items: stretch !important;
    gap: 11px !important;
    padding: 14px !important;
  }
  .filters > *, .filters .field, .filters .field:first-child,
  .filters label, .filters input, .filters select {
    min-width: 0 !important;
    max-width: 100% !important;
    grid-column: auto !important;
    width: 100%;
  }
  form .field, .field { max-width: 100%; min-width: 0; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea {
    max-width: 100% !important;
    min-width: 0;
    font-size: 16px !important;
  }
  input[type="date"], input[type="datetime-local"], select {
    min-height: 44px;
  }
  button, input[type="submit"], a.btn, .primary-btn,
  .save, .cancel, .back, .month-nav a {
    min-height: 44px;
    touch-action: manipulation;
  }
  .actions, .form-actions, .report-actions, .search-row {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .search-row { flex-direction: column !important; }
  .search-row > input, .search-row > button,
  .search-row > a { width: 100% !important; min-width: 0; }
  .actions > button, .actions > a, .form-actions > button,
  .form-actions > a { flex: 1 1 130px; text-align: center; }
  .month-nav { width: 100%; justify-content: space-between; gap: 7px !important; }
  .month-label { flex: 1; min-width: 0 !important; padding: 10px 7px !important; }
  .legend { gap: 7px !important; }
  .legend span { font-size: 11px !important; }
  .chart-legend { gap: 9px 13px !important; }
  .cto-mobile-table-wrap, .table-wrap, .chart-scroll, .history-scroll,
  .cto-mobile-chart-wrap {
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .cto-mobile-table-wrap { width: 100%; border-radius: 9px; }
  .cto-mobile-table-wrap > table { min-width: 660px; }
  .cto-mobile-table-wrap table th, .cto-mobile-table-wrap table td,
  .table-wrap table th, .table-wrap table td {
    font-size: 12px;
    white-space: normal;
  }
  .cto-mobile-chart-wrap { margin-top: 6px; }
  .cto-mobile-chart-wrap > .chart { min-width: 570px; margin-top: 16px; }
  .cto-mobile-chart-wrap > .chart .month { min-width: 76px; }
  .cto-mobile-scroll-hint {
    display: block;
    font-size: 11px;
    line-height: 1.3;
    color: #69809e;
    margin: 7px 0;
    font-weight: 600;
  }
  .table-wrap, .chart-scroll { width: 100%; }
  img, svg { max-width: 100%; }
  svg { height: auto; }
  .dashboard-alert { flex-wrap: wrap !important; }
  .dashboard-alert-form { width: 100%; }
  .dashboard-alert-btn { width: 100%; }
  /* Calendar: a readable day-by-day listing and an optional original monthly view. */
  body.cto-mobile-ready .cto-mobile-calendar-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
  }
  .cto-mobile-calendar-switch strong { font-size: 16px; }
  .cto-mobile-calendar-switch button {
    border: 1px solid #cbd9ec;
    background: white;
    color: #082a63;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 700;
  }
  body.cto-mobile-ready .cto-mobile-agenda {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }
  body.cto-mobile-ready .cto-mobile-agenda.is-hidden { display: none; }
  body.cto-mobile-ready .calendar:not(.cto-calendar-show-grid) { display: none !important; }
  body.cto-mobile-ready .calendar.cto-calendar-show-grid { display: block !important; overflow-x: auto !important; }
  .cto-mobile-agenda a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 53px;
    padding: 12px 13px;
    border: 1px solid #dce5f0;
    border-radius: 12px;
    background: white;
    color: #163964;
    text-decoration: none;
    gap: 12px;
  }
  .cto-mobile-agenda a.is-weekend { background: #f7f9fb; }
  .cto-mobile-agenda a.has-activities { border-left: 4px solid #2f80ed; }
  .cto-mobile-agenda a:focus-visible { outline: 3px solid #2f80ed; outline-offset: 2px; }
  .cto-mobile-day-label { font-size: 13px; font-weight: 700; }
  .cto-mobile-day-count { font-size: 12px; font-weight: 700; color: #536b86; white-space: nowrap; }
  .cto-mobile-day-count.has-activities { color: #0b60b4; }
  /* Short login on phones: login form visible without a large cover image. */
  body.cto-mobile-login { padding: 12px !important; align-items: flex-start !important; }
  .login-layout { max-width: 100% !important; grid-template-columns: 1fr !important; }
  .presentation { min-height: 0 !important; padding: 18px !important; }
  .presentation-main, .presentation-footer { display: none !important; }
  .presentation h1 { font-size: 24px !important; }
  .login-side { padding: 24px 19px !important; }
  .brand-logo-login { max-width: 115px !important; }
}

@media screen and (max-width: 380px) {
  .cards, .kpis { grid-template-columns: minmax(0,1fr) !important; }
  body > header > .brand img, body > header .brand-logo-header { width: 88px !important; height: 42px !important; flex-basis: 88px; }
  body > header .brand h1 { font-size: 17px !important; }
  .panel, .search-card, .section { padding: 15px 11px !important; }
}

@media print {
  .cto-mobile-menu-bar, .cto-mobile-agenda, .cto-mobile-calendar-switch,
  .cto-mobile-scroll-hint { display: none !important; }
}
