/* KORDVEX · capa visual iOS nativa (sólo mobile/tablet).
   No contiene lógica PWA; se apoya en manifest/SW para standalone. */
@media (max-width: 1180px), (pointer: coarse) and (max-width: 1366px) {
  :root {
    --ios-bg: #f4f6f3;
    --ios-card: #ffffff;
    --ios-line: #e1e7df;
    --ios-ink: #17231c;
    --ios-muted: #6b786f;
    --ios-blue: #0f1c2e;
    --ios-safe-top: env(safe-area-inset-top, 0px);
    --ios-safe-bottom: env(safe-area-inset-bottom, 0px);
    --ios-gutter: 16px;
    --ios-radius: 14px;
  }

  html, body {
    background: var(--ios-bg);
    color: var(--ios-ink);
    overscroll-behavior-y: none;
  }
  body { min-height: 100dvh; }
  * { -webkit-tap-highlight-color: transparent; }

  /* Topbar nativa */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    padding-top: var(--ios-safe-top);
    background: rgba(15, 28, 46, .97);
    border-bottom: 1px solid rgba(255,255,255,.08);
    backdrop-filter: saturate(160%) blur(16px);
  }
  .topbar-inner {
    max-width: 760px;
    min-height: 58px;
    padding: 8px var(--ios-gutter);
    margin: 0 auto;
  }
  .mobile-menu-toggle,
  .topbar-actions .btn,
  .account-trigger {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    border-radius: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .brand-app-icon { width: 34px; height: 34px; border-radius: 9px; }

  /* Página */
  .page {
    max-width: 720px;
    margin-inline: auto;
    padding: 16px var(--ios-gutter) calc(28px + var(--ios-safe-bottom));
  }
  .view-hero { padding: 2px 0 4px; }
  .view-hero h1 { letter-spacing: -.045em; line-height: 1.05; }
  .view-hero p { color: var(--ios-muted); font-size: 12px; line-height: 1.55; }
  .eyebrow { letter-spacing: .13em; }

  .panel,
  .command-panel,
  .patrol-panel,
  .crm-panel {
    background: var(--ios-card);
    border: 1px solid var(--ios-line);
    border-radius: var(--ios-radius);
    box-shadow: 0 1px 2px rgba(20, 35, 26, .035);
  }
  .command-kpi {
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--ios-line);
    box-shadow: 0 1px 2px rgba(20, 35, 26, .03);
  }
  .command-kpi strong { letter-spacing: -.04em; }

  /* Login nativo */
  .auth-screen {
    display: block;
    min-height: 100dvh;
    background:
      radial-gradient(560px 380px at 50% -10%, rgba(38, 68, 55, .32), transparent 70%),
      #0f1c2e;
  }
  .auth-brand-panel { display: none; }
  .auth-form-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: calc(24px + var(--ios-safe-top)) var(--ios-gutter) calc(24px + var(--ios-safe-bottom));
    background: transparent;
  }
  .auth-card {
    width: 100%;
    max-width: 430px;
    padding: 24px 20px 20px;
    border-radius: 22px;
    border: 1px solid rgba(255,255,255,.12);
    background: #fff;
    box-shadow: 0 24px 80px -30px rgba(0,0,0,.55);
  }
  .auth-mobile-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--ios-line);
  }
  .auth-mobile-brand img { width: 148px; height: auto; }
  .auth-card h2 { font-size: 26px; letter-spacing: -.045em; }
  .auth-subtitle { font-size: 12px; margin-bottom: 18px; }
  .auth-form { gap: 12px; }
  .auth-form .field input { height: 48px; }
  .auth-submit { min-height: 48px; border-radius: 12px; }
  .auth-note { margin-top: 14px; border-radius: 10px; }

  /* Diálogos tipo sheet nativo */
  dialog.modal,
  dialog.modal-service,
  dialog.modal-confirm,
  dialog.modal-password,
  dialog.modal-share,
  dialog.modal-report,
  dialog.modal-users,
  dialog.modal-pause,
  dialog.modal-admin-time,
  dialog.modal-location,
  dialog.modal-credentials {
    background: #fff;
  }
  dialog.modal .modal-shell,
  dialog.modal-service .modal-shell {
    background: #fff;
  }
  dialog.modal .modal-head,
  dialog.modal-service .modal-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(255,255,255,.98);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--ios-line);
    padding-top: calc(13px + var(--ios-safe-top));
  }
  dialog.modal .modal-body,
  dialog.modal-service .modal-body {
    padding: 16px;
    background: var(--ios-bg);
  }
  dialog.modal .modal-footer,
  dialog.modal-service .modal-footer {
    background: rgba(255,255,255,.98);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--ios-line);
    padding-bottom: calc(10px + var(--ios-safe-bottom));
  }
  dialog.modal .modal-head h2,
  dialog.modal-service .modal-head h2 { font-size: 20px; letter-spacing: -.035em; }

  /* Formularios nativos */
  .field { margin-bottom: 14px; }
  .field-label,
  .field > span:first-child {
    display: block;
    margin-bottom: 6px;
    color: var(--ios-muted);
    font-size: 10px;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .field input,
  .field select,
  .field textarea {
    background: #fff;
    border: 1px solid #dbe2d8;
    border-radius: 11px;
    height: 48px;
    font-size: 16px;
    padding: 12px 13px;
    color: var(--ios-ink);
  }
  .field textarea { min-height: 96px; height: auto; }
  .field input:focus,
  .field select:focus,
  .field textarea:focus {
    border-color: #8ba695;
    box-shadow: 0 0 0 3px rgba(93, 129, 105, .14);
    outline: none;
  }
  .form-section {
    background: #fff;
    border: 1px solid var(--ios-line);
    border-radius: var(--ios-radius);
    padding: 15px;
    margin-top: 14px;
  }
  .shift-card {
    background: #fff;
    border: 1px solid var(--ios-line);
    border-radius: 12px;
    padding: 13px;
  }
  .shift-times .time-field span { font-size: 9px; color: var(--ios-muted); }
  .shift-times .time-field input { height: 46px; border-radius: 10px; }

  /* Menú nativo */
  .mobile-nav-dialog { background: #0f1c2e; }
  .mobile-nav-shell { max-width: 560px; }
  .mobile-nav-head {
    padding-top: calc(16px + var(--ios-safe-top));
    padding-bottom: 14px;
  }
  .mobile-nav-head h2 { font-size: 28px; letter-spacing: -.05em; }
  .mobile-nav-item {
    min-height: 48px;
    border-radius: 11px;
    font-size: 14px;
  }
  .mobile-nav-group summary { min-height: 44px; font-size: 12px; }

  /* Chat Sentinel nativo */
  .sentinel-dialog {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: #fff;
    overflow: hidden;
  }
  .sentinel-shell {
    width: 100%;
    max-width: 560px;
    margin-inline: auto;
    height: 100%;
    background: #fff;
  }
  .sentinel-head {
    padding: calc(13px + var(--ios-safe-top)) 15px 12px;
    border-bottom: 1px solid var(--ios-line);
    background: rgba(255,255,255,.98);
    backdrop-filter: blur(14px);
  }
  .sentinel-scope {
    background: var(--ios-bg);
    border-bottom: 1px solid var(--ios-line);
    font-size: 10px;
    padding: 8px 15px;
  }
  .sentinel-messages { padding: 14px 15px; gap: 9px; }
  .sentinel-msg {
    max-width: 90%;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
  }
  .sentinel-msg.is-user { border-bottom-right-radius: 4px; }
  .sentinel-msg.is-assistant { border-bottom-left-radius: 4px; }
  .sentinel-composer {
    padding: 9px 12px calc(9px + var(--ios-safe-bottom));
    background: rgba(255,255,255,.98);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--ios-line);
    align-items: flex-end;
  }
  .sentinel-composer textarea {
    min-height: 44px;
    max-height: 120px;
    border-radius: 12px;
    font-size: 16px;
    padding: 11px 12px;
  }
  .sentinel-composer .btn { min-height: 44px; border-radius: 12px; }
  .sentinel-fab {
    width: 50px;
    height: 50px;
    right: 16px;
    bottom: calc(16px + var(--ios-safe-bottom));
    border-radius: 16px;
    background: #0f1c2e;
    box-shadow: 0 12px 28px -8px rgba(0,0,0,.45);
  }

  /* Toasts */
  .toast {
    position: fixed;
    left: 14px;
    right: 14px;
    bottom: calc(14px + var(--ios-safe-bottom));
    max-width: 520px;
    margin-inline: auto;
    border-radius: 12px;
    z-index: 200;
  }

  /* Tablas/cards */
  table.mobile-card-table tbody tr { border-radius: 12px; }
  .history-table-wrap,
  .table-wrap,
  .analytics-table-wrap,
  .payroll-table-wrap { overflow-x: clip; }

  /* Charts */
  .analytics-chart,
  .chart-card,
  .chart-container {
    background: #fff;
    border: 1px solid var(--ios-line);
    border-radius: var(--ios-radius);
    padding: 12px;
    overflow: hidden;
  }
  .chart-legend { font-size: 10px; color: var(--ios-muted); }

  /* Touch targets */
  .btn { min-height: 44px; border-radius: 10px; }
  .icon-button { min-width: 40px; min-height: 40px; }
  .check-field { min-height: 44px; }

  /* Scrollbars invisibles en app */
  * { scrollbar-width: none; }
  *::-webkit-scrollbar { display: none; width: 0; height: 0; }
}

@media (max-width: 1180px), (pointer: coarse) and (max-width: 1366px) {
  .mobile-menu-toggle,
  .mobile-menu-toggle:hover,
  .mobile-menu-toggle:focus {
    color: #fff;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.18);
    box-shadow: none;
  }
  .mobile-menu-toggle .icon { color: #fff; stroke: currentColor; }
  .topbar-actions .btn:hover,
  .account-trigger:hover { background: rgba(255,255,255,.09); }
}

@media (max-width: 1180px), (pointer: coarse) and (max-width: 1366px) {
  .mobile-nav-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    color: #fff;
    background: #0f1c2e;
  }
  .mobile-nav-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(16px + var(--ios-safe-top)) 18px 14px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    flex: 0 0 auto;
  }
  .mobile-nav-head .eyebrow { color: rgba(255,255,255,.5); margin: 0 0 2px; }
  .mobile-nav-head h2 { margin: 0; color: #fff; font-size: 28px; letter-spacing: -.05em; }
  .mobile-nav-head .icon-button {
    color: #fff;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.18);
    outline: none;
  }
  .mobile-nav-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 14px calc(24px + var(--ios-safe-bottom));
  }
  .mobile-nav-section { margin: 8px 0 16px; }
  .mobile-nav-label {
    margin: 0 10px 7px;
    color: rgba(255,255,255,.45);
    font-size: 9px;
    letter-spacing: .14em;
    text-transform: uppercase;
  }
  .mobile-nav-item {
    display: flex;
    width: 100%;
    min-height: 48px;
    align-items: center;
    gap: 11px;
    padding: 11px 12px;
    color: rgba(255,255,255,.82);
    background: transparent;
    border: 0;
    border-radius: 11px;
    font: inherit;
    font-size: 14px;
    text-align: left;
  }
  .mobile-nav-item:hover,
  .mobile-nav-item.is-active {
    color: #fff;
    background: rgba(255,255,255,.1);
  }
  .mobile-nav-item .icon { width: 19px; height: 19px; flex: 0 0 auto; opacity: .9; }
  .mobile-nav-group { margin: 2px 0 4px; }
  .mobile-nav-group summary {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 9px 12px;
    color: rgba(255,255,255,.72);
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
    list-style: none;
    border-radius: 9px;
  }
  .mobile-nav-group summary::-webkit-details-marker { display: none; }
  .mobile-nav-group summary::after { content: '›'; margin-left: auto; font-size: 18px; color: rgba(255,255,255,.45); }
  .mobile-nav-group[open] summary::after { transform: rotate(90deg); }
  .mobile-nav-group .mobile-nav-item { padding-left: 30px; }
}

@media (max-width: 1180px), (pointer: coarse) and (max-width: 1366px) {
  /* Inputs nativos iOS: impedir ancho intrínseco y recortes dentro del modal. */
  .field,
  .field-full,
  .form-grid > *,
  .form-section,
  .shift-card,
  .shift-times,
  .shift-times .time-field {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }
  .field input,
  .field select,
  .field textarea {
    display: block;
    inline-size: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
  }
  .field input[type="date"],
  .field input[type="time"],
  .field input[type="datetime-local"] {
    inline-size: 100%;
    width: 100%;
    max-width: 100%;
    min-inline-size: 0;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
  }
  .shift-times {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }
  .shift-times .time-field input {
    inline-size: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  dialog.modal .modal-body,
  dialog.modal-service .modal-body {
    overflow-x: hidden;
  }
}

@media (max-width: 1180px), (pointer: coarse) and (max-width: 1366px) {
  /* Turnos: header sin competir con el switch y horarios en una columna. */
  .shift-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    width: 100%;
  }
  .shift-card-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: flex-start;
    gap: 8px;
    min-width: 0;
  }
  .shift-card-copy strong,
  .shift-card-copy span {
    overflow-wrap: anywhere;
  }
  .shift-times .time-field input {
    inline-size: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
  }

  /* Personal · disponibilidad y formularios inline. */
  .workforce-day {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 5px;
    width: 100%;
    min-width: 0;
    align-items: center;
  }
  .workforce-day > span {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 10px;
  }
  .workforce-day input[type="time"] {
    inline-size: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 38px;
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
  }
  .workforce-inline-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    gap: 7px;
    align-items: stretch;
  }
  .workforce-inline-form input,
  .workforce-inline-form select,
  .workforce-inline-form .btn {
    inline-size: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .workforce-inline-form input[type="text"] { width: 100%; }
  .workforce-range {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }
  .workforce-range .btn {
    grid-column: 1 / -1;
    width: 100%;
  }
  .workforce-profile-name {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .workforce-profile-name strong { min-width: 0; overflow-wrap: anywhere; }
}

@media (max-width: 1180px), (pointer: coarse) and (max-width: 1366px) {
  /* PWA sin banda de safe-area visible. */
  .topbar { padding-top: 0 !important; }
  .page { padding-bottom: 24px !important; }
  dialog.modal .modal-head,
  dialog.modal-service .modal-head { padding-top: 13px !important; }
  dialog.modal .modal-footer,
  dialog.modal-service .modal-footer { padding-bottom: 11px !important; }
  .mobile-nav-head { padding-top: 16px !important; }
  .mobile-nav-content { padding-bottom: 24px !important; }
  .sentinel-head { padding-top: 13px !important; }
  .sentinel-composer { padding-bottom: 9px !important; }
  .sentinel-fab { bottom: 16px !important; }
  .toast { bottom: 14px !important; }

  /* Desde / Hasta de turnos: columna única, ancho completo y sin centrado externo. */
  dialog.modal-service .shift-times {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 12px 0 0 !important;
    padding: 0 !important;
    align-items: stretch !important;
    justify-items: stretch !important;
  }
  dialog.modal-service .shift-times .time-arrow { display: none !important; }
  dialog.modal-service .shift-times .time-field {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    align-items: stretch !important;
    text-align: left !important;
  }
  dialog.modal-service .shift-times .time-field input {
    display: block !important;
    inline-size: 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    text-align: center !important;
    -webkit-appearance: none !important;
    appearance: none !important;
  }

  /* Personal: cada control inline ocupa el ancho del modal. */
  .workforce-inline-form { grid-template-columns: minmax(0, 1fr) !important; }
  .workforce-inline-form > * { width: 100% !important; max-width: 100% !important; min-width: 0 !important; }
}

@media (max-width: 1180px), (pointer: coarse) and (max-width: 1366px) {
  /* Toast/banner de acciones: ancho de pantalla, centrado real y sin herencia desktop. */
  .toast,
  .toast.is-in-dialog {
    position: fixed !important;
    left: 50% !important;
    right: auto !important;
    bottom: 14px !important;
    width: calc(100% - 28px) !important;
    max-width: 520px !important;
    margin: 0 !important;
    padding: 11px 14px 11px 11px !important;
    transform: translateX(-50%) !important;
    border-radius: 13px !important;
    box-sizing: border-box !important;
    font-size: 12px !important;
    line-height: 1.4 !important;
    z-index: 3000 !important;
  }
  .toast.is-in-dialog {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .toast .toast-icon { width: 26px; height: 26px; }
  .toast .toast-icon .icon { width: 14px; height: 14px; }
}
